Objective c UIImagePickerController相机在翻转和取消几次后会冻结
你好,我在一个带摄像头的应用程序中工作 我能正确地打开和使用相机。但我发现了一个bug: 当我打开相机时,翻转相机,再次翻转相机并按取消。做几次3-5。再次打开相机,我有一个黑色的冻结屏幕几秒钟,如果你拍照,看到的图像,但屏幕继续在黑色。几秒钟后,相机再次出现,您可以继续正常操作。但我找不到解决办法 我在网上搜索了很多,找到了一些答案,但没有任何东西能解决我的问题 这里有一个类似的问题,但解决方案对我不起作用: 我还使用DejalBezelActivityView创建带有标签的微调器区域 有什么想法吗 我有我的.h声明:Objective c UIImagePickerController相机在翻转和取消几次后会冻结,objective-c,ios7,camera,uiimagepickercontroller,Objective C,Ios7,Camera,Uiimagepickercontroller,你好,我在一个带摄像头的应用程序中工作 我能正确地打开和使用相机。但我发现了一个bug: 当我打开相机时,翻转相机,再次翻转相机并按取消。做几次3-5。再次打开相机,我有一个黑色的冻结屏幕几秒钟,如果你拍照,看到的图像,但屏幕继续在黑色。几秒钟后,相机再次出现,您可以继续正常操作。但我找不到解决办法 我在网上搜索了很多,找到了一些答案,但没有任何东西能解决我的问题 这里有一个类似的问题,但解决方案对我不起作用: 我还使用DejalBezelActivityView创建带有标签的微调器区域 有什么
@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;
}
问题依然存在 这是一个非常晚的回答,但对于那些仍在努力解决这个问题的人来说:我注意到,当某个东西正在备份主线程,或者在单独的线程上影响图形上下文时,似乎会发生这种情况。这些可能是开始寻找的地方