如何修复AVcapture会话的未解析标识符'stopRunning'错误

时间:2017-11-08 13:39:16

标签: ios swift

我正在使用swift在iOS上构建条形码扫描程序。当我第一次编写代码时,这种方法非常有效,但我最近回到编程中并发现它会抛出一些错误。 当用户按下按钮时,我有一个退出扫描按钮,它应该退出扫描模式

这是exitScan按钮

  let exitScanButton: UIButton = {
    let button = UIButton(type: .system)
    button.backgroundColor = UIColor(r: 80, g: 101, b: 161)
    button.setTitle("Exit", for: .normal)
    button.setTitleColor(UIColor.white, for: .normal)
    button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 16)
    button.translatesAutoresizingMaskIntoConstraints = false

   button.addTarget( nil, action: #selector(exitScan), for:.touchUpInside)
    return button
}()

这是我的exitScan功能

   func exitScan() -> Void {
    //Go back to ViewController
    [self.captureSession, stopRunning];
    [self.videoPreviewLayer, removeFromSuperlayer];
    self.videoPreviewLayer = nil;
    self.captureSession = nil;
    self.navigationController?.popToRootViewController(animated: true)
}

Xcode抛出两个错误

  

使用未解析的标识符'stopRunning'

     

使用未解析的标识符'removeFromSuperlayer'

这是一个错误,我该如何解决?

1 个答案:

答案 0 :(得分:1)

它的objective-c语法。

在斯威夫特:

self.catpureSession.stopRunning()

self.videoPreviewLayer.removeFromSuperLayer()

也没有分号。

相关问题