UIImagePickerController在相机翻转时冻结

时间:2012-11-03 18:27:05

标签: objective-c ios xcode uiimagepickercontroller freeze

当按下从前向后翻转相机的按钮时,我的UIImagePickerController冻结并关闭相机。这是我从方法初始化项目中的图像选择器控制器对象(其余代码被省略)的方式,因为它与UIimagepickercontroller对象无关。

//In my .h file 
UIImagePickerController * imgPicker;

//in my .m file
-(void)viewDidLoad {

imgPicker = [[UIImagePickerController alloc] init];
imgPicker.delegate = self;
imgPicker.allowsEditing = YES;

}

-(void) takePicture {

imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:imgPicker animated:YES completion:NULL];

}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{

masterImage.image = [info objectForKey:UIImagePickerControllerEditedImage];

if(masterImage.image == nil) {

    masterImage.image = [info objectForKey:UIImagePickerControllerEditedImage];

}

[self dismissModalViewControllerAnimated:YES];

}

-(void) imagePickerControllerDidCancel:(UIImagePickerController *)picker{

[self dismissModalViewControllerAnimated:YES];

}

-(void) releaseOutlets {

[imgPicker release];

}

2 个答案:

答案 0 :(得分:1)

仅限于规则,请更改您的代码。而不是:

UIImagePickerController * imgPicker;

写入您的.h文件:

@property (nonatomic, strong) UIImagePickerController * imgPicker;

而不是在.m文件中合成它:

imgPicker = _imgPicker;

然后每次调用此属性都会调用self。

答案 1 :(得分:-2)

  • 首先,你不应该在viewdidload方法中分配init。在-init方法中进行所有分配。
  • 按照edzio27的建议添加属性。
  • 再次测试

如果问题仍然存在: - 检查你是否"接收内存警告"。在内存警告的情况下,再次调用viewdidload方法。如果你在那个方法中保留你的分配init,你将每次都创建新的实例。

我们遇到了与MPMoviePlayerController类似的问题。不确定你是否有同样的问题。