参考总结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"];
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- pqdy.cn 版权所有 赣ICP备2024042791号-6
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务