Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Orientation deprecated in iOS 6

Tags:

iphone

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

[self setPreviewLayer:[[AVCaptureVideoPreviewLayer alloc] initWithSession:[self captureSession]]];
[[self previewLayer] setVideoGravity:AVLayerVideoGravityResizeAspectFill];
previewLayer.orientation = UIInterfaceOrientationLandscapeRight;
like image 743
Marsman Avatar asked Oct 31 '12 14:10

Marsman


2 Answers

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;
like image 51
Nikolai Ruhe Avatar answered Sep 29 '22 21:09

Nikolai Ruhe


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.

like image 36
ediheld Avatar answered Sep 29 '22 20:09

ediheld