在我的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))
...
}
这很有效。但是,问题是它加载了我在故事板中为这个特定视图所拥有的元素(按钮)。 如何在相机预览视图中加载我的情节提要元素?
答案 0 :(得分:1)
更新lib中的行
https://github.com/bwearley/BESwiftCamera/blob/master/BESwiftCamera/BESwiftCamera.swift#L139
vc.view.addSubview(self.view)
到
vc.view.insertSubview(self.view, atIndex: 0)