繁体   English   中英

当UIAlertview在Landscape viewcontroller中显示时,shouldAutorotate()方法崩溃吗?

[英]Crash on shouldAutorotate() method when UIAlertview show in Landscape viewcontroller?

我正在开发一个仅使用一个方向(即人像)的应用程序。 这是设备方向设置:

在此处输入图片说明

但是在我的应用程序中,我只想在“横向右”模式下显示视频播放器( MPMoviePlayerViewController自定义播放器),并且不应旋转它。 一切正常,我的意思是该自定义播放器在“横向右移”中完美显示,但是当我使用UIAlertview应用程序在此方法上崩溃了:

- (BOOL)shouldAutorotate {


    return NO;

}

这些是其他一些定向方法:

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationLandscapeRight; // or Right of course
}

#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000
- (NSUInteger)supportedInterfaceOrientations
#else
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
#endif
{
    return UIInterfaceOrientationMaskLandscape;
}

我收到此错误:

 *** Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and [UIAlertController shouldAutorotate] is returning YES'

iOS8:UIAlertController

#import "UIAlertController+Portrait.h"

@implementation UIAlertController (Portrait)

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

@end

iHTCboy的答案在转换为swift后为我解决了。

快速4:

extension UIAlertController {

override open var supportedInterfaceOrientations: UIInterfaceOrientationMask { return .all }

}

解决方案1.转到info.plist并删除不需要的其他方向:-

在此处输入图片说明 解决方案2.使用以下代码(在您所在的位置):

-(NSUInteger)supportedInterfaceOrientations {
    UIViewController *vC = self.topViewController;
    return vC.supportedInterfaceOrientations;
}

-(BOOL)shouldAutorotate {
   UIViewController *vC = self.topViewController;
   return [vC shouldAutorotate];
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM