今天突然想起来,以前的一个问题没有解决,就上网百度了一些方法,看到一篇文章,写的很详细,我就操作试试,结果还真的实现了功能,接下来我将重复他的结合我自己的测试,说一下iOS中的旋屏问题。

  1、首先配置工程 使其支持屏幕旋转

            

  2、如果你的rootViewController为UITabBarController的情况下 建议创建一个UITabBarController的公共父类 在里面实现如下代理方法

  preferredInterfaceOrientationForPresentation 我理解为打开时当前界面的朝向

  shouldAutorotate 是否支持旋转

  supportedInterfaceOrientations 所支持的旋转方向

  return返回的为当前选中 tabar 的item的情况

  具体的代码如下:

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {

return [self.selectedViewController preferredInterfaceOrientationForPresentation];

}

- (BOOL)shouldAutorotate {

return YES;

}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {

return [self.selectedViewController supportedInterfaceOrientations];

}

  3、在 UITabBarController 中放UINavigationController后 还需要在 UINavigationController中实现还是那三个方法  因为我的界面只有VideoDetail1ViewController需要横竖屏的处理 所以我只是单独的做了判断

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {

if ([self.topViewController isKindOfClass:[VideoDetail1ViewController class]]) {

return UIInterfaceOrientationPortraitUpsideDown;

}

return UIInterfaceOrientationPortrait;

}

- (BOOL)shouldAutorotate {

if ([self.topViewController isKindOfClass:[VideoDetail1ViewController class]]) {

return YES;

}

return NO;

}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {

if ([self.topViewController isKindOfClass:[VideoDetail1ViewController class]]) {

return UIInterfaceOrientationMaskAllButUpsideDown;

}

return UIInterfaceOrientationMaskPortrait;

}

  如果不需要特定的对某个界面做旋屏的还,可以直接进行如下操作:

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {

return  [self.topViewController preferredInterfaceOrientationForPresentation];

}

- (BOOL)shouldAutorotate {

return   [self.topViewController shouldAutorotate];

}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {

return  [self.topViewController supportedInterfaceOrientations];

}

  4、然后如果某个界面想支持屏幕旋转 只需要在里面重写写方法即可

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {

return UIInterfaceOrientationPortrait;

}

- (BOOL)shouldAutorotate {

return YES;

}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {

return UIInterfaceOrientationMaskAllButUpsideDown;

}

  5、 运行就可以达到想要的结果

  (总结下来为 APP 中 UITabBarController中的支持旋转由 UITabBarController 下的 UINavigationController 控制 而UINavigationController的旋转由你自己在当前Controller中设置的值来控制),如果rootViewController不是UITabBarController的话 同理...

附: 在手机为横屏模式下打开APP  APP会按照横屏来布局 需要在 如下方法中新加

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];//此方法    ....

}

这样就会解决横屏模式下打开 APP 产生的一些问题

(容易出现的一些问题为:当你在didFinishLaunchingWithOptions中 加载了另一个 window 的时候需要在自己建的 window 中也遵守屏幕旋转的几个代理方法 不然横屏模式下打开APP布局依然会乱)

iOS 旋屏问题的更多相关文章

  1. iOS旋屏

    横竖屏切换,视图乱了怎么办? 首先,我们必须了解一下下列4种状态,它们被用来描述设备旋转方向: UIInterfaceOrientationLandscapeLeft 向左,即HOME键在右 UIIn ...

  2. ios 导航栏和旋屏

    1,状态栏(UIStatusBar) http://my.oschina.net/shede333/blog/304560 2,visibleViewController和topViewControl ...

  3. iOS特殊界面旋屏设置的方法之一

    1.AppDelegate.h @property (assign, nonatomic) BOOL allowRotation; 2.AppDelegate.m #pragma mark - 自动旋 ...

  4. iOS6的旋屏控制技巧

    在iOS5.1 和 之前的版本中, 我们通常利用 shouldAutorotateToInterfaceOrientation: 来单独控制某个UIViewController的旋屏方向支持,比如: ...

  5. UIImagePickerController在UIPopoverController中 旋屏问题

    1弧度=180/π度1度=π/180弧度今天遇到了 一个问题.UIImagePickerController在UIPopoverController中 旋屏问题. 在查找了许多资料后方知,此乃iOS系 ...

  6. iOS离屏渲染之优化分析

    在进行iOS的应用开发过程中,有时候会出现卡顿的问题,虽然iOS设备的性能越来越高,但是卡顿的问题还是有可能会出现,而离屏渲染是造成卡顿的原因之一.因此,本文主要分析一下离屏渲染产生的原因及避免的方法 ...

  7. Yosemite 给 iOS 录屏

    [Yosemite 给 iOS 录屏] Mac 升级到Yosemite后,支持iOS屏幕录制.把Mac和iPhone用数据线相连.打开QuickTime Player,新建一个影片. 从摄像头源中选择 ...

  8. 同时支持Android 和 ios 投屏到电脑的软件,Support Android and ios screen shrare to PC - 希沃授课助手

    最近学校由粉笔黑板更换了智慧电子黑板,然后发现了一个好玩的软件. 感谢希沃公司的开发: 希沃授课助手,这是一款同时支持Android 和 ios 投屏和远程控制的. 效果很流畅,非常赞

  9. iOS 离屏渲染的研究

    GPU渲染机制: CPU 计算好显示内容提交到 GPU,GPU 渲染完成后将渲染结果放入帧缓冲区,随后视频控制器会按照 VSync 信号逐行读取帧缓冲区的数据,经过可能的数模转换传递给显示器显示. G ...

随机推荐

  1. LeetCode OJ 223.Rectangle Area

    Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined b ...

  2. 运维命令rsync

    如果你是一位运维工程师,你很可能会面对几十台.几百台甚至上千台服务器,除了批量操作外,环境同步.数据同步也是必不可少的技能. 说到“同步”,不得不提的利器就是rsync,今天就来说说我从这个工具中看到 ...

  3. MySQL 视图 总结

    什么是视图 视图是从一个或多个表中导出来的表,是一种虚拟存在的表. 视图就像一个窗口,通过这个窗口可以看到系统专门提供的数据. 这样,用户可以不用看到整个数据库中的数据,而之关心对自己有用的数据. 数 ...

  4. avd

    http://stackoverflow.com/questions/2662650/making-the-android-emulator-run-faster http://www.cnblogs ...

  5. Struts2 知识体系

    1.struts2是什么 struts2是用于企业级Web开发的框架,基于struts2开发Web应用程序,在开发效率.可扩展性.可维护性上都会大有提升. 2.struts2的优点 struts2框架 ...

  6. java 区分error和exception

    1) java.lang.Error: Throwable的子类,用于标记严重错误.合理的应用程序不应该去try/catch这种错误.绝大多数的错误都是非正常的,就根本不该出现的.java.lang. ...

  7. 内联函数 inline 漫谈

    内联函数存在的结论是: 引入内联函数是为了解决函数调用效率的问题 由于函数之间的调用,会从一个内存地址调到另外一个内存地址,当函数调用完毕之后还会返回原来函数执行的地址.函数调用会有一定的时间开销,引 ...

  8. iOS项目架构 小谈

    层级结构,自底向上 持久层(File,Realm,SQLite)<==>网络层(相信每个公司都有自己的网络层吧)==>业务层(ViewModel)==>展示层(View,VC) ...

  9. selenium工具简介

    通过selenium百科可知: 组件 Selenium IDE:一个Firefox插件,可以录制用户的基本操作,生成测试用例.随后可以运行这些测试用例在浏览器里回放,可将测试用例转换为其他语言的自动化 ...

  10. java 数据结构 图

    以下内容主要来自大话数据结构之中,部分内容参考互联网中其他前辈的博客,主要是在自己理解的基础上进行记录. 图的定义 图是由顶点的有穷非空集合和顶点之间边的集合组成,通过表示为G(V,E),其中,G标示 ...