Force iOS view to not rotate, while still allowing child to rotate

前端 未结 6 726
粉色の甜心
粉色の甜心 2021-02-02 02:42

I have a view controller with a child view controller.

tab bar controller
|
|
nav controller
|
|
UIPageViewController (should rotate)
|
|
A (Video Player) (shoul         


        
6条回答
  •  无人共我
    2021-02-02 03:26

    The simplest, most straight-forward answer to this question is to look at Apple's AVCam sample code. The key parts for me were that it:

    1. Uses a view whose layerClass is AVCaptureVideoPreviewLayer.
    2. Sets the videoOrientation of the AVCaptureVideoPreviewLayer's connection to match the application's statusBarOrientation when the view is presented, essentially viewWillAppear(_:).
    3. Sets the videoOrientation to match UIDevice.currentDevice().orientation in viewWillTransitionToSize(_:withTransitionCoordinator:).
    4. Enables autorotation and supports all interface orientations.

    I implemented the background window approach described by jstn and it worked fairly well, but the reality is that it is much more complicated than is necessary. AVCam works great and has relatively simple approach.

提交回复
热议问题