今天突然想起来,以前的一个问题没有解决,就上网百度了一些方法,看到一篇文章,写的很详细,我就操作试试,结果还真的实现了功能,接下来我将重复他的结合我自己的测试,说一下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布局依然会乱)

最新文章

  1. asp.net页面跳转sessionid会变
  2. What are the main disadvantages of Java Server Faces 2.0?
  3. C#...何时需要重写ToString()方法?
  4. Good Bye 2015 C - New Year and Domino
  5. 谈Web应用系统的可维护性
  6. C++11 virtual函数学习笔记
  7. Example015实现html中checkbox的全选和反选(2)
  8. 前端到后台ThinkPHP开发整站(7)
  9. 【Linux SELinux】提升系统安全(一)
  10. 正确使用volatile场景--状态标志
  11. SDL 2.0 如何在 windows 上使用?
  12. rbac(基于角色权限控制)-------权限管理
  13. Java的 volatile关键字的底层实现原理
  14. php的垃圾回收机制
  15. python学习之----导航树
  16. Hdu1728 逃离迷宫 2017-01-17 10:56 81人阅读 评论(0) 收藏
  17. Swift 里字符串(一)概览
  18. HDU 1231 最大子序列
  19. SOA (面向服务的架构)-Service Oriented Architecture
  20. cxGrid显示行号

热门文章

  1. poj_2778_DNA Sequence(AC自动机+矩阵)
  2. OpenCV——运用于pixels war游戏
  3. MC 在1分钟图拿出5分钟,15分钟,30分钟,1小时的K线
  4. jsp第1讲(上集)
  5. servlet第3讲(上集)----同一用户的不同页面共享数据
  6. 20150627分享iOS开发笔记
  7. qmake pro工程设置
  8. oracle数据库字符集的修改
  9. centos7 python
  10. WPF中CheckBox三种状态打勾打叉和滑动效果