UIImagePickerController cameraViewTransform不适用于iOS 10

问题描述:

我已经在我的应用程序中实现了摄像头覆盖视图。相机覆盖视图在iOS 9中运行良好。但iOS 10 cameraViewTransform无法解决此问题。请指导我。由于UIImagePickerController cameraViewTransform不适用于iOS 10

我的工作代码

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

试试这个:

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

+0

谢谢,我会检查并更新你@Jamshed Alam –

+0

好的。如果您再次遇到问题,请告诉我。 –

+0

我已经使用过您的代码,但仍然无法使用@ Jamshed Alam –

iOS 10.2修复了这个问题!您现在可以在再次出现相机之前使用cameraViewTransform属性。