AVCaptureVideoPreviewLayer smooth orientation rotation

后端 未结 9 898
Happy的楠姐
Happy的楠姐 2021-02-02 16:45

I\'m trying to disable any discernable orientation rotation to an AVCaptureVideoPreviewLayer while still maintaining rotation for any subviews. AVCaptureVideoPreviewLayer does h

9条回答
  •  失恋的感觉
    2021-02-02 16:47

    This is how I do it:

    - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
        if (tookFirstPicture)
            return;
    
        if (toInterfaceOrientation == UIInterfaceOrientationPortrait) {
            [previewLayer setOrientation:AVCaptureVideoOrientationPortrait];
        }
        else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
            [previewLayer setOrientation:AVCaptureVideoOrientationLandscapeLeft];
        }
        else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
            [previewLayer setOrientation:AVCaptureVideoOrientationLandscapeRight];
        }
        else {
            [previewLayer setOrientation:AVCaptureVideoOrientationPortraitUpsideDown];
        }
    }
    

提交回复
热议问题