ios 屏幕旋转Orientation总结2

参考总结1的内容发现在Ios78中,覆盖supportedInterfaceOrientations方法无效。正确的做法是覆盖以下方法:

自定义一个UINavigationController的子类,当添加viewcontroller的时候记录当前显示的那个viewcontroller,然后重写preferredInterfaceOrientationForPresentation和shouldAutorotate使之调用当前显示的viewcontroller里面的屏幕旋转方法

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {

    UIViewController* viewController = [self.viewControllersobjectAtIndex:index];

    return viewController.preferredInterfaceOrientationForPresentation;

}

-(BOOL)shouldAutorotate {

    UIViewController* viewController = [self.viewControllersobjectAtIndex:index];

    return viewController.shouldAutorotate;

}

最后你需要在每一个需要改变屏幕方向的viewcontroller里面重写preferredInterfaceOrientationForPresentation和shouldAutorotate,让它选择正确的旋转方向就行

ios8通过preferredInterfaceOrientationForPresentation锁定的旋转,弹出UIActionSheet的时候会出现显示方向不对的问题,我们可以在appdelegate里面给出正确的方向

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window

{

    NSString* strClass = [NSStringstringWithUTF8String:object_getClassName(window.rootViewController)];

    if ([@"_UIAlertShimPresentingViewController"isEqualToString:strClass]) {

        returnUIInterfaceOrientationMaskPortrait;

    }

    return [applicationsupportedInterfaceOrientationsForWindow:window];

}

ios8需要正确的显示软键盘的方向需要设置如下:

[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationPortrait] forKey:@"orientation"];



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值