我是swift和Xcode的新手,正在尝试为我的应用构建自定义相机。我在这里遵循这个教程: https://github.com/codepath/ios_guides/wiki/Creating-a-Custom-Camera-View
我正在使用Xcode 8.1,我的ios部署目标是ios 10.0
应用运行正常,直到我将videoPreviewLayer添加到视图中。这是代码
videoPreviewLayer = AVCaptureVideoPreviewLayer(session: session)
videoPreviewLayer!.videoGravity = AVLayerVideoGravityResizeAspect
videoPreviewLayer!.connection?.videoOrientation = AVCaptureVideoOrientation.Portrait
previewView.layer.addSublayer(videoPreviewLayer!)
session!.startRunning()
应用程序在
行崩溃 previewView.layer.addSublayer(videoPreviewLayer!)
控制台出错
fatal error: unexpectedly found nil while unwrapping an Optional value
2016-12-13 00:03:43.274268 smarticannativetest2[682:172753] fatal error: unexpectedly found nil while unwrapping an Optional value
我也得到以下
Thread 1: EXC_BREAKPOINT(code=1, subcode=0x1002f51ec)
我做错了什么,我怎么能让它发挥作用? 感谢