Force camera view in landscape with orientation lock on

后端 未结 1 1918
情歌与酒
情歌与酒 2021-01-03 05:39

I am developing an augmented reality game, and I\'ve encountered an issue with the orientation of the camera view when the orientation lock of the device is on.

I a

相关标签:
1条回答
  • 2021-01-03 06:14

    The reason why your Preview layer is not orientating is due the fact that you are using deprecated API and moreover you are not updating the Video orientation at the change of device orientation.

    1. Remove the deprecated API i.e in your code instead of

      captureVideoPreviewLayer.orientation
      

      use videoOrientation property i.e

      captureVideoPreviewLayer.connection.videoOrientation 
      
    2. Update the video orientation in shouldAutorotate as follows:

      - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
      {
      
          if(interfaceOrientation == UIInterfaceOrientationLandscapeRight)
          {
             captureVideoPreviewLayer.connection.videoOrientation = AVCaptureVideoOrientationLandscapeRight
          }
      
            // and so on for other orientations
      
          return ((interfaceOrientation == UIInterfaceOrientationLandscapeRight));
      }
      
    0 讨论(0)
提交回复
热议问题