屏幕旋转 iOS7 iOS8 通用版

第一  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 大功告成 



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值