你好,我在一个有摄像头的应用程序工作。
我可以正确地打开和使用相机。但我发现一只虫子:
当我打开相机,翻转相机,再次翻转相机,然后按取消键。做几次(3-5次)。再次打开相机,我有一个黑色冻结屏幕几秒钟,如果你拍一张照片,看到图像,但屏幕继续黑色。几秒钟后,相机再次出现,您可以继续正常的行为。但我找不到解决办法。
我在网上搜索了很多,找到了一些答案,但没有解决我的问题。
这里有一个类似的问题,但这个解决方案对我没有用:
此外,我还使用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;
}问题依然存在。
发布于 2014-05-21 00:36:24
这是一个非常晚的响应,但对于那些仍然在努力解决这个问题的人:我注意到,当某个东西备份主线程或影响单独线程上的图形上下文时,似乎会发生这种情况。那里可能是开始寻找的地方。
https://stackoverflow.com/questions/22975555
复制相似问题