【发布时间】:2019-11-07 06:33:09
【问题描述】:
使用UITextFieldDelegate 我有两个函数可以控制文本字段开始编辑和结束发生的情况。
使用UIView.animate 我有一个按钮消失并使用.isHidden 和.alpha 属性隐藏。
正在使用.alpha,因为我还为按钮的消失设置了动画,但稍有延迟。
虽然消失效果很好,但在使用 textFieldDidEndEditing 时动画不起作用,按钮确实会恢复,但它会突然恢复并不容易。
要关闭键盘,我允许用户在 ViewDidLoad() 中使用它来点击任意位置
self.view.addGestureRecognizer(UITapGestureRecognizer(target:
self.view, action: #selector(UIView.endEditing(_:))))
我使用的委托函数如下:
extension ExampleViewController: UITextFieldDelegate {
func textFieldDidBeginEditing(_ textField: UITextField) {
if textField == exampleTextField {
UIView.animate(withDuration: 0.1, delay: 0.1, options: .curveEaseOut,
animations: {self.exampleButton.alpha = 0.0},
completion: { _ in self.exampleButton.isHidden = true
})
}
}
func textFieldDidEndEditing(_ textField: UITextField) {
if textField == exampleTextField {
UIView.animate(withDuration: 0.1, delay: 0.1, options: .curveEaseInOut,
animations: {self.exampleButton.alpha = 1.0},
completion: { _ in self.exampleButton.isHidden = false
//Do anything else that depends on this animation ending
})
}
}
}
为什么.curveEaseIn 不起作用?
【问题讨论】: