iOS - UIAlertController hidden under keyboard

Viewed 2172

I have an UIAlertController presented from a UIViewController which is pushed in the UINavigationController as the last UIViewController. This UIAlertViewController has a UITextField in it.

My problem is that when I select the UITextField the keyboard shows up, but the UIAlertViewController stays centered, and partly hidden under the keyboard.

My code looks like this:

UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Enter Your PIN" message:@"Please enter your PIN!" preferredStyle:UIAlertControllerStyleAlert];

[alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
        [textField setSecureTextEntry:YES];
    }];

UIAlertAction* okAction = [UIAlertAction actionWithTitle:@"Confirm"
                                                       style:UIAlertActionStyleDefault
                                                     handler:^(UIAlertAction * _Nonnull action) {  }];


UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
                                                           style:UIAlertActionStyleCancel
                                                         handler:^(UIAlertAction * _Nonnull action) {
                                                         }];
[alert addAction:okAction];
[alert addAction:cancelAction];
[self presentViewController:alert animated:YES completion:nil];

ScrenshotHidden UIAllertController

6 Answers
Related