uitextview contentinset默认动画
当要显示键盘时,我有此代码可以调整UITEXTVIEW。
@objc func keyboardWillShow(notification: NSNotification) {
if let rectValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue {
let keyboardSize = rectValue.cgRectValue.size
let contentInsets: UIEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: keyboardSize.height - view.safeAreaInsets.bottom, right: 0)
textView.contentInset = contentInsets
textView.scrollIndicatorInsets = contentInsets
}
}
我看到设置ContentInset
自动创建一个滚动动画(键盘完全出现后),使光标处的文本可见。动画会自动发生,无法将其禁用。当键盘显示时,我想滚动到文本视图中的给定位置(最好将其与键盘外观一起使用)。隐式contentInset
动画使其不可能。首先,键盘动画,然后ContentInset
动画,现在只能在TextView中使用我们选择的位置动画。这很尴尬。我想知道实现它的正确方法是什么?
I have this code to adjust UITextView when keyboard is about to be displayed.
@objc func keyboardWillShow(notification: NSNotification) {
if let rectValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue {
let keyboardSize = rectValue.cgRectValue.size
let contentInsets: UIEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: keyboardSize.height - view.safeAreaInsets.bottom, right: 0)
textView.contentInset = contentInsets
textView.scrollIndicatorInsets = contentInsets
}
}
I see setting contentInset
automatically creates a scrolling animation (after the keyboard appears fully) that makes the text at the cursor visible. The animation happens automatically and there is no way to disable it. I want to scroll to a given location in the textView sometimes when the keyboard is presented (preferably, animating it along with keyboard appearance). The implicit contentInset
animation makes it impossible however. First the keyboard animates, then contentInset
animates, and now only can I animate to my chosen location in textView. This is awkward. I am wondering what is the right way to achieve it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论