UIImagePickerController appears but camera doesn&#

2019-04-11 03:12发布

I have an app where I present a UIImagePickerController with source type UIImagePickerControllerSourceTypeCamera. Everything works fine unless I leave the app and come back (multitasking is enabled so the app comes back right where it left off) and I present the UIImagePickerController again. It appears on screen but the camera never shows, the animation where the camera is revealed never happens, here is a screenshot: screenshot

If I press cancel and present the UIImagePickerController again, the camera will show up fine. So the only time this problem occurs is the first time I present the UIImagePickerController after coming back to the app. Anyone know why this is happening? I'm coding for iOS 5

I'm presenting the UIImagePickerController with:

[self presentViewController:capturePhotoPicker animated:YES completion:nil];

and dismissing it with:

[self dismissViewControllerAnimated:YES completion:nil];

I am using the same UIImagePickerController object each time I present it

2条回答
成全新的幸福
2楼-- · 2019-04-11 03:38

I had exactly the same problem and then realized I wasn't releasing the UIImagePickerController after presenting it. The camera now works fine first-time after leaving and returning to the app.

So this is my exact code:

UIImagePickerController *takePhotoController = [[UIImagePickerController alloc] init];
takePhotoController.sourceType = UIImagePickerControllerSourceTypeCamera;
takePhotoController.delegate = self;

[self presentModalViewController:takePhotoController animated:YES];
[takePhotoController release];

It's one of those problems you can spend ages on, and the solution is not that obvious (well, it wasn't to me), so I hope this helps some people!

查看更多
男人必须洒脱
3楼-- · 2019-04-11 03:47

if you change the -(void)viewDidLoad to - (void)viewDidAppear:(BOOL)animated it fixes the problem. I've spent the last 2 weeks trying to figure this out

查看更多
登录 后发表回答