UIImagePickerController cameraViewTransform在iOS 10中不起作用

时间:2016-11-02 07:36:58

标签: objective-c uiimagepickercontroller ios10 ios-camera

我在我的应用程序中实现了相机叠加视图。相机叠加视图在iOS 9中运行良好。但iOS 10 cameraViewTransform无法正常工作如何解决此问题。请指导我。感谢

我的工作代码

CGSize screenBounds = [UIScreen mainScreen].bounds.size;
CGFloat cameraAspectRatio = 4.0f/3.0f;
CGFloat camViewHeight = screenBounds.width * cameraAspectRatio;
CGFloat scale = screenBounds.height / camViewHeight;
picker.cameraViewTransform = CGAffineTransformMakeTranslation(0, (screenBounds.height - camViewHeight) / 2.0);
picker.cameraViewTransform = CGAffineTransformScale(picker.cameraViewTransform, scale, scale);

更新

OverlayView *overlay = [[OverlayView alloc]
                            initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
    picker =
    [[UIImagePickerController alloc] init];
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.showsCameraControls = NO;
    picker.navigationBarHidden = NO;
    picker.toolbarHidden = YES;

    // Device's screen size (ignoring rotation intentionally):
    CGSize screenSize = [[UIScreen mainScreen] bounds].size;

    float cameraAspectRatio = 4.0 / 3.0;
    float imageWidth = floorf(screenSize.width * cameraAspectRatio);
    float scale = ceilf((screenSize.height / imageWidth) * 10.0) / 10.0;





     picker.cameraViewTransform = CGAffineTransformScale(CGAffineTransformIdentity, 2, 2);
   picker.cameraOverlayView = overlay;
    picker.allowsEditing = NO;

    UIPinchGestureRecognizer *pinchRec = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(zoom:)];
    [overlay addGestureRecognizer:pinchRec];
    overlay.image =image;
    [self.navigationController presentViewController:picker animated:NO completion:nil];

2 个答案:

答案 0 :(得分:1)

iOS 10.2修复此问题!现在,您可以在再次展示相机之前使用cameraViewTransform属性。

答案 1 :(得分:0)

试试这个:

我在IOS 9.3中也遇到了同样的问题。这是我使用的代码

//transform values for full screen support
#define CAMERA_TRANSFORM_X 1
#define CAMERA_TRANSFORM_Y 1.12412    

        if (IS_IPAD)
            CGAffineTransformScale(objImagePickerController.cameraViewTransform, CAMERA_TRANSFORM_X,  CAMERA_TRANSFORM_Y);
        else if (IS_IPHONE_5_Land||IS_IPHONE_4_Land||IS_IPHONE_6_Land||IS_IPHONE_6_PLUS_Land)
        {
            objImagePickerController.cameraViewTransform = CGAffineTransformScale(CGAffineTransformIdentity, 2, 2);
        }

希望这会有所帮助。如需更多帮助:UIImagePickerController's cameraViewTransform is ignoring 'scaling' and 'translation' on iOS 10 beta