【问题标题】:AVCaptureVideoPreviewLayer autorotation under Size classesSize类下的AVCaptureVideoPreviewLayer自动旋转
【发布时间】:2017-08-31 10:15:05
【问题描述】:

一旦 AVCaptureSession 开始运行,我将手动创建一个 AVCaptureVideoPreviewLayer(一种 CALayer)并将其添加到 UIView,如下所示:

 func captureSessionStartedRunning(session:AVCaptureSession?) {
    if let captureSession = session {
        if let previewLayer = AVCaptureVideoPreviewLayer.init(session: captureSession) {
            previewLayer.frame = self.view.bounds
            self.view.layer.addSublayer(previewLayer)
            previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
        }
    }
}

我对大小类的自动旋转没有经验,所以有人可以告诉我在这里处理自动旋转的最简单方法是什么?

【问题讨论】:

    标签: ios calayer ios-autolayout size-classes autorotate


    【解决方案1】:

    覆盖:

    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubViews()
        previewLayer.frame = self.view.bounds
    }
    

    每当您的视图布局发生变化时,它都会将图层的大小更新为视图的大小。

    您可能还想将 previewLayer 的 .videoGravity 更改为 .aspectFill

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-25
      • 1970-01-01
      相关资源
      最近更新 更多