5

我有一个仅限横向的应用程序,每当我访问照片库时,应用程序都会崩溃(因为UIImagePickerViewController试图以纵向模式加载)。应用程序在 iOS 5 和 6 中运行良好。

我收到以下错误,

由于未捕获的异常' UIApplicationInvalidInterfaceOrientation'而终止应用程序,原因:'支持的方向与应用程序没有共同的方向,并且shouldAutorotate正在返回YES'

*** First throw call stack:
(0x2ff7ae8b 0x3a2746c7 0x2ff7adcd 0x3277337d 0x3277a4c5 0x3277a47b 0x327795b3 0x326fff3d 0x326ffd19 0x326ff609 0x326ff467 0x3270c153 0x3270bbd3 0x327b7f67 0x327b7d83 0x327afdf3 0x327af279 0x327aefe9 0x327aef7d 0x32700533 0x32387f43 0x32383767 0x323835f9 0x3238300d 0x32382e1f 0x3237cb4d 0x2ff45f71 0x2ff438ff 0x2ff43c4b 0x2feae541 0x2feae323 0x34be52eb 0x327651e5 0x8c439 0x8c3c0)

`libc++abi.dylib:` terminating with uncaught exception of type `NSException`

当我启用纵向模式时,一切都照常工作,但我不想启用纵向模式。解决方法是什么?

4

4 回答 4

8

是的,我在应用程序中有类似的问题

您可以将纵向模式支持添加到应用程序,但将所有其他视图限制为仅支持横向、模式,然后图像选择器将起作用

UIImagePickerViewController仅适用于纵向模式

要限制其他视图仅支持横向模式,请在视图控制器中覆盖 - (NSUInteger)supportedInterfaceOrientations

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscape;
}
于 2013-09-25T07:23:18.970 回答
1

在 appdelegate.m 文件中添加以下代码片段。这将解决上述问题。

 -(NSUInteger)application:(UIApplication *)application 
supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
     {
         return UIInterfaceOrientationMaskAll;
     }
     else
     {
         return UIInterfaceOrientationMaskAllButUpsideDown;
     }
}
于 2015-08-31T06:23:49.103 回答
0

The CGAffineTransform property of UIImagePickerController can be used to get the camera in desired orientation. imagePicker.cameraViewTransform=CGAffineTransformRotate(yourimagePicker.cameraViewTransform, M_PI/2);

Alternatively you can also use CGAffineTransformScale to apply custom size to your camera.

于 2014-11-26T11:05:28.920 回答
0

您可以使用简单地呈现 imagePicker

ImagePickerController *imagePickerController=[[ImagePickerController alloc]init];
imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
于 2016-10-14T12:56:26.163 回答