iOS 6中的UIImagePickerController无法正常工作 [英] UIImagePickerController in iOS 6 doesn't work properly

查看:108
本文介绍了iOS 6中的UIImagePickerController无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常奇怪的行为:

I'm having a very strange behavior:


  1. 在iOS 5中我出现 UIImagePickerController 以这种方式:

  1. in iOS 5 I present UIImagePickerController in this way:

imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.modalPresentationStyle = UIModalPresentationFullScreen;
imagePicker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

[self presentModalViewController:imagePicker animated:YES];

现在在iOS 6会产生崩溃。我通过在 UIImagePickerController 上写一个类别来解决崩溃:

now in iOS 6 this produce a crash. I resolved the crash by writing a category on UIImagePickerController:

@implementation UIImagePickerController (NonRotating)

- (BOOL)shouldAutorotate
{
    return NO;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationMaskPortrait;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

@end

现在的问题是 UIImagePickerController 不会旋转,它显示在上方。此外,当我按下取消按钮并且选择器被解雇时,应用程序再次崩溃。

The problem is that now the UIImagePickerController doesn't rotate and it's shown up-side. Moreover, when I press the "cancel" button and the picker is dismissed, the app crash again.


  1. 如果我使用 UIImagePickerController UIPopoverController 中,一切正常(属于弹出窗口不旋转的事实)但是当我解除弹出窗口时我的应用中的所有视图控制器停止响应轮换事件,这导致所有应用都以此方向被阻止。要恢复正确的行为,我需要从后台退出应用并再次打开。

  1. If I use the UIImagePickerController inside a UIPopoverController, all works fine (belonging to the fact that the popover doesn't rotate) but when I dismiss the popover ALL view controller in my app stop responding to rotation events and this cause that all app is blocked in this orientation. To restore the correct behavior I need to quit the app from the background and open again.

这是我用来代码的代码显示popover

This is the code I'm using to display popover

_cameraPopoverController = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[_cameraPopoverController presentPopoverFromRect:_takeFromCamera.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

这个问题让我抓狂!

推荐答案

虽然我不建议使用类别来覆盖图像选择器的默认行为,但实现中存在一个错误引起崩溃:

While I don't recommend using the category to override the image picker's default behavior, there is a bug in the implementation that causes the crash mentioned:

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationMaskPortrait;
                                 ~~~~
}

返回值不应该是取向掩模,它应该是一个方向,例如UIInterfaceOrientationPortrait。

The return value shouldn't be an orientation mask, it should be an orientation, e.g. UIInterfaceOrientationPortrait.

这篇关于iOS 6中的UIImagePickerController无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆