在 UITextField
上调用 becomeFirstResponder()
时,光标从左上角开始动画。如何删除它?
UITextField 在 SearchBar 中。
最佳答案
[ swift 4]
根据上述答案,我们可以制定另一种解决方法,即禁用此 native 光标进入动画。
让我们观察键盘事件,例如:
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: .UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidShow), name: .UIKeyboardDidShow, object: nil)
然后,在每个方法上:
@objc func keyboardWillShow(_ notification: Notification) {
searchBar.tintColor = UIColor.clear
}
@objc func keyboardDidShow(_ notification: Notification) {
searchBar.tintColor = UISearchBar.appearance().tintColor
}
或您决定的任何颜色。
关于ios - 移除 iOS 11 中的 UITextField 光标动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46367768/