我有一个UIAlertController从一个UIViewController弹出,这个UIViewController在UINavigationController中作为最后一个UIViewController被推入。这个UIAlertViewController里面有一个UITextField。
我的问题是当我选择UITextField时,键盘会弹出,但是UIAlertViewController仍然居中,并且部分被键盘遮挡。
我的代码如下:
我的问题是当我选择UITextField时,键盘会弹出,但是UIAlertViewController仍然居中,并且部分被键盘遮挡。
我的代码如下:
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];
UAlertController
时隐藏键盘。或者使用自定义的alertcontroller
。 - jhd