通过键盘显示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];

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...