记录各种疑难杂症
1. Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and [UIAlertController shouldAutorotate] is returning YES'
由于APP只支持竖屏,而在其中某个页面中单独设置支持横屏,在此横屏页面下,如果触发了某个业务弹出了UIAlertController
,则会导致崩溃。网上有说写一个UIAlertController
分类,在其中重写shouldAutorotate
方法处理,然而写了之后并不会执行。
当然不仅仅是UIAlertController
这一种情况,UIImagePickerViewController
这种系统的东西都有可能触发。
解决方案:在AppDelegate
中实现以下方法根据实际业务判断处理
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
UIViewController *rootVC = window.rootViewController;
if (rootVC.presentedViewController) {
UIViewController *theVC = rootVC.presentedViewController;
while (theVC.presentedViewController) {
theVC = theVC.presentedViewController;
}
if ([theVC shouldAutorotate]) {
return UIInterfaceOrientationMaskAll;
}
return theVC.supportedInterfaceOrientations;
}
return rootVC.supportedInterfaceOrientations;
}
网友评论