Katie H Katie H - 4 months ago 19
Swift Question

Adding button over camera preview view [BESwiftCamera lib]

Within my swift app, I am using this library to build a custom video camera: https://github.com/bwearley/BESwiftCamera

In my view controller:

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))
...
}


This works well. However, the issue is that it loads over the elements(buttons) I have in my storyboard for this particular view. How do I load my storyboard elements over the camera preview view?

Answer

Update the line in the lib

https://github.com/bwearley/BESwiftCamera/blob/master/BESwiftCamera/BESwiftCamera.swift#L139

    vc.view.addSubview(self.view)

to

    vc.view.insertSubview(self.view, atIndex: 0)
Comments