2016-11-02 50 views
2

我已經在我的應用程序中實現了攝像頭覆蓋視圖。相機覆蓋視圖在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]; 

回答

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

+0

謝謝,我會檢查並更新你@Jamshed Alam –

+0

好的。如果您再次遇到問題,請告訴我。 –

+0

我已經使用過您的代碼,但仍然無法使用@ Jamshed Alam –

1

iOS 10.2修復了這個問題!您現在可以在再次出現相機之前使用cameraViewTransform屬性。

相關問題