I would like use camera in my iPhone inside of View. I don't want use typical full screen camera view, but my own.
For example I would like have a square 200x200 at the middle of the screen and there have a camera preview. Below this square I would like have a button to take a picture. How to do it? I'm swift beginer.
You'll want to use the AVFoundation
Framework to allow you to make your own AVCaptureSession
inside of a view that you create in your storyboard. Here is a nice tutorial showing you how to find the camera and create a capture session:
http://jamesonquave.com/blog/taking-control-of-the-iphone-camera-in-ios-8-with-swift-part-1/
This tutorial uses the whole view as the capture view, so that is how big the camera will be if you model it after his code. To make a 200x200 square in the middle of the screen, you have to draw one out on your view controller in your storyboard, link it to a variable in your swift file where all the code is going, and then change the part at the bottom that says,
previewLayer?.frame = self.view.layer.frame
to your200by200View.layer.frame
Hopefully this can help. If not, I can try to help some more or someone can correct me.
Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With