2015-06-04 214 views
1

我知道很多人都問過這個問題,但是我找不到一些正確的答案來解決這個問題,我的問題是:如何在預覽視圖(後用戶點擊捕捉按鈕,然後去預覽視圖,讓用戶預覽)不鏡像,可以在UIImagePickerController,我知道如何旋轉照片,在枚舉UIImageOrientationUIImageOrientationUp,我知道這是什麼意思。

UIImagePickerController前置攝像頭在預覽視圖中顯示鏡像

嘗試1:

我顧不上讓使用者開關拍攝後照片按鈕之前去預覽查看和使用,我有鏡子覆蓋默認照片的照片(使用cameraOverlayView) ,我可以檢測到用戶點擊捕獲按鈕使用NSNotificationCenter@「_ UIImagePickerControllerUserDidCaptureItem」,但我找不到照片的方式。

嘗試2:

我使用cameraViewTransform,但是當用戶拍照(前置攝像頭)時在底部或頂部,在預覽視圖的圖像主頁按鈕不是鏡,但是當Home按鈕在左側或右側,手機上的圖像在用戶點擊捕獲之前有一些問題,但預覽視圖上的圖像不是鏡像。使用AVCaptureDeviceDidStartRunningNotification通知。

- (void)cameraChanged:(NSNotification *)notification 
{ 
    if(self.imagePickerController.cameraDevice == UIImagePickerControllerCameraDeviceFront) 
    { 
    self.imagePickerController.cameraViewTransform = CGAffineTransformIdentity; 
    self.imagePickerController.cameraViewTransform = CGAffineTransformScale(self.imagePickerController.cameraViewTransform, -1, 1); 
    if (self.imagePickerController.cameraOverlayView) { 
     NSLog_DEBUG(@"self.imagePickerController.cameraOverlayView is not nil"); 
    } else { 
     NSLog_DEBUG(@"self.imagePickerController.cameraOverlayView is nil"); 
    } 
    self.imagePickerController.cameraOverlayView.transform = CGAffineTransformScale(self.imagePickerController.cameraViewTransform, -1, 1); 
    } else { 
    self.imagePickerController.cameraViewTransform = CGAffineTransformIdentity; 
    } 
} 

回答

2

最後,我解決不了這個問題UIImagePickerController,但我解決了使用AVFoundationCoreMotion這個問題,你可以看到AVCam

//init the motionManager 
- (void)initializeMotionManager{ 
    motionManager = [[CMMotionManager alloc] init]; 
    motionManager.accelerometerUpdateInterval = .1; 
    motionManager.gyroUpdateInterval = .1; 

    [motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue currentQueue] 
            withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) { 
             if (!error) { 
              [self outputAccelertionData:accelerometerData.acceleration]; 
             } 
             else{ 
              NSLog_DEBUG(@"%@", error); 
             } 
            }]; 
    } 

//detect the device orientation 
- (void)outputAccelertionData:(CMAcceleration)acceleration{ 

    if (acceleration.x >= 0.75) { 
     _orientationNew = UIInterfaceOrientationLandscapeLeft; 
    } 
    else if (acceleration.x <= -0.75) { 
     _orientationNew = UIInterfaceOrientationLandscapeRight; 
    } 
    else if (acceleration.y <= -0.75) { 
     _orientationNew = UIInterfaceOrientationPortrait; 
    } 
    else if (acceleration.y >= 0.75) { 
     _orientationNew = UIInterfaceOrientationPortraitUpsideDown; 
    } 
    else { 
     // Consider same as last time 
     return; 
    } 

    if (_orientationNew == _orientationLast) 
     return; 

    _orientationLast = _orientationNew; 
} 
相關問題