In my application, I want the user to be able to take a picture or use it in a photo library. When the user clicks on the button, I made a warning pop-up window, and you can choose between recording a new photo or a photo from the photo library. Here is the code I used:
- (void)PictureAlert:(id)sender { UIAlertView *AlertDialog; // Setting up AlertDialog. AlertDialog = [[UIAlertView alloc] initWithTitle:nil message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Choose From Library", @"Take New Picture", nil]; [AlertDialog show]; } - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { NSString *ButtonTitle = [alertView buttonTitleAtIndex:buttonIndex]; if ([ButtonTitle isEqualToString:@"Choose From Library"]) { if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) { // Pick photo. UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.delegate = self; picker.allowsEditing = YES; picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; [self presentModalViewController:picker animated:YES]; } else if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) { // Setting up AlertDialog. UIAlertView *AlertDialog; AlertDialog = [[UIAlertView alloc] initWithTitle:@"Error accessing photo library" message:@"Device does not support a photo library" delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil]; [AlertDialog show]; } } else if ([ButtonTitle isEqualToString:@"Take New Picture"]) { if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { // Take new photo. UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.delegate = self; picker.allowsEditing = YES; picker.wantsFullScreenLayout = YES; picker.sourceType = UIImagePickerControllerSourceTypeCamera; [self presentModalViewController:picker animated:YES]; } else if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { // Setting up AlertDialog. UIAlertView *AlertDialog; AlertDialog = [[UIAlertView alloc] initWithTitle:@"Error accessing camera" message:@"Device does not support a camera" delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil]; [AlertDialog show]; } } }
The problem is that if the user wants to take a new image, a camera window will appear, and then if you turn the device, the interface looks like this: 
And then when the user rotates it back, it suddenly looks like this: 
The little problem is that the camera takes a long time to load.
Any thoughts would be appreciated :)
Niklas Jensen
source share