简体   繁体   English

如何获取导航栏以在AVCapture会话中显示

[英]How to get Navigation Bar to show in AVCapture session

I have a navigation bar with a cancel button in the top left that brings the user back to the previous view. 我有一个导航栏,该导航栏的左上角有一个取消按钮,可以使用户返回上一个视图。

When the AVCapture view comes up, I can not see the bar, the view is fullscreen for the camera view. 出现AVCapture视图时,我看不到该栏,该视图对于摄像机视图是全屏的。 However, If I tap where the cancel button would be... it works fine. 但是,如果我点击取消按钮所在的位置, 它将可以正常工作。

Why can't I see the navigation bar? 为什么看不到导航栏?

override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = UIColor.blackColor()
        captureSession = AVCaptureSession()

        let videoCaptureDevice = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
        let videoInput: AVCaptureDeviceInput

        do {
            videoInput = try AVCaptureDeviceInput(device: videoCaptureDevice)
        } catch {
            return
        }

        if (captureSession.canAddInput(videoInput)) {
            captureSession.addInput(videoInput)
        } else {
            failed();
            return;
        }
        let metadataOutput = AVCaptureMetadataOutput()

        if (captureSession.canAddOutput(metadataOutput)) {
            captureSession.addOutput(metadataOutput)

            //All of the Supported Barcode Types
            metadataOutput.setMetadataObjectsDelegate(self, queue: dispatch_get_main_queue())
            metadataOutput.metadataObjectTypes = [AVMetadataObjectTypeEAN8Code, AVMetadataObjectTypeEAN13Code, AVMetadataObjectTypePDF417Code, AVMetadataObjectTypeUPCECode, AVMetadataObjectTypeCode39Code, AVMetadataObjectTypeCode39Mod43Code, AVMetadataObjectTypeCode93Code, AVMetadataObjectTypeEAN13Code, AVMetadataObjectTypeEAN8Code, AVMetadataObjectTypeCode128Code, AVMetadataObjectTypePDF417Code, AVMetadataObjectTypeQRCode, AVMetadataObjectTypeAztecCode]
        } else {
            failed()
            return
        }
        previewLayer = AVCaptureVideoPreviewLayer(session: captureSession);
        previewLayer.frame = view.layer.bounds;
        previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
        view.layer.addSublayer(previewLayer);

        captureSession.startRunning();
    }

Are you using a UINavigationController as parent of your view controller? 您是否使用UINavigationController作为视图控制器的父级?

If not, I suspect that your preview, with same size as your view, is added on top of other sub views in your controller, effectively covering them. 如果不是,我怀疑与您的视图大小相同的预览已添加到控制器中其他子视图的顶部,从而有效地覆盖了它们。 If this is the case, you can tweak the height of your preview layer to account for the navigation bar height. 在这种情况下,您可以调整预览层的高度以说明导航栏的高度。

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

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