我的应用程序只在横向模式下运行!所以我知道 UIImagePickerController
仅在纵向模式下显示,因此在 iOS 6 中,我创建了 UIImagePickerController
的子类,它强制 UIImagePickerController
以纵向模式打开模式:
@interface NonRotatingUIImagePickerController : UIImagePickerController
@end
@implementation NonRotatingUIImagePickerController
- (BOOL)shouldAutorotate {
return NO;
}
@end
//presenting picker controller :
UIImagePickerController *ipc = [[NonRotatingUIImagePickerController alloc]init];
ipc.delegate = self;
[self presentViewController:ipc animated:YES completion:nil];
这在 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'
如果我在部署信息中检查 Portrait
,这个问题就可以解决:
问题是,如果我选中此选项,我的应用程序也会纵向运行,但我不想要它!
我该如何解决这个问题?
最佳答案
我已经对其进行了测试,发现您不应该通过目标窗口中的复选框处理方向,如上图所示,因为它是您的整个应用程序方向,因此请选中所有框以支持所有方向。如果您想要一些不同方向的 View 和一些不同方向的 View ,那么您将必须通过返回 YES
或 NO
在 ViewController
类中进行编码来处理它用于定位。
这是我的 Sample .我做的。请检查。
下面的方法将处理 ViewController
的方向
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
// Old Method
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
return NO;
}
else {
return YES;
}
}
因此,解决方案是:创建两个自定义类,一个用于 UIImagePickerController
,另一个用于 ViewController
(对于所有 ViewController),并针对特定方向制作它们并使用这些类作为您的 UIImagePickerController
和所有 ViewControllers
的父类(super class)。
关于ios - 在 iOS 7 中呈现 UIImagePickerController 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19705433/