Custom camera view Swift iOS 8 iPhone Xcode 6.1

前端 未结 3 1194
予麋鹿
予麋鹿 2021-01-31 12:31

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

3条回答
  •  清歌不尽
    2021-01-31 13:27

    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!

提交回复
热议问题