En mi aplicación, quiero que el usuario pueda tomar una foto o usar una de la biblioteca de fotos. Cuando el usuario hace clic en el botón que hice que aparezca una alerta, el usuario puede elegir entre tomar una foto nueva o una de la biblioteca de fotos. Aquí está el código que he utilizado:¿Por qué la interfaz de mi cámara actúa de manera extraña cuando uso UIImagePickerController?
- (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];
}
}
}
El problema es que si el usuario quiere hacer una nueva foto de la interfaz de la cámara aparece, y luego, si se gira el dispositivo de la interfaz se parece a esto:
Y luego, cuando el usuario gira de nuevo, de repente se ve así:
un pequeño problema adicional es que la cámara tarda mucho tiempo en cargar.
Cualquier idea sería apreciada :)
tengo exactamente este problema. – nicholjs