你好呀,
我试图在点击 UITextField
时减少/增加键盘动画持续时间.
我尝试了不同的东西,但我无法实现我的目标:
textFieldShouldBeginEditing(textField: UITextField) -> Bool
中设置动画持续时间,但是当我尝试调用 textField.becomeFirstResponder()
时出现了无限循环再次调用func textFieldShouldBeginEditing(textField: UITextField) -> Bool
等等... NSNotification
的 UIKeyboardWillShowNotification
)但看起来为时已晚 UITapGestureRecognizer
给我的UITextField
这会触发动画,但我担心它会与原生 UITextField
冲突的手势识别器当我说“触发动画”时,我的意思是做这样的事情:
UIView.animateWithDuration(10.0, animations: {
textField.becomeFirstResponder()
})
我现在真的不知道该怎么做,改变这个动画持续时间似乎很棘手。
任何建议将不胜感激:)
最佳答案
一个简单的解决方案,覆盖 becomeFirstResponder,只记得做一些检查。
例子。
class MyTextField: UITextField{
override func becomeFirstResponder() -> Bool {
// guard clause
if(!self.canBecomeFirstResponder()) { return false }
UIView.animateWithDuration(1.0, animations: {
super.becomeFirstResponder()
})
return true;
}
}
只需将动画参数修改为您喜欢的任何内容,然后将您的 TextField 替换为 This MyTextField。
关于ios - 点击 UITextField 时更改键盘动画持续时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37455531/