UIImagePickerController Freezes when camera flips

冷暖自知 提交于 2020-01-06 18:08:44

问题


My UIImagePickerController freezes and the camera closes when the button to flip the camera from front to back is pressed. This is how I initialize the image picker controller object within the project (the rest of the code was ommitted) from the methods as it is irrelevant to the UIimagepickercontroller object.

//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];

}

回答1:


Just for rule, change your code. Instead of:

UIImagePickerController * imgPicker;

Write in your .h file:

@property (nonatomic, strong) UIImagePickerController * imgPicker;

than synthesize it in your .m file:

imgPicker = _imgPicker;

and next every call to this property call with self.




回答2:


  • first of all, you should not alloc init in viewdidload method. Do all ur allocations in -init method.
  • add property as suggested by edzio27.
  • test again

if problem persists: - check if u are "receiving memory warning". In case of memory warning ur viewdidload method is called again. In case u keep ur alloc init in that method u will be creating new instance everytime.

We faced a similar issue with MPMoviePlayerController. not sure if u have the same issue.



来源:https://stackoverflow.com/questions/13212168/uiimagepickercontroller-freezes-when-camera-flips

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!