博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[翻译] LLSimpleCamera
阅读量:5886 次
发布时间:2019-06-19

本文共 3110 字,大约阅读时间需要 10 分钟。

LLSimpleCamera A simple customizable camera control

LLSimpleCamera is a library for creating a customized camera screens similar to snapchat's. You don't have to present the camera in a new view controller.

LLSimpleCamera是一个开源库,帮助你创建自定义的照相机,类似于应用snapchat那样子的效果。你不需要重新在新控制器中创建出照相机。

LLSimpleCamera:

  • lets you easily capture photos 能让你非常容易的截取图片
  • handles the position and flash of the camera 能控制照相机的位置以及照相机闪光灯
  • hides the nitty gritty details from the developer 隐藏各种恶心的代码细节
  • don't have to be presented in a new modal view controller, simply can be embedded any of your VCs. (like Snapchat) 可以快速的嵌入到你的控制器当中

Version 1.1.1

  • fixed a potential crash scenario if -stop() is called multiple times 修复了一个重复调用-stop()导致崩溃的问题

Version 1.1.0

  • fixed a problem that sometimes caused a crash after capturing a photo. 修复了有时候获取图片时崩溃的问题
  • improved code structure, didChangeDevice delegate is now also triggered for the first default device.  改进代码结构,didChangeDevice代理方法如今已经可以控制第一个默认的设备了

Install

pod 'LLSimpleCamera', '~> 1.1'

Example usage - 如何使用

CGRect screenRect = [[UIScreen mainScreen] bounds];// create camera vcself.camera = [[LLSimpleCamera alloc] initWithQuality:CameraQualityPhoto];// attach to the view and assign a delegate[self.camera attachToViewController:self withDelegate:self];// set the camera view frame to size and origin required for your appself.camera.view.frame = CGRectMake(0, 0, screenRect.size.width, screenRect.size.height);

and here are the example delegates:

这是代理的使用方式:

/* camera delegates */- (void)cameraViewController:(LLSimpleCamera *)cameraVC didCaptureImage:(UIImage *)image {    // we should stop the camera, since we don't need it anymore. We will open a new vc.    [self.camera stop];    ImageViewController *imageVC = [[ImageViewController alloc] initWithImage:image];    [self presentViewController:imageVC animated:NO completion:nil];}- (void)cameraViewController:(LLSimpleCamera *)cameraVC didChangeDevice:(AVCaptureDevice *)device {    // device changed, check if flash is available    if(cameraVC.isFlashAvailable) {        self.flashButton.hidden = NO;    }    else {        self.flashButton.hidden = YES;    }    self.flashButton.selected = NO;}

Adding the camera controls - 添加照相机控制

You have to add your own camera controls (flash, camera switch etc). Simply add the controls to the view that the camera is attached to. You can see a full camera example in the example project. Download and try it on your device.

你需要添加你自己的照相机控制(闪光灯,照相机等等诸如此类的)。你只需要简单的将控制相关的控件添加上去就可以,你可以在示例代码中看一下就知道了。

Stopping and restarting the camera

You should never forget to stop the camera either after the didCaptureImage delegate is triggered, or inside somewhere -viewWillDisappear of the parent controller to make sure your app doesn't try to use the camera when it is not needed. You can call -start() again to use the camera. So it may be good idea to to place -start() inside -viewWillAppear or some other method where you think it's good to start using the camera input.

你永远都不应该忘记不用的时候要调用didCaptureImage,或者在其他地方调用-viewWillDisappear。你可以在需要用的时候重新执行-start(),所以,比较便利的方法,就是你将-start()方法放到-viewWillAppear,或者其他的方法当中,你觉得方便就行。

 

转载地址:http://uhoix.baihongyu.com/

你可能感兴趣的文章
对象并不一定都是在堆上分配内存的
查看>>
刘宇凡:罗永浩的锤子情怀只能拿去喂狗
查看>>
php晚了8小时 PHP5中的时间相差8小时的解决办法
查看>>
JS(JavaScript)的初了解7(更新中···)
查看>>
svn文件管理器的使用
查看>>
Ansible playbook 使用
查看>>
for/foreach/linq执行效率测试
查看>>
js /jquery停止事件冒泡和阻止浏览器默认事件
查看>>
长春理工大学第十四届程序设计竞赛(重现赛)I.Fate Grand Order
查看>>
好作品地址
查看>>
[翻译]Protocol Buffer 基础: C++
查看>>
runloop与线程的关系
查看>>
[Bzoj2246]迷宫探险(概率+DP)
查看>>
详解消息队列的设计与使用
查看>>
使用Sqoop从mysql向hdfs或者hive导入数据时出现的一些错误
查看>>
控制子窗口的高度
查看>>
处理 Oracle SQL in 超过1000 的解决方案
查看>>
Alpha线性混合实现半透明效果
查看>>
chkconfig 系统服务管理
查看>>
ORACLE---Unit04: SQL(高级查询)
查看>>