[翻译] DBCamera 轻量级定制摄像头
DBCamera 轻量级定制摄像头
https://github.com/danielebogo/DBCamera
DBCamera is a simple custom camera with AVFoundation.
DBCamera使用了AVFoundation框架并简单的定制了摄像头.
Getting Started
Installation
The recommended approach for installating DBCamera is via the CocoaPods package manager, as it provides flexible dependency management and dead simple installation. For best results, it is recommended that you install via CocoaPods >= 0.16.0 using Git >= 1.8.0 installed via Homebrew.
推荐你使用CocoaPods安装.
Integration
DBCamera has a simple integration:
DBCamera模块化很简单:
#import "DBCameraViewController.h"
#import "DBCameraContainer.h"
//Add DBCameraViewControllerDelegate protocol
@interface RootViewController () <DBCameraViewControllerDelegate>
//Present DBCameraViewController with different behaviours - (void) openCamera
{
DBCameraContainerViewController *cameraContainer = [[DBCameraContainerViewController alloc] initWithDelegate:self];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:cameraContainer];
[nav setNavigationBarHidden:YES];
[self presentViewController:nav animated:YES completion:nil];
} - (void) openCameraWithoutSegue
{
DBCameraContainerViewController *container = [[DBCameraContainerViewController alloc] initWithDelegate:self];
DBCameraViewController *cameraController = [DBCameraViewController initWithDelegate:self];
[cameraController setUseCameraSegue:NO];
[container setCameraViewController:cameraController];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:container];
[nav setNavigationBarHidden:YES];
[self presentViewController:nav animated:YES completion:nil];
} - (void) openCameraWithoutContainer
{
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[DBCameraViewController initWithDelegate:self]];
[nav setNavigationBarHidden:YES];
[self presentViewController:nav animated:YES completion:nil];
}
//Use your captured image
#pragma mark - DBCameraViewControllerDelegate - (void) captureImageDidFinish:(UIImage *)image withMetadata:(NSDictionary *)metadata
{
[_imageView setImage:image];
[self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
}
By default, DBCameraViewController has another controller to display the image preview. When you create DBCameraViewController instance, you can set useCameraSegue:
NO, to avoid it.
默认情况下,DBCameraViewController有一个其他的controller来展示图片列表,当你创建这个DBCameraViewController实例时,你可以手动设置关闭它.
- (void) openCameraWithoutSegue
{
DBCameraContainerViewController *container = [[DBCameraContainerViewController alloc] initWithDelegate:self];
DBCameraViewController *cameraController = [DBCameraViewController initWithDelegate:self];
[cameraController setUseCameraSegue:NO];
[container setCameraViewController:cameraController];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:container];
[nav setNavigationBarHidden:YES];
[self presentViewController:nav animated:YES completion:nil];
}
Customizing the camera
Basic
For simple customizations, you can customize the built-in camera view by sending a cameraSettingsBlock to the view controller.
对于简单的定制,你可以给这个controller传递一个cameraSettingsBlock来实现内置照相机view的定制.
#import "DBCameraView.h"
- (void)openCameraWithSettings:(CDVInvokedUrlCommand*)command
{
DBCameraContainerViewController *cameraContainer = [[DBCameraContainerViewController alloc]
initWithDelegate:self
cameraSettingsBlock:^(DBCameraView *cameraView) {
[cameraView.gridButton setHidden:YES];
}]; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:cameraContainer];
[nav setNavigationBarHidden:YES];
[self presentViewController:nav animated:YES completion:nil];
}
Advanced
You can also create a custom interface, using a subclass of DBCameraView
当然,你也可以自己创建一个界面,通过继承DBCameraView子类的方式来实现.
#import "DBCameraView.h" @interface CustomCamera : DBCameraView
- (void) buildInterface;
@end
#import "CustomCamera.h" @interface CustomCamera ()
@property (nonatomic, strong) UIButton *closeButton;
@property (nonatomic, strong) CALayer *focusBox, *exposeBox;
@end @implementation CustomCamera - (void) buildInterface
{
[self addSubview:self.closeButton]; [self.previewLayer addSublayer:self.focusBox];
[self.previewLayer addSublayer:self.exposeBox]; [self createGesture];
} - (UIButton *) closeButton
{
if ( !_closeButton ) {
_closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_closeButton setBackgroundColor:[UIColor redColor]];
[_closeButton setImage:[UIImage imageNamed:@"close"] forState:UIControlStateNormal];
[_closeButton setFrame:(CGRect){ CGRectGetMidX(self.bounds) - 15, 17.5f, 30, 30 }];
[_closeButton addTarget:self action:@selector(close) forControlEvents:UIControlEventTouchUpInside];
} return _closeButton;
} - (void) close
{
if ( [self.delegate respondsToSelector:@selector(closeCamera)] )
[self.delegate closeCamera];
} #pragma mark - Focus / Expose Box - (CALayer *) focusBox
{
if ( !_focusBox ) {
_focusBox = [[CALayer alloc] init];
[_focusBox setCornerRadius:45.0f];
[_focusBox setBounds:CGRectMake(0.0f, 0.0f, 90, 90)];
[_focusBox setBorderWidth:5.f];
[_focusBox setBorderColor:[[UIColor whiteColor] CGColor]];
[_focusBox setOpacity:0];
} return _focusBox;
} - (CALayer *) exposeBox
{
if ( !_exposeBox ) {
_exposeBox = [[CALayer alloc] init];
[_exposeBox setCornerRadius:55.0f];
[_exposeBox setBounds:CGRectMake(0.0f, 0.0f, 110, 110)];
[_exposeBox setBorderWidth:5.f];
[_exposeBox setBorderColor:[[UIColor redColor] CGColor]];
[_exposeBox setOpacity:0];
} return _exposeBox;
} - (void) drawFocusBoxAtPointOfInterest:(CGPoint)point andRemove:(BOOL)remove
{
[super draw:_focusBox atPointOfInterest:point andRemove:remove];
} - (void) drawExposeBoxAtPointOfInterest:(CGPoint)point andRemove:(BOOL)remove
{
[super draw:_exposeBox atPointOfInterest:point andRemove:remove];
} @end
//Present DBCameraViewController with a custom view.
@interface RootViewController () <DBCameraViewControllerDelegate> - (void) openCustomCamera
{
CustomCamera *camera = [CustomCamera initWithFrame:[[UIScreen mainScreen] bounds]];
[camera buildInterface]; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[[DBCameraViewController alloc] initWithDelegate:self cameraView:camera]];
[nav setNavigationBarHidden:YES];
[self presentViewController:nav animated:YES completion:nil];
}
[翻译] DBCamera 轻量级定制摄像头的更多相关文章
- js 打开摄像头方法 (定制摄像头)
var video = document.getElementById("video");if (navigator.mediaDevices && navigat ...
- 安卓平台RTMP推流或轻量级RTSP服务(摄像头或同屏)编码前数据接入类型总结
很多开发者在做Android平台RTMP推流或轻量级RTSP服务(摄像头或同屏)时,总感觉接口不够用,以大牛直播SDK为例 (Github) 我们来总结下,我们常规需要支持的编码前音视频数据有哪些类型 ...
- Android同屏、摄像头RTMP推送常用的数据接口设计探讨
前言 好多开发者在调用Android平台RTMP推送或轻量级RTSP服务接口时,采集到的video数据类型多样化,如420sp.I420.yv12.nv21.rgb的,还有的拿到的图像是倒置的,如果开 ...
- 小白学Python——用 百度翻译API 实现 翻译功能
本人英语不好,很多词组不认识,只能借助工具:百度翻译和谷歌翻译都不错,近期自学Python,就想能否自己设计一个百度翻译软件呢? 百度翻译开放平台: http://api.fanyi.baidu.co ...
- Android平台摄像头/屏幕/外部数据采集及RTMP推送接口设计描述
好多开发者提到,为什么大牛直播SDK的Android平台RTMP推送接口怎么这么多?不像一些开源或者商业RTMP推送一样,就几个接口,简单明了. 不解释,以Android平台RTMP推送模块常用接口, ...
- 2018 AI产业界大盘点
2018 AI产业界大盘点 大事件盘点 “ 1.24——Facebook人工智能部门负责人Yann LeCun宣布卸任 Facebook人工智能研究部门(FAIR)的负责人Yann LeCun宣布卸 ...
- 《iPhone高级编程—使用Mono Touch和.NET/C#》
第1章 C#开发人员基于MonoTouch进行iPhone开发概述 1 1.1 产品对比 2 1.1.1 .NET Framework 2 1.1.2 Mono 2 1.1.3 MonoTouch 3 ...
- Bootstrap 简洁、直观、强悍、移动设备优先的前端开发框架,让web开发更迅速、简单。
http://v3.bootcss.com/ 从2.x升级到3.0版本 Bootstrap 3并不向后兼容Bootstrap v2.x.下面章节列出的内容可以作为从v2.x升级到v3.0的通用指南.如 ...
- phonegap的照相机API
1. Camera Api简单介绍 2. 拍照 3. 预览照片 一. Camera Api简单介绍 Camera选择使用摄像头拍照,或从设备相册中获取一张照片.图片以base64编码的 字符串或图片U ...
随机推荐
- after_create and after_commit
A relational database, like mysql, provides transactions to wrap several operations in one unit, mak ...
- python线程入门
目录 python线程入门 线程与进程 线程 总结 参考 python线程入门 正常情况下,我们在启动一个程序的时候.这个程序会先启动一个进程,启动之后这个进程会启动起来一个线程.这个线程再去处理事务 ...
- 前端项目中使用git来做分支和合并分支,管理生产版本
最近由于公司前端团队扩招,虽然小小的三四团队开发,但是也出现了好多问题.最让人揪心的是代码的管理问题:公司最近把版本控制工具从svn升级为git.前端H5组目前对git的使用还不是很熟悉,出现额多次覆 ...
- C# list的合并
转自:https://www.cnblogs.com/liguanghui/archive/2011/11/09/2242309.html List<int> listA = new Li ...
- Linux下的mysql默认大小写敏感
在Linux下: 1.数据库名与表名是严格区分大小写的: 2.表的别名是严格区分大小写的: 3.列名与列的别名在所有的情况下均是忽略大小写的: 4.变量名也是严格区分大小写的: 在Windows下: ...
- OracleServer总结进阶之系统分析(进阶完结)
个人原创,转载请在文章头部明显位置注明出处:https://www.cnblogs.com/sunshine5683/p/10080102.html 在上一篇进阶中大概讲解了一些关于进阶方面的知识,今 ...
- GitHub fork的使用
我的GitHub账号是lanshanxiao,fork的账号是king1ko1king,再此说明! fork的项目是:Class-for-Everyone-Java-Server- 作者源项目地址是: ...
- Nginx 反向代理时获取用户的真实 IP
在平时我们开发后端程序的过程中,应该多多少少都会碰到记录客户端 IP 的场景,例如我之前写过的 APP 用户的一个审计功能,就需要获取用户的 IP 地址:还有广告系统里面,也是需要获取用户的 IP 地 ...
- Go 中包导入声明
Go中的程序由软件包组成.通常,软件包依赖于其他软件包,或者内置于标准库或第三方的软件包.包需要先导入才能使用其导出的标识符.本文将翻译一篇国外的文章,用于介绍包导入的原理以及几种常用的导入方式. & ...
- wamp 安装monggo扩展
1.下载对应的monggo扩展 http://pecl.php.net/package/mongo 2. 找对应的版本 放在D:\program\wamp\bin\php\php5.5.12\ext ...