在我的Swift应用程序中,我正在使用该库来构建自定义摄像机:https://github.com/bwearley/BESwiftCamera
在我的视图控制器中:
var camera:BESwiftCamera!
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
self.attachCamera()
}
func attachCamera() {
do {
try self.camera.start()
} catch BESwiftCameraErrorCode.CameraPermission {
self.showCameraPermissionAlert()
} catch BESwiftCameraErrorCode.MicrophonePermission {
self.showMicrophonePermissionAlert()
} catch {
self.showUnknownErrorAlert()
}
}
override func viewDidLoad() {
super.viewDidLoad()
let screenRect = UIScreen.mainScreen().bounds
// Configure Camera
self.camera = BESwiftCamera(withQuality: AVCaptureSessionPresetHigh, position: .Rear, videoEnabled: true)
self.camera.attachToViewController(self, withFrame: CGRectMake(0,0,screenRect.size.width,screenRect.size.height))
...
}
这很好。但是,问题在于它加载了我在情节提要中针对该特定视图的元素(按钮)。如何在相机预览视图上加载情节提要板元素?
最佳答案
更新库中的行
https://github.com/bwearley/BESwiftCamera/blob/master/BESwiftCamera/BESwiftCamera.swift#L139
vc.view.addSubview(self.view)
至
vc.view.insertSubview(self.view, atIndex: 0)