Почему интерфейс моей камеры ведет себя странно, когда я использую 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];

        }

    }

}

Проблема в том, что если пользователь хочет сделать новый снимок, всплывает интерфейс камеры, а затем, если вы поворачиваете устройство, интерфейс выглядит следующим образом: enter image description here

​​А затем, когда пользователь поворачивает ее обратно, это внезапно выглядит так: enter image description here

Небольшая побочная проблема в том, что камера долго загружается.

Любые мысли приветствуются :)

7
задан Oliver 20 October 2011 в 12:58
поделиться