自定义相机视图Swift iOS 8 iPhone xCode 6.1 [英] Custom camera view Swift iOS 8 iPhone xCode 6.1

查看:470
本文介绍了自定义相机视图Swift iOS 8 iPhone xCode 6.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的iPhone里面使用相机视图。我不想使用典型的全屏相机视图,但是我自己的。



例如,我想在屏幕的中间有一个正方形200x200,相机预览。在这个正方形下面,我想要一个按钮拍照。怎么做?我是快速的初学者。

解决方案

您将需要使用 AVFoundation 框架在您在故事板中创建的视图中创建自己的 AVCaptureSession 。这是一个很好的教程,告诉您如何找到相机和创建捕获会话:



http://jamesonquave.com/blog/taking-control-of-the-iphone-camera-in- ios-8-with-swift-part-1 /



本教程使用整个视图作为捕获视图,如果你在他的代码之后建模。要在屏幕中间制作一个200x200的广场,你必须在你的故事板中的视图控制器上绘制一个,将它链接到swift文件中的所有代码都要执行的变量,然后改变底部的部分

  previewLayer?.frame = self.view.layer.frame 

your200by200View.layer.frame



<希望这可以帮助。如果没有,我可以尝试帮助更多,或者有人可以更正我。



祝你好运!


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!

这篇关于自定义相机视图Swift iOS 8 iPhone xCode 6.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆