iPad iOS7 - UIPopoverController 中的 UIImagePickerController 有错误的预览图像 [英] iPad iOS7 - UIImagePickerController in UIPopoverController has wrong preview image

查看:21
本文介绍了iPad iOS7 - UIPopoverController 中的 UIImagePickerController 有错误的预览图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using an UIImagePickerController within an UIPopoverController which is working perfectly with iOS6. With iOS 7 the "preview" image which is shown to capture the image is rotated, but if I take a picture it is saved correctly.

这就是我如何得到我的选择器:

This is how I get my picker:

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

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

And add it to a popover controller:

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];

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

Those are calculations for the button position at a UIScrollView to show the popover at the correct position:

presentPopoverFromRect:CGRectMake(aPosViewA.x, cameraButton_y, 100.0, 30.0)

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

I don't think that the problem lies there as I have tried out several combinations.

我也尝试在全屏模式下捕获图像,但该应用程序只能使用横向模式.如果图像是在纵向模式下拍摄的并且模式视图被关闭,应用程序也会保持在纵向模式.如果模态视图被关闭,我找不到阻止 UIImagePickerController 切换到纵向模式或强制应用返回横向模式的方法.

I have also tried to capture the image in fullscreen-mode, but the app is only allowed to use landscape mode. If the image is taken in portrait-mode and the modal view is dismissed, the app stays in portrait mode as well. I couldn't find a way to prevent the UIImagePickerController to switch to portrait mode or to force the app back to landscape mode if the modal view was dismissed.

更新

我从 此处 并更进一步.

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

I transform the view after creating the picker and before showing the popover :

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;
    }

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

which works as long as i don't turn around the iPad. For that I am registering for the orientation changed event:

[[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(orientationChanged:)  name:UIDeviceOrientationDidChangeNotification  object:nil];

并更改选择器视图:

- (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;
        }
    }
}

遗留问题:正如我在开头写的那样,当照片被拍摄时,它被正确地显示为接受或拒绝它.这现在也发生了转变.不知何故,我需要知道何时拍摄图像并将其转换回来.

REMAINING PROBLEM: As I wrote in the beginning, when the picture was taken, it was shown correctly to accept or dismiss it. This is now transformed as well. Somehow I need to know when the image is taken and transform it back.

而且,这确实是一个令人讨厌的黑客行为,可能不适用于下一个 iOS 更新.有没有人知道如何以更简洁的方式实现它?

AND, this is really a nasty hack and probably won't work with the next iOS Update. Has anybody an idea how to implement that in a cleaner way?

更新 2

这太令人讨厌了,我找到了一个更简洁的解决方案,它可以解决我的问题,但不是关于弹出框控制器中的图像选择器的初始问题的答案,Apple 不推荐,但允许这样做.

This was too nasty, I have found a cleaner solution which solves my problem but is not the answer to the initial question regarding an imagepicker in a popover controller, which is not recommended by Apple, but allowed.

我现在已经子类化了 UIImagePickerController,如下所示:

I have subclassed now the UIImagePickerController like this:

@implementation QPImagePickerController

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

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscape;
}

@end

我在全屏中使用图像选择器而不是在弹出窗口中.目前已在 iOS7 中测试.

and I am using the imagepicker in fullscreen instead in a popover. Tested so far in iOS7.

推荐答案

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

The UIImagePickerController has a property called cameraViewTransform. Applying a CGAffineTransform to this will transform the preview image but will not transform the captured image which will therefore be correctly captured. I have the same problem that you describe and I solved it (for iOS7) by creating my camera controller and placing it in a popover as follows:

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];

我还在横向时缩放图像,以便它比其他情况下更多地填充取景器.在我看来,这一切都相当糟糕,但我希望在 iOS7.1 到来后能够将其删除.

I also scale the image when in Landscape so that it fills the viewfinder more than it otherwise would. To my mind this is all rather nasty, but I will hopefully be able to remove it once iOS7.1 arrives.

这篇关于iPad iOS7 - UIPopoverController 中的 UIImagePickerController 有错误的预览图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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