屏幕旋转 iOS7 iOS8 通用版

来源:互联网 发布:协同过滤推荐算法综述 编辑:程序博客网 时间:2024/04/30 15:50

第一  presentViewController模式

[self presentViewController:vc animated:YES completion:nil];

vc的方向是vc自己管理的


第二 pushViewController模式

[self.navigationController pushViewController:vc animated:YES];

vc的方向是navigationController管理的
系统调用navigationController的方向适配
vc设置的不起作用   故添加分类

@implementation UINavigationController (Rotation)- (BOOL)shouldAutorotate{    return [self.topViewController shouldAutorotate];}- (NSUInteger)supportedInterfaceOrientations{    return [self.topViewController supportedInterfaceOrientations];}- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {    return [self.topViewController preferredInterfaceOrientationForPresentation];}

但是 但是 如果navigationController 是放在 TabBarController中的那么 
vc的方向是TabBarController管理的
系统调用系统调用TabBarController的方向适配
vc设置的不起作用   故添加分类

- (BOOL)shouldAutorotate{    return [self.selectedViewController shouldAutorotate];}- (NSUInteger)supportedInterfaceOrientations{    return [self.selectedViewController  supportedInterfaceOrientations];}- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {    return [self.selectedViewController  preferredInterfaceOrientationForPresentation];}

现在需求是:个别屏幕横屏
基类做支持横屏处理 (自己写)
需要横屏处理的 添加

- (BOOL)shouldAutorotate{    return NO;}- (NSUInteger)supportedInterfaceOrientations{    return UIInterfaceOrientationMaskLandscapeRight;}- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {    return UIInterfaceOrientationLandscapeRight;}

vc中如果需要状态栏转动的
[[UIApplication sharedApplication] setStatusBarOrientation:  UIInterfaceOrientationLandscapeRight animated:NO];

注意 方向保持一致!方向保持一致!方向保持一致!


然后 iOS7下一切正常  iO8下各种不顺

问题一  push 后 pop回来界面没竖过来 
返回前 
[[UIApplication sharedApplication] setStatusBarOrientation:  UIInterfaceOrientationPortrait animated:NO];

问题二 状态栏横屏隐藏了

1、didFinishLaunchingWithOptions:中添加如下方法 
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];

(为啥 我也不知道 但是就是可以了 知道的求告知)
2、在plist文件中将 View controller-based status bar appearance 设置为NO 

OK 大功告成 



0 0
原创粉丝点击