【问题标题】:How to stop captureOutput in iOS app如何在 iOS 应用程序中停止 captureOutput
【发布时间】:2016-05-24 08:26:36
【问题描述】:

我找到了使用 QR 码的教程 - here it is。使用这种方法,我可以从设备摄像头获取图像并在那里找到二维码。

问题是当我更改 ViewController 甚至停止 AVCaptureSession 时 - 我的相机似乎仍在工作并且设备正在搜索 QR 码。那么我应该如何禁用 captureOutput 方法呢?

【问题讨论】:

    标签: ios swift qr-code avcapturesession avcaptureoutput


    【解决方案1】:

    我下载了演示项目并在做

     self.captureSession?.stopRunning()
    

    对我来说很好用

    全码

    func captureOutput(captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [AnyObject]!, fromConnection connection: AVCaptureConnection!) {
    
            // Check if the metadataObjects array is not nil and it contains at least one object.
            if metadataObjects == nil || metadataObjects.count == 0 {
                qrCodeFrameView?.frame = CGRectZero
                messageLabel.text = "No barcode/QR code is detected"
                return
            }
                    self.captureSession?.stopRunning()
    

    我在这个函数的开头设置了一个断点,一旦找到第一个二维码就不再调用它。

    【讨论】:

    • 这对我也有用,如果打印 captureSession?.running 它等于 false。但是当我把二维码放在相机后面时,它仍然会通知我二维码在那里。
    • @moonvader 我更新了答案,如果没有帮助,你能发布你使用的确切代码吗?
    • 我发现了问题所在 - 你的代码很好。
    • @moonvader 很高兴发布您的“找到问题解决方案” - 这是 Stackoverflow,许多人有相同的问题并正在寻找相同的答案......
    • 两年前我现在不能肯定地说出了什么问题。但运行这段代码是我的错,而不是答案的问题。
    猜你喜欢
    • 2014-06-17
    • 1970-01-01
    • 2020-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-24
    相关资源
    最近更新 更多