23

我的图像选择器视图控制器设置在弹出框控制器内。在 iOS 6 上一切正常,但在 iOS 7 上,图像被旋转并且所有移动都在做诗:当 iPad 向左转动时图像向下,向上移动时图像向左等等。

这是显示我的相机的代码:

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;
    imagePicker.sourceType =  UIImagePickerControllerSourceTypeCamera;

    objPopView = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
    [objPopView presentPopoverFromRect:CGRectMake(842, 163, 0, 0)
                                inView:self.view
              permittedArrowDirections:UIPopoverArrowDirectionRight
                              animated:YES];

我的应用仅使用横向模式,现在图像已旋转: 在此处输入图像描述

4

3 回答 3

17

正如苹果官方文档所说:

呈现用户界面。在 iPhone 或 iPod touch 上,通过调用当前活动视图控制器的presentViewController:animated:completion:方法以模态方式(全屏)执行此操作,将配置的图像选择器控制器作为新视图控制器传递。

iPad上,显示图像选择器的正确方法取决于其源类型,如下表所示:

  • 相机照片:使用全屏
  • 已保存库:必须使用弹出框
  • 相册:必须使用弹出框

...

在 iPad 上,如果您指定 UIImagePickerControllerSourceTypeCamera 的源类型,则可以模态(全屏)或使用弹出框呈现图像选择器。但是,Apple 建议您仅全屏显示相机界面

尽管它说“您可以以模态方式(全屏)或使用弹出框呈现图像选择器”,但正如您所看到的,使用弹出框会导致这个奇怪的问题。我想这可能是 iOS 7 SDK 上的一个错误。

我仍在尝试解决此问题,但就目前而言,我能说的唯一方法是通过模态方式显示它

-presentViewController:animated:completion:

方法,就是全屏(其实我不喜欢这种方式)。

在 Apple 的开发论坛上有一个THREAD讨论过它,你可以看看它。;)

于 2013-09-26T14:07:40.177 回答
6

尝试以下操作:

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =  UIImagePickerControllerSourceTypeCamera;

CGFloat scaleFactor=1.3f;

switch ([UIApplication sharedApplication].statusBarOrientation) {

    case UIInterfaceOrientationLandscapeLeft:

        imagePicker.cameraViewTransform = CGAffineTransformScale(CGAffineTransformMakeRotation(M_PI * 90 / 180.0), scaleFactor, scaleFactor);

        break;

    case UIInterfaceOrientationLandscapeRight:

        imagePicker.cameraViewTransform = CGAffineTransformScale(CGAffineTransformMakeRotation(M_PI * -90 / 180.0), scaleFactor, scaleFactor);

        break;

    case UIInterfaceOrientationPortraitUpsideDown:

        imagePicker.cameraViewTransform = CGAffineTransformMakeRotation(M_PI * 180 / 180.0);

        break;

        default:
            break;
    }

objPopView = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[objPopView presentPopoverFromRect:CGRectMake(842, 163, 0, 0)
                            inView:self.view
          permittedArrowDirections:UIPopoverArrowDirectionRight
                          animated:YES];

归功于https://stackoverflow.com/a/19071958/1363779

于 2014-02-06T20:16:40.510 回答
0

在 iOS7 中正常工作的唯一一种方法是使用

-presentViewController:动画:完成:

您可以尝试通过 cameraViewTransform 属性更改相机视图转换,但结果会很丑陋。将视图添加到自定义 ViewController(旋转到横向)也会给你带来丑陋的结果。我开始讨厌这个操作系统版本。

于 2013-09-26T15:27:57.473 回答