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

时间:2016-05-27 09:56:39

标签: ios orientation uialertview landscape shouldautorotate

我正在开发一个应用程序,其中我只使用一个方向,即Portrait。这是设备方向设置:

enter image description here

但在我的应用程序中有视频播放器(MPMoviePlayerViewController的自定义播放器),我想仅在Landscape Right模式下显示它,它不应该旋转。 这工作正常,我的意思是这个自定义播放器完全在Landscape Right中显示,但当我使用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'

3 个答案:

答案 0 :(得分:0)

iOS8:UIAlertController

#import "UIAlertController+Portrait.h"

@implementation UIAlertController (Portrait)

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

@end

答案 1 :(得分:0)

iHTCboy的答案在转换为swift之后为我修复了。

在swift 4中:

extension UIAlertController {

override open var supportedInterfaceOrientations: UIInterfaceOrientationMask { return .all }

}

答案 2 :(得分:-1)

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

enter image description here 解决方案2.使用以下代码(您的位置): -

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

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