我的应用程序仅在横向模式下运行!所以我知道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'
This problem could be solved if I check Portrait
in deployment info :
问题是,如果我选中此选项,我的应用程序也可以纵向运行,但我不想要它!
我该如何解决这个问题?
我已经对其进行了测试,发现您不应该通过目标窗口中的复选框来处理方向,如上图所示,因为它是您的整个应用程序方向,因此请选中所有框以获得支持的所有方向。如果您想要不同方向的某些视图和不同方向的某些视图,那么您将必须通过编码来处理它ViewController
返回类YES
OR NO
用于定向。
这是我的Sample https://dl.dropboxusercontent.com/u/74641080/ImagePickerSample.zip。我做的。请检查。
下面的方法将处理方向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
分别。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)