通过键盘显示UIAlertController

在iOS 8及更低版本中,当显示键盘显示UIActionSheet将通过键盘显示动作片.使用iOS 9,情况就不一样了.

在我的应用程序中,我们有一个聊天功能,并希望通过键盘显示一个动作.我们曾经使用UIActionSheet,直到iOS 8才能正常工作.在iOS 9中,操作列表位于键盘后面.我试过UIActionSheet和U​​IAlertController.

我们想要的是一个action.app中的动作页

我已经尝试将操作表放在自己的窗口中,并覆盖刚刚使键盘消失的canBecomeFirstResponder.

解决方法

我已经在我们的应用程序中实现了这一点.诀窍是让警报控制器出现在不同的窗口上.这是UIActionSheet实现的方式,在iOS 8上也是非常棒的,但是在9,Apple已将键盘实现移到了一个非常高的窗口级(10000000)的窗口中.修复是使您的警报窗口具有更高的窗口级别(作为自定义double值,不使用提供的常量).

当使用具有透明度的自定义窗口时,请确保读取my answer here,关于背景颜色,以防止窗口在旋转过渡期间变黑.

_alertwindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
_alertwindow.rootViewController = [UIViewController new];
_alertwindow.windowLevel = 10000001;
_alertwindow.hidden = NO;
_alertwindow.tintColor = [[UIWindow valueForKey:@"keyWindow"] tintColor];

__weak __typeof(self) weakSelf = self;

UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Test" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
[alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    weakSelf.alertwindow.hidden = YES;
    weakSelf.alertwindow = nil;
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"Test" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    weakSelf.alertwindow.hidden = YES;
    weakSelf.alertwindow = nil;
}]];

[_alertwindow.rootViewController presentViewController:alert animated:YES completion:nil];

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...