在顶部正确渲染CameraOutput

问题描述 投票:0回答:1

我有以下代码:

var body: some View {
        VStack {
            CameraView()
        }
...

override public func viewDidLoad() {
        super.viewDidLoad()
        
        // Set up the video preview view.
        previewView.session = session
        previewView.videoPreviewLayer.videoGravity = videoGravity
        previewView.videoPreviewLayer.connection?.videoOrientation = AVCaptureVideoOrientation.portrait
        previewView.frame = view.frame
...

如何让我的 CameraPreview 渲染在视图顶部。因为有那个上边距我不知道它从哪里来。

这很奇怪,如果我尝试

previewView.frame.offset(x: 0, y: -90)
,它看起来几乎完美,但这不是解决方案,这是糟糕的编码。

Here is a Screenshot

swift swiftui avfoundation avcapturesession
1个回答
0
投票

尝试使用.edgesIgnoringSafeArea

var body: some View {
    VStack {
        CameraView()
    }
    .edgesIgnoringSafeArea(.top) // Ignore the top safe area
    // ...
}
© www.soinside.com 2019 - 2024. All rights reserved.