iPad iOS7 - UIPopoverController中的UIImagePickerController具有错误的预览图像

Mar*_*zen 26 uiimagepickercontroller uipopovercontroller uiinterfaceorientation ios ios7

我在UIPopoverController中使用UIImagePickerController,它与iOS6完美配合.使用iOS 7时,显示捕获图像的"预览"图像会旋转,但如果我拍照,则会正确保存.

这就是我选择的方式:

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
                              (NSString *) kUTTypeImage,
                              nil];
imagePicker.allowsEditing = NO;
Run Code Online (Sandbox Code Playgroud)

并将其添加到弹出控制器:

self.imagePickerPopOver = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
    [self.imagePickerPopOver presentPopoverFromRect:CGRectMake(aPosViewA.x, cameraButton_y, 100.0, 30.0) inView:self.detailViewController.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
Run Code Online (Sandbox Code Playgroud)

这些是UIScrollView上按钮位置的计算,以显示正确位置的弹出窗口:

presentPopoverFromRect:CGRectMake(aPosViewA.x, cameraButton_y, 100.0, 30.0)
Run Code Online (Sandbox Code Playgroud)

我不认为问题就在那里,因为我尝试了几种组合.

我还尝试在全屏模式下捕获图像,但应用程序只允许使用横向模式.如果以纵向模式拍摄图像并且取消模态视图,则应用程序也将保持纵向模式.如果模态视图被解除,我找不到阻止UIImagePickerController切换到纵向模式或强制应用程序回到横向模式的方法.

UPDATE

我从这里得到了答案,又向前迈进了一步.

我在创建选择器之后和显示弹出窗口之前转换视图:

switch ([UIApplication sharedApplication].statusBarOrientation) {
        case UIInterfaceOrientationLandscapeLeft:
            self.imagePicker.view.transform = CGAffineTransformMakeRotation(M_PI/2);
            break;
        case UIInterfaceOrientationLandscapeRight:
            self.imagePicker.view.transform = CGAffineTransformMakeRotation(-M_PI/2);
            break;
        default:
            break;
    }
Run Code Online (Sandbox Code Playgroud)

只要我不转动iPad,它就能正常工作.为此,我正在注册方向更改事件:

[[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(orientationChanged:)  name:UIDeviceOrientationDidChangeNotification  object:nil];
Run Code Online (Sandbox Code Playgroud)

并更改选择器视图:

- (void)orientationChanged:(NSNotification *)notification{

    if (self.imagePicker) {
        switch ([UIApplication sharedApplication].statusBarOrientation) {
            case UIInterfaceOrientationLandscapeLeft:
                self.imagePicker.view.transform = CGAffineTransformMakeRotation(M_PI/2);
                break;
            case UIInterfaceOrientationLandscapeRight:
                self.imagePicker.view.transform = CGAffineTransformMakeRotation(-M_PI/2);
                break;
            default:
                break;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

遗留问题:正如我在开始时写的那样,拍摄照片时,它被正确地显示为接受或解散它.现在也改变了.不知怎的,我需要知道何时拍摄图像并将其转换回来.

而且,这真是一个讨厌的黑客,可能无法与下一个iOS更新一起使用.有谁知道如何以更清洁的方式实现它?

更新2

这太糟糕了,我找到了一个更清晰的解决方案来解决我的问题,但不是关于弹出控制器中的图像选择器的初始问题的答案,这不是Apple推荐的,但是允许的.

我现在已经将UIImagePickerController子类化为这样:

@implementation QPImagePickerController

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscape;
}

@end
Run Code Online (Sandbox Code Playgroud)

我在全屏幕中使用imagepicker而不是在popover中.到目前为止在iOS7中测试过.

Jou*_*man 14

UIImagePickerController有一个名为cameraViewTransform的属性.对此应用CGAffineTransform将转换预览图像,但不会转换因此将被正确捕获的捕获图像.我有你描述的同样的问题,我解决了它(对于iOS7),通过创建我的相机控制器并将其放置在弹出框中,如下所示:

UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];

[imagePickerController setDelegate:self];

imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;

CGFloat scaleFactor=1.3f;

switch ([UIApplication sharedApplication].statusBarOrientation) {

        case UIInterfaceOrientationLandscapeLeft:

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

            break;

        case UIInterfaceOrientationLandscapeRight:

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

            break;

        case UIInterfaceOrientationPortraitUpsideDown:

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

            break;

            default:
                break;
        }

 __popoverController = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];

[__popoverController presentPopoverFromRect:presentationRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
Run Code Online (Sandbox Code Playgroud)

我还在横向拍摄时缩放图像,使其比其他情况更能填充取景器.在我看来,这一切都很讨厌,但是一旦iOS7.1到货,我希望能够删除它.