标签:
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:
pod ‘LLSimpleCamera‘, ‘~> 1.1‘
CGRect screenRect = [[UIScreen mainScreen] bounds];
// create camera vc
self.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 app
self.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://www.cnblogs.com/YouXianMing/p/4205241.html