简体   繁体   English

iOS 6中不推荐使用方向

[英]Orientation deprecated in iOS 6

Looks like orientation for avcapturevideopreviewlayer has been depreciated in iOS 6. Anyone know the new code? 看起来avcapturevideopreviewlayer的方向已在iOS 6中折旧。任何人都知道新代码? Here is my current (depreciated) code: 这是我目前的(折旧)代码:

[self setPreviewLayer:[[AVCaptureVideoPreviewLayer alloc] initWithSession:[self captureSession]]];
[[self previewLayer] setVideoGravity:AVLayerVideoGravityResizeAspectFill];
previewLayer.orientation = UIInterfaceOrientationLandscapeRight;

Did you check the documentation? 你查过文件了吗? It's only one line: 它只有一行:

The layer's orientation. 图层的方向。 (Deprecated in iOS 6.0. Use videoOrientation (AVCaptureConnection) instead.) (在iOS 6.0中不推荐使用。请改用videoOrientation (AVCaptureConnection)。)

so use: 所以使用:

[[AVCaptureVideoPreviewLayer connection] setVideoOrientation: AVCaptureVideoOrientationLandscapeRight];

or 要么

AVCaptureVideoPreviewLayer.connection.videoOrientation= AVCaptureVideoOrientationLandscapeRight;

I tried to use videoOrientation(AVCaptureConnection) instead of the deprecated orientation(AVCaptureVideoPreviewLayer), but it did not rotate the video preview anymore. 我尝试使用videoOrientation(AVCaptureConnection)而不是弃用的方向(AVCaptureVideoPreviewLayer),但它不再旋转视频预览。

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. 问题是我在将AVCaptureDeviceInput添加到AVCaptureSession之前添加并修改了AVCaptureVideoPreviewLayer。 Therefore the connection of my AVCaptureVideoPreviewLayer was null. 因此,我的AVCaptureVideoPreviewLayer的连接为空。 The solution was to add the AVCaptureVideoPreviewLayer after I added the AVCaptureDeviceInput to my AVCaptureSession. 解决方案是在我将AVCaptureDeviceInput添加到AVCaptureSession之后添加AVCaptureVideoPreviewLayer。

Just like @Nikolai posted, use the AVCaptureVideoPreviewLayer's connection's videoOrientation property instead. 就像@Nikolai发布的那样,使用AVCaptureVideoPreviewLayer的连接的videoOrientation属性。

(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.) (我之所以再次发布这个原因是因为他的代码可能有点令人困惑,因为看起来connection是一个类方法。希望这个例子说得清楚。)

Replace the following: 替换以下内容:

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

With: 附:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM