离开视图控制器时停止AVCaptureSession

3

我有一个带有AVCaptureSession的ViewController。我可以轻松地开始和停止AVCaptureSession:

var captureSession: AVCaptureSession?
captureSession = AVCaptureSession()

//start
captureSession?.startRunning() 

//stop
captureSession?.stopRunning() 

我想知道当用户打开另一个ViewController时,如何停止AVCaptureSession。

例如,在 viewWillDisappear 中? - Larme
1个回答

1
只需让viewWillDisappear方法为您处理即可。
override func viewWillDisappear(animated: Bool) {
    super.viewWillDisappear(animated)
    captureSession?.stopRunning()
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接