UIImagePickerController 相机在翻转和取消几次时冻结

Posted

技术标签:

【中文标题】UIImagePickerController 相机在翻转和取消几次时冻结【英文标题】:UIImagePickerController camera freezes when flip and cancel a few times 【发布时间】:2014-04-09 23:01:26 【问题描述】:

您好,我正在使用带有相机的应用程序。

我可以正确打开和使用相机。但我发现了一个错误:

当我打开相机时,翻转相机,再次翻转相机并按取消。做几次(3-5 次)。再次打开相机,我有几秒钟的黑色冻结屏幕,如果您拍照,请查看图像,但屏幕继续为黑色。几秒钟后,相机再次出现,您可以继续正常行为。但我找不到解决方案。

我在互联网上搜索了很多并找到了一些答案,但没有解决我的问题。

这里有一个类似的问题,但解决方案对我不起作用:

*** - UIImagePickerController Freezes when camera flips *** - UIImagePicker freezes *** - ios 7 UIImagePicker preview black screen *** - iDevice camera shows black instead of preview

我还使用 DejalBezelActivityView 创建带有标签DejalBezelActivityView 的微调器区域

有什么想法吗?

我有我的 .h 声明:

@property (nonatomic, strong) UIImagePickerController* picker;

- (void) takePhoto: (id)vc;
- (void) selectPhoto: (id)vc;

还有我的 .mm 代码:​​

@synthesize picker = _picker;

- (id) init
self = [super init];

if (self)
    self.picker = [[UIImagePickerController alloc] init];


return self;




- (void)takePhoto:(id)vc
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    [VC_Camera showAlert];
    return;


[self init];
self.picker.delegate = self;
self.picker.allowsEditing = YES;
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;

[[VC_Camera getMainWindow] presentViewController:self.picker animated:YES completion:NULL];


- (void)selectPhoto:(id)vc
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
    [VC_Camera showAlert];
    return;


[self init];    
self.picker.delegate = self;
self.picker.allowsEditing = YES;
self.picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

[[VC_Camera getMainWindow] presentViewController:self.picker animated:YES completion:NULL];


- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker 

self.picker = picker;

DejalActivityView * _activityView = [DejalBezelActivityView activityViewForView:[[UIApplication sharedApplication] keyWindow]  withLabel:@"Loading"];

  [self performSelector:@selector(cancelAfterDelay:) withObject:@@"DejalAV":_activityView afterDelay:1.0];




- (void) cancelAfterDelay:(NSDictionary*) dict


DejalActivityView* _activityView = [dict objectForKey:@"DejalAV"];

[DejalBezelActivityView removeViewAnimated:YES];

[self.picker dismissViewControllerAnimated:YES completion:nil];

谢谢:D

[更新]

我尝试将 UIImagePickerController 用作单例:

-(UIImagePickerController *) imagePicker
if(!_imagePicker)
   _imagePicker = [[UIImagePickerController alloc] init];
   _imagePicker.delegate = self;
   if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
       _imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
   
   else
       _imagePicker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
     

return _imagePicker;

问题仍然存在。

【问题讨论】:

【参考方案1】:

这是一个很晚的回应,但对于那些仍在与这个问题搏斗的人:我注意到这似乎发生在某些事情正在备份主线程或影响单独线程上的图形上下文时。这些可能是开始寻找的地方。

【讨论】:

以上是关于UIImagePickerController 相机在翻转和取消几次时冻结的主要内容,如果未能解决你的问题,请参考以下文章

在iPad iOS8环境下打开相冊或者拍照

SVG 覆盖在 UIImagePickerController 之上,UIImagePickerController 响应手势(iPhone/iOS)

UIImagePickerController 不是全屏

UIImagePickerController、自定义 UIButton 和 AutoLayout

UIImagePickerController 实况照片

OCMock 模拟 UIImagePickerController