键盘和UILalertView动画冲突

打开键盘时,点击某个按钮,弹出alertView并进行操作进入另外页面,键盘不能及时收起来,会在下个页面闪一下才收起来。

解决方法分为两种
①用UIAlertController,适用于ios8以后
②若还是想用UIAlertView,那么可以用如下方法

alertview show的时候写个主线程延迟,pop也延迟

UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"感谢!" delegate:self cancelButtonTitle:@"好的" otherButtonTitles:nil, nil];
[alert show];

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex==0) {
        [self backForward];
    }
}

方案一
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"感谢你对我们提出的意见或建议,你的支持就是我们进步的动力!" delegate:self cancelButtonTitle:@"我知道了" otherButtonTitles:nil, nil];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    [alert show];
});
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex==0) {
        [self performSelector:@selector(backForward) withObject:nil afterDelay:0.25f];
    }
}

方案二
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提醒设置项有修改,是否保存"   message:@"" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [self.navigationController popViewControllerAnimated:YES];
        }];
        UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"保存" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [self uploadDataAndPushView:NO];
        }];
        [alertController addAction:cancelAction];
        [alertController addAction:okAction];
        [self presentViewController:alertController animated:YES completion:nil];
        

你可能感兴趣的:(键盘和UILalertView动画冲突)