我使用UIAlertController
创建了一个注册表单,并使用addTextFieldWithConfigurationHandler
方法添加了一个文本框。但是出现了一个小问题。
当表单出现时,键盘和模态视图以平滑的动画显示。在关闭表单时,模态视图先消失,然后键盘才消失。这使得键盘出现了突然向下的落差。
我如何让模态视图和键盘优雅地消失?
lazy var alertController: UIAlertController = { [weak self] in
let alert = UIAlertController(title: "Alert", message: "This is a demo alert", preferredStyle: .Alert)
alert.addTextFieldWithConfigurationHandler { textField in
textField.delegate = self
}
alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
return alert
}()
@IBAction func alert() {
presentViewController(alertController, animated: true, completion: nil)
}
func textFieldShouldReturn(textField: UITextField) -> Bool {
alertController.dismissViewControllerAnimated(true, completion: nil)
return true
}