Ios UIImagePickerController在有活动AVSession时变慢
我有一个Ios UIImagePickerController在有活动AVSession时变慢,ios,cocoa-touch,uiimagepickercontroller,avcapturesession,Ios,Cocoa Touch,Uiimagepickercontroller,Avcapturesession,我有一个UIImagePickerController,可用于在我的社交网络应用程序中上载个人资料图像 单独使用时工作正常,即没有其他摄像头干扰 在另一个视图中,我使用AVCaptureSession和AVCaptureVideoPreviewLayer将相机视图嵌入视图中。在这里,用户可以上传他们拍摄的各种照片 单独使用时,也可以正常工作,即没有其他摄像头干扰 (这是一个选项卡栏应用程序) 无论何时AVCapturePreviewLayer处于活动状态,并且我使用UIImagePickerCo
UIImagePickerController
,可用于在我的社交网络应用程序中上载个人资料图像
单独使用时工作正常,即没有其他摄像头干扰
在另一个视图中,我使用AVCaptureSession
和AVCaptureVideoPreviewLayer
将相机视图嵌入视图中。在这里,用户可以上传他们拍摄的各种照片
单独使用时,也可以正常工作,即没有其他摄像头干扰
(这是一个选项卡栏应用程序)
无论何时AVCapturePreviewLayer
处于活动状态,并且我使用UIImagePickerController
进入视图,imagePicker都需要很长时间才能加载,有时甚至会冻结
这就是我初始化AVSession/AVCapturePreviewLayer的方法:
self.session = [[AVCaptureSession alloc] init];
self.session.sessionPreset = AVCaptureSessionPreset640x480;
self.captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.session];
self.captureVideoPreviewLayer.frame = self.cameraView.bounds;
[self.captureVideoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
[self.cameraView.layer addSublayer:self.captureVideoPreviewLayer];
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error = nil;
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
if (!input) {
// Handle the error appropriately.
NSLog(@"ERROR: trying to open camera: %@", error);
}else
[self.session addInput:input];
self.stillImageOutput = [[AVCaptureStillImageOutput alloc] init];
NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys: AVVideoCodecJPEG, AVVideoCodecKey, nil];
[self.stillImageOutput setOutputSettings:outputSettings];
[self.session addOutput:self.stillImageOutput];
self.picker = [[UIImagePickerController alloc] init];
self.picker.delegate = self;
self.picker.allowsEditing = YES;
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:self.picker animated:YES completion:NULL];
以下是初始化UIImagePickerController的方法:
self.session = [[AVCaptureSession alloc] init];
self.session.sessionPreset = AVCaptureSessionPreset640x480;
self.captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.session];
self.captureVideoPreviewLayer.frame = self.cameraView.bounds;
[self.captureVideoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
[self.cameraView.layer addSublayer:self.captureVideoPreviewLayer];
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error = nil;
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
if (!input) {
// Handle the error appropriately.
NSLog(@"ERROR: trying to open camera: %@", error);
}else
[self.session addInput:input];
self.stillImageOutput = [[AVCaptureStillImageOutput alloc] init];
NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys: AVVideoCodecJPEG, AVVideoCodecKey, nil];
[self.stillImageOutput setOutputSettings:outputSettings];
[self.session addOutput:self.stillImageOutput];
self.picker = [[UIImagePickerController alloc] init];
self.picker.delegate = self;
self.picker.allowsEditing = YES;
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:self.picker animated:YES completion:NULL];
- 为什么当previewLayer在另一个视图中处于活动状态时,
要花很长时间才能加载UIImagePickerController
- 如何缩短
的加载时间UIImagePickerController
- 好的。好像在叫:
[AVSession stopRunning];
在<代码>视图中消失:(BOOL)动画
为我解决了这个问题