Orientation deprecated in iOS 6

前端 未结 3 1289
轻奢々
轻奢々 2021-01-06 03:01

Looks like orientation for avcapturevideopreviewlayer has been depreciated in iOS 6. Anyone know the new code? Here is my current (depreciated) code:

[self s         


        
相关标签:
3条回答
  • 2021-01-06 03:16

    Did you check the documentation? It's only one line:

    The layer’s orientation. (Deprecated in iOS 6.0. Use videoOrientation (AVCaptureConnection) instead.)

    so use:

    [[AVCaptureVideoPreviewLayer connection] setVideoOrientation: AVCaptureVideoOrientationLandscapeRight];
    

    or

    AVCaptureVideoPreviewLayer.connection.videoOrientation= AVCaptureVideoOrientationLandscapeRight;
    
    0 讨论(0)
  • 2021-01-06 03:28

    Just like @Nikolai posted, use the AVCaptureVideoPreviewLayer's connection's videoOrientation property instead.

    (The reason I am posting this again is because his code may be a bit confusing since it looks like connection is a class method. Hopefully this example makes it clear.)

    Replace the following:

    AVCaptureVideoPreviewLayer *previewLayer = ...;
    previewLayer.orientation = UIInterfaceOrientationLandscapeRight;
    

    With:

    AVCaptureVideoPreviewLayer *previewLayer = ...;
    previewLayer.connection.videoOrientation = AVCaptureVideoOrientationLandscapeRight;
    
    0 讨论(0)
  • 2021-01-06 03:36

    I tried to use videoOrientation(AVCaptureConnection) instead of the deprecated orientation(AVCaptureVideoPreviewLayer), but it did not rotate the video preview anymore.

    I replaced this:

    AVCaptureVideoPreviewLayer *previewLayer = ...;
    previewLayer.orientation = AVCaptureVideoOrientationLandscapeRight;
    

    With this:

    AVCaptureVideoPreviewLayer *previewLayer = ...;
    previewLayer.connection.videoOrientation = AVCaptureVideoOrientationLandscapeRight;
    

    But it did not rotate the video preview. The problem was that I added and modified the AVCaptureVideoPreviewLayer before I added the AVCaptureDeviceInput to my AVCaptureSession. Therefore the connection of my AVCaptureVideoPreviewLayer was null. The solution was to add the AVCaptureVideoPreviewLayer after I added the AVCaptureDeviceInput to my AVCaptureSession.

    0 讨论(0)
提交回复
热议问题