Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom camera view Swift iOS 8 iPhone Xcode 6.1

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.

like image 611
Adam Smaka Avatar asked Feb 27 '15 15:02

Adam Smaka


Video Answer


1 Answers

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!

like image 96
Komran Ghahremani Avatar answered Oct 12 '22 05:10

Komran Ghahremani