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

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

问题描述

我在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;

并将其添加到popover控制器:

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

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

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

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



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



UPDATE



我已经从这里并且更进一步。



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

  switch([UIApplication sharedApplication] .statusBarOrientation){
case UIInterfaceOrientationLandscapeLeft:
self.imagePicker.view.transform = CGAffineTransformMakeRotation(M_PI / 2);
休息;
case UIInterfaceOrientationLandscapeRight:
self.imagePicker.view.transform = CGAffineTransformMakeRotation(-M_PI / 2);
休息;
默认值:
break;
}

只要我不转身iPad就可以使用。为此,我正在注册方向更改事件:

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

并更改选择器视图:

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

if(self.imagePicker){
switch([UIApplication sharedApplication] .statusBarOrientation){
case UIInterfaceOrientationLandscapeLeft:
self.imagePicker.view.transform = CGAffineTransformMakeRotation(M_PI / 2);
休息;
case UIInterfaceOrientationLandscapeRight:
self.imagePicker.view.transform = CGAffineTransformMakeRotation(-M_PI / 2);
休息;
默认值:
break;
}
}
}

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



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



UPDATE 2



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



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

  @implementation QPImagePickerController 

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

- (BOOL)shouldAutorotate {
返回YES;
}

- (NSUInteger)supportedInterfaceOrientations {
返回UIInterfaceOrientationMaskLandscape;
}

@end

我正在使用imagepicker全屏而不是弹出窗口。到目前为止在iOS7中测试过。

解决方案

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

休息;

case UIInterfaceOrientationLandscapeRight:

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

休息;

case UIInterfaceOrientationPortraitUpsideDown:

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

休息;

默认值:
break;
}

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

[__popoverController presentPopoverFromRect:presentationRect inView:self.view allowedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

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


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

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.

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.

UPDATE

I have taken the answer from here and came a step further.

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

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

and change the picker view:

- (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.

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?

UPDATE 2

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.

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

and I am using the imagepicker in fullscreen instead in a popover. Tested so far in 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];

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天全站免登陆