在iOS 8及更低版本中,当显示键盘时显示UIActionSheet将通过键盘显示动作片.使用iOS 9,情况就不一样了.
在我的应用程序中,我们有一个聊天功能,并希望通过键盘显示一个动作.我们曾经使用UIActionSheet,直到iOS 8才能正常工作.在iOS 9中,操作列表位于键盘后面.我试过UIActionSheet和UIAlertController.
我已经尝试将操作表放在自己的窗口中,并覆盖刚刚使键盘消失的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];
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。