离开ViewController时停止AVCaptureSession

时间:2016-05-23 15:22:17

标签: ios swift avcapturesession ios-camera

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

var captureSession: AVCaptureSession?
captureSession = AVCaptureSession()

//start
captureSession?.startRunning() 

//stop
captureSession?.stopRunning() 

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

1 个答案:

答案 0 :(得分:1)

让viewWillDisappear方法为您处理。

override func viewWillDisappear(animated: Bool) {
    super.viewWillDisappear(animated)
    captureSession?.stopRunning()
}