0

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

在此处输入图像描述

但是在我的应用程序中,有一个视频播放器(自定义播放器MPMoviePlayerViewController),我只想在横向右模式下显示它,它不应该被旋转。这工作正常,我的意思是这个自定义播放器完美地显示在横向右侧,但是当我使用UIAlertviewthen 应用程序时,这个方法会崩溃:

- (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'
4

3 回答 3

1

转换为 swift 后,iHTCboy 的回答为我修复了它。

在 Swift 4 中:

extension UIAlertController {

override open var supportedInterfaceOrientations: UIInterfaceOrientationMask { return .all }

}
于 2018-02-02T17:56:54.123 回答
0

iOS8:UIAlertController

#import "UIAlertController+Portrait.h"

@implementation UIAlertController (Portrait)

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

@end
于 2017-06-07T03:01:00.077 回答
-1

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

在此处输入图像描述 解决方案2.使用以下代码(您的):-

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

-(BOOL)shouldAutorotate {
   UIViewController *vC = self.topViewController;
   return [vC shouldAutorotate];
}
于 2016-05-27T10:10:20.443 回答