您的位置:首页 > 产品设计 > UI/UE

bug日志(1):UIAlertView消失之后收起的键盘又弹出

2016-04-28 16:21 344 查看

iOS8之后,有了UIAlertController这个类,如下

NS_CLASS_AVAILABLE_IOS(8_0) @interface UIAlertController : UIViewController

很明显,苹果强烈建议广大码农们如果能不用UIAlertView就不要用啦,因为我们有UIAlertController了!

进入正题......

为了兼容iOS7,我们的项目中就统一使用了UIAlertView。问题来了:(项目中的某一)界面中textField处于编辑状态(界面上有键盘),点击界面中一个执行确定操作的按钮时,我先将键盘收起,键盘收起的执行代码是这样的

[self.view endEditing:YES];

随即又执行了弹出一个UIAlertView的代码,点击UIAlertView上的确定按钮之后其被dismiss掉了。这时,键盘又神奇般的弹了出来!!!

看了一下真机系统版本号:9.2.1。随后又用另外一个真机(系统版本8.1.2)进行测试时,这个问题却没有出现。

于是百度了一下,经验证,以下代码可以解决我遇到的这个问题

if (IOS_SystemVersion >= 8.0)  {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"title" message:@"message" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

}];
[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];
}
else  {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"title" message:@"message" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
[alert show];
}

有位大侠是这样说的: 在iOS 8.3以后,dismiss alert view时系统会尝试恢复之前的keyboard input。可有一点我不明白的是,我明明执行了收起键盘的代码啊!!! 苹果,你告诉我,这算不算是一个系统级的bug...... 

接昨天的写。在百度的时候,还有一位朋友问了这么一个问题:A界面有个textview,在编辑状态(有键盘)的时候我点击按钮,按钮的处理有结束所有控件编辑(关闭键盘)的操作,然后再弹出alertview,点击alerview对话框后pop到B界面,现在发现pop到B界面后界面会出现弹出键盘再消失的情况,如果我去掉弹出alertview这个操作,点击按钮后直接pop则不会出现这个问题.

这个,本人亲自试验了一下,发现这个现象也是高版本系统在处理UIAlertView时所表现出来的现象。

有大侠说用NSTimer,0.25秒(键盘收起的动画时间)后,再去pop,像下面这样

self.myTimer = [NSTimer scheduledTimerWithTimeInterval:0.25 target:self selector:@selector(popToPreviousViewController) userInfo:nil repeats:NO];

也有建议这样

[self performSelector:@selector(popVC) withObject:nil afterDelay:0.25];

都能解决问题。

但我的建议是这样的

if (IOS_SystemVersion >= 8.0)  {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"alert" message:@"l am alert" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action = [UIAlertAction actionWithTitle:@"l know" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[self.navigationController popViewControllerAnimated:YES];
}];
[alertController addAction:action];
[self presentViewController:alertController animated:YES completion:nil];
}
else {
[self.navigationController popViewControllerAnimated:YES];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"alertView" message:@"l am alertView" delegate:nil cancelButtonTitle:@"pop" otherButtonTitles:nil];
[alertView show];
}

好了,就写到这里吧!

从这一篇开始,我将整个iOS开发bug报告系列,欢迎大家关注!

本文参考:http://www.cnblogs.com/android-wuwei/p/4685960.html

              http://blog.csdn.net/ul123dr/article/details/50385929

              http://www.cocoachina.com/bbs/read.php?tid=307336&page=e&#a

 

转载于:https://www.cnblogs.com/zhangguangkai/p/5443113.html

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: