AVCaptureVideoPreviewLayer预览位置从导航栏(工具栏)开始

时间:2017-09-08 11:37:13

标签: swift swift3 avcapturesession

嗨,我是一个快速的新蜜蜂。试图使用AVCaptureVideoPreviewLayer为我的自定义相机应用程序。但捕获的图像与预览不同。 试过以下

 self.previewLayer.frame = self.view.layer.bounds
previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill

这是我的代码段

 self.previewLayer.frame = self.view.layer.bounds
        self.view.layer.insertSublayer(self.previewLayer!, at: 0 )
        previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
         captureSession.startRunning()

        let dataOutput = AVCaptureVideoDataOutput()
        dataOutput.videoSettings = [(kCVPixelBufferPixelFormatTypeKey as NSString):NSNumber(value:kCVPixelFormatType_32BGRA)]

        dataOutput.alwaysDiscardsLateVideoFrames = true[capture screen][1]

result [![enter image description here图像] 2] 2

1 个答案:

答案 0 :(得分:1)

在UINavigationController中,视图位置以(x:0,y:0)开头是默认值。导航栏与视图重叠64px(20px =状态栏,44px =导航栏)高度。您有两个选项修复视频预览图层框架:

<强>选项1:

更改previewLayer的Y位置,

<connectionStrings>
    <add name="DefaultConnection" 
         connectionString="Data Source=.;Initial Catalog=WebFormsIdentity;Trusted_Connection=Yes;Integrated Security=True"  
         providerName="System.Data.SqlClient" />
 </connectionStrings>

<强>选项2:

var frame = self.view.layer.bounds
frame.origin.y = 64
frame.size.height = frame.size.height-64
self.previewLayer.frame = frame

在ViewdidLoad()方法中添加此行。 默认为self.navigationController?.navigationBar.isTranslucent = false, ,分配isTranslucent = true表示视图帧位置从x:0和y开始:64。

无需使用 Option2

更改您的代码