iOS 6中UIPopoverController方向闪退问题

17

我的目前程序只支持横屏模式。

在iOS 6中,它会在UIPopoverController上崩溃。

'UIApplicationInvalidInterfaceOrientation',原因是 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'

我为项目启用了所有方向,它运行良好。但是,我需要更改大量视图以仅支持横屏。

是否有其他简单的方法来修复UIPopoverController中的UIOrientation


2
嗨@satungod,我的回答不幸被管理员删除了,因为我已经在另一个帖子中发布了它...很公平。请在此处找到此答案:https://dev59.com/6Gcs5IYBdhLWcg3w3HkG#12575058 - 我正在添加一个新答案以引导到另一个答案。 - Daniel
5个回答

0
新建一个UIImagePickerController的子类并添加以下代码:
@property (nonatomic)NSUInteger supportedInterfaceOrientations;

-(NSUInteger)supportedInterfaceOrientations{
    return _supportedInterfaceOrientations;
}
-(BOOL)shouldAutorotate{
    return YES;
}

使用方法如下:

    if (imagePickerController==nil) {
        imagePickerController = [[WUIImagePickerController alloc]init];//the subclass
        imagePickerController.delegate = self;
        imagePickerController.supportedInterfaceOrientations = UIInterfaceOrientationMaskLandscapeRight;//any orientation you want to set
        if (popoverController==nil) {
            popoverController = [[UIPopoverController alloc]initWithContentViewController:imagePickerController];
        }
    }

谁知道更好的方法请告诉我。


1
看看丹尼尔的回答。有一个带有答案的链接。 - Léo Natan
1
这不是一个setter方法。imagePickerController.supportedInterfaceOrientations = UIInterfaceOrientationMaskLandscapeRight; 完全错误... - Solid Soft

0
Use these delegates for orientation,
- (BOOL)shouldAutorotate
{

return YES;
}

-(NSUInteger)supportedInterfaceOrientations

{
return UIInterfaceOrientationMaskLandscape;

}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
  return UIInterfaceOrientationLandscapeLeft;
}

0

尝试将以下内容添加到您的UIApplicationDelegate中:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    return UIInterfaceOrientationMaskAll;
}

您仍然可以在您的Info.plist文件中设置您支持的界面方向,并通过在每个视图控制器的supportedInterfaceOrientations:方法中返回一个掩码来实现。


这是正确的,根据https://devforums.apple.com/message/731764#731764。 - Zeophlite

0
尝试这个链接。你必须在开始时设置应用程序支持所有方向。在应用委托中进行更改。
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window

{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        return UIInterfaceOrientationMaskAll;
    else  /* iphone */
        return UIInterfaceOrientationMaskAllButUpsideDown;

}

0
@interface NonRotatingUIImagePickerController : UIImagePickerController

@end

@implementation NonRotatingUIImagePickerController

- (BOOL)shouldAutorotate
{
    return NO;
}

@end

UIImagePickerController *picker = [[NonRotatingUIImagePickerController alloc] init];

使用上述代码,这对我有效。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接