[翻译] LLSimpleCamera

时间:2022-07-20 15:23:27

LLSimpleCamera

[翻译] LLSimpleCamera

https://github.com/omergul123/LLSimpleCamera

[翻译] LLSimpleCamera

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

You can also use my LLVideoEditor library to easily edit recorded videos.

LLSimpleCamera是一个用以构造自定义照相机 - 视频录制界面的库,类似于snapchat.你不需要将当前控制器在一个新的控制器中推出来.

LLSimpleCamera:

  • lets you easily capture photos and record videos (finally) 让你非常简易的照相以及录制视频
  • handles the position and flash of the camera 控制照相位置或者是闪光灯
  • hides the nitty gritty details from the developer 隐藏令人恶心的实现细节
  • doesn't have to be presented in a new modal view controller, simply can be embedded inside any of your VCs. (like Snapchat) 不需要创建一个新的控制器,你可以在你的任何VC中进行显示

Install

pod 'LLSimpleCamera', '~> 3.0'

Example usage

Initialize the LLSimpleCamera

初始化LLSimpleCamera

CGRect screenRect = [[UIScreen mainScreen] bounds];

// create camera with standard settings
self.camera = [[LLSimpleCamera alloc] init]; // camera with video recording capability
self.camera = [[LLSimpleCamera alloc] nitWithVideoEnabled:YES]; // camera with precise quality, position and video parameters.
self.camera = [[LLSimpleCamera alloc] initWithQuality:AVCaptureSessionPresetHigh
position:CameraPositionBack
videoEnabled:YES];
// attach to the view
[self.camera attachToViewController:self withFrame:CGRectMake(0, 0, screenRect.size.width, screenRect.size.height)];

To capture a photo:

照相:

// capture
[self.camera capture:^(LLSimpleCamera *camera, UIImage *image, NSDictionary *metadata, NSError *error) {
if(!error) {
// we should stop the camera, since we don't need it anymore. We will open a new vc.
// this very important, otherwise you may experience memory crashes
[camera stop]; // show the image
ImageViewController *imageVC = [[ImageViewController alloc] initWithImage:image];
[self presentViewController:imageVC animated:NO completion:nil];
}
}];

To start recording a video:

开始录像:

// start recording
NSURL *outputURL = [[[self applicationDocumentsDirectory]
URLByAppendingPathComponent:@"test1"] URLByAppendingPathExtension:@"mov"];
[self.camera startRecordingWithOutputUrl:outputURL];

To stop recording the video:

[self.camera stopRecording:^(LLSimpleCamera *camera, NSURL *outputFileUrl, NSError *error) {
VideoViewController *vc = [[VideoViewController alloc] initWithVideoUrl:outputFileUrl];
[self.navigationController pushViewController:vc animated:YES];
}];

Changing the focus layer and animation:

- (void)alterFocusBox:(CALayer *)layer animation:(CAAnimation *)animation;

Adding the camera controls

添加摄像头控制细节

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

你需要根据需求添加你想用的控制细节(闪光灯,照相机或者其他的东西).只需要将要添加的东西添加到LLSimpleCamera附着的view上.你可以在项目源码中看到一个完整的实例.

Stopping and restarting the camera

You should never forget to stop the camera either after the capture block is triggered, or inside somewhere -viewWillDisappear of the parent controller to make sure that the app doesn't use the camera when it is not needed. You can call -start() to reuse the camera. So it may be good idea to to place -start() inside -viewWillAppear or in another relevant method.

你要确保不要忘记在用完了摄像头后关闭相关的操作句柄.