在iOS 7中展示UIImagePickerController的问题

Mc.*_*ver 9 iphone xcode objective-c ipad ios

我的应用程序仅以横向模式运行!所以我UIImagePickerController只知道纵向模式下的礼物,所以在iOS 6中,我创建了一个UIImagePickerController强制UIImagePickerController以纵向模式打开的子类:

@interface NonRotatingUIImagePickerController : UIImagePickerController

@end

@implementation NonRotatingUIImagePickerController

- (BOOL)shouldAutorotate {

    return NO;
}

@end
Run Code Online (Sandbox Code Playgroud)
//presenting picker controller :

UIImagePickerController *ipc = [[NonRotatingUIImagePickerController alloc]init];
ipc.delegate = self;
[self presentViewController:ipc animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

这在iOS 6中运行良好,但现在在iOS 7中,我的应用程序因此崩溃:

2013-10-31 14:56:01.028 Medad[1731:60b] *** Terminating app due to
uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason:
'Supported orientations has no common orientation with the
application, and shouldAutorotate is returning YES'
Run Code Online (Sandbox Code Playgroud)

如果我检查Portrait部署信息,可以解决此问题: 在此输入图像描述

问题是,如果我检查此选项,我的应用程序也会以纵向运行,但我不想要它!

我该如何解决这个问题?

The*_*ger 6

我已经对它进行了测试,发现您不应该通过目标窗口中的复选框处理方向,如上图所示,因为它是您的整个应用程序方向所以请检查所有方框以获得所有方向支持.如果你想要一些不同方向的视图和一些不同的视图,那么你将不得不ViewController通过返回YESOR NO来定位来通过类中的编码来处理它.

这是我的样品.我做的.请检查.

下面的方法将处理方向 ViewController

-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}

// Old Method
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
     return NO;
    }
    else {
        return YES;
    }
}
Run Code Online (Sandbox Code Playgroud)

因此,解决方案是:为两个自定义类创建一个,UIImagePickerController而另一个用于ViewController(For All ViewControllers)并且只为特定方向创建它们,并将这些类分别用作您UIImagePickerController和所有类的超类ViewControllers.