ios - 在 iOS 7 中呈现 UIImagePickerController 的问题

标签 ios iphone objective-c xcode ipad

我的应用程序只在横向模式下运行!所以我知道 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 ,这个问题就可以解决: enter image description here

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

我该如何解决这个问题?

最佳答案

我已经对其进行了测试,发现您不应该通过目标窗口中的复选框处理方向,如上图所示,因为它是您的整个应用程序方向,因此请选中所有框以支持所有方向。如果您想要一些不同方向的 View 和一些不同方向的 View ,那么您将必须通过返回 YESNOViewController 类中进行编码来处理它用于定位。

这是我的 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/

相关文章:

ios - 如何在应用程序中保存用户名和密码,以便我们不需要登录应用程序?

ios - 在 ios 中使用 LongGestureRecognizer 更改 View 选定部分的颜色

iphone - 我是否正确使用 CNCopyCurrentNetworkInfo?

ios - 使用 WhatsApp URL Scheme 发送我的 App URL Scheme

objective-c - UIDatePicker 具有 15m 间隔但总是准确的时间作为返回值

Objective-C – 用一个空格替换换行序列

ios - 如何使用 objective-c 查看 PDF 文件中的数字签名

带 SSL 的 C# 异步 Tcp 服务器。如何使用 iOS NSStream 进行相互认证?

ios - Twilio 客户端 ios 调用的任何示例代码

iphone - 在 Objective-c 中截断字符串并在末尾添加省略号