LLSimpleCamera 是一个用于创建类似于 snapchat 的定制相机 - 视频录制界面的库。您无需在新视图控制器中展示相机。
您还可以使用我的 LLVideoEditor 库轻松编辑记录的视频。
新功能
合并了一些 PR
感谢开源社区,最近我合并了约 10 个 PR,使这个库变得更加出色和可靠。我还进行了一些清理,其中包含一些有破坏性的更改(为此感到抱歉)。因此,我将主版本递增。
pod 'LLSimpleCamera', '~> 4.1'
初始化 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] initWithVideoEnabled:YES];
// camera with precise quality, position and video parameters.
self.camera = [[LLSimpleCamera alloc] initWithQuality:AVCaptureSessionPresetHigh
position:LLCameraPositionRear
videoEnabled:YES];
// attach to the view
[self.camera attachToViewController:self withFrame:CGRectMake(0, 0, screenRect.size.width, screenRect.size.height)];
捕获照片
// 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];
}
}];
开始录制视频
// start recording
NSURL *outputURL = [[[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"test1"] URLByAppendingPathExtension:@"mov"];
[self.camera startRecordingWithOutputUrl:outputURL didRecord:^(LLSimpleCamera *camera, NSURL *outputFileUrl, NSError *error) {
VideoViewController *vc = [[VideoViewController alloc] initWithVideoUrl:outputFileUrl];
[self.navigationController pushViewController:vc animated:YES];
}];
停止录制视频
[self.camera stopRecording];
更改焦点层和动画
- (void)alterFocusBox:(CALayer *)layer animation:(CAAnimation *)animation;
您必须添加自己的相机控件(闪光灯、相机切换等)。只需将控件添加到LLSimpleCamera所依附的视图中。您可以在示例项目中看到一个完整的相机示例。下载并在您的设备上尝试。
在捕获块被触发后,或者在某些地方的父控制器中的 viewWillDisappear 内,您决不应忘记停止相机,以确保在不需要时应用不会使用相机。您可以通过调用 -start() 来重用相机。因此,将 -start() 放置在 -viewWillAppear 或其他相关方法中可能是个好主意。
Ömer Faruk Gül
对内部结构和 API 做了重大的改变。