更快地准备iOS相机

时间:2014-05-16 22:24:04

标签: ios objective-c uiimagepickercontroller

有没有办法在呈现UIImagePickerController时更快地准备相机?

这个问题解决了确实存在延迟,以及在相机准备就绪时接收回叫的方法How to know if iPhone camera is ready to take picture?

我知道这一定是可能的(Snapchat,Instagram等)在拍照方面都有相当无缝的用户界面。

我目前只是像这样展示我的imagepicker:

    _imagePicker = [[UIImagePickerController alloc] init];
    _imagePicker.delegate = self;
    _imagePicker.allowsEditing = YES;
    _imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
    _imagePicker.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;
    [self presentViewController:_imagePicker animated:NO completion:NULL];

2 个答案:

答案 0 :(得分:1)

我认为不可能,除非您开始使用AVFoundation构建自己的照片选择器并从那里捕捉电影和照片。从头开始构建一个好的照片选择器具有相同的功能是相当昂贵的任务。有一些例子,苹果AVCam可能是最完整的。您可以将它用作基准测试,并了解如何比uiimagepickercontroller更快

答案 1 :(得分:0)

尝试在用户尝试拍照前设置相机。正如我之前提到的,这并不是真的更快,但对用户来说却是如此。

此代码将异步设置摄像机:

__block声明中的UIImagePickerController之前添加_imagePicker

NSOperationQueue *cameraSetupQueue = [[NSOperationQueue alloc] init];
cameraSetupQueue.name = @"camera setup";

[cameraSetupQueue addOperationWithBlock:^(void){

    _imagePicker = [[UIImagePickerController alloc] init];
    _imagePicker.delegate = self;
    _imagePicker.allowsEditing = YES;
    _imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
    _imagePicker.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;
}];

将此代码放在某处,以便在需要使用相机之前执行。