iPhone AVFoundation camera orientation

前端 未结 12 612
走了就别回头了
走了就别回头了 2020-12-02 09:46

I\'ve been tearing my hair out trying to get the AVFoundation camera to capture a picture in the correct orientation (i.e. the device orientation) but I can\'t get it to wor

12条回答
  •  借酒劲吻你
    2020-12-02 10:36

    This uses the view controller's orientation method. This works for me, hopefully works for you.

    - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
    {
        [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    
        AVCaptureConnection *videoConnection = self.prevLayer.connection;
        [videoConnection setVideoOrientation:(AVCaptureVideoOrientation)toInterfaceOrientation];
    }
    

提交回复
热议问题