以交互方式关闭键盘时如何检测键盘框架变化? [英] How to detect keyboard frame changes when dismiss the keyboard interactively?
问题描述
考虑这种情况,我有一个在情节提要中交互式设置键盘关闭的文本视图,因此当用户向下滚动并能够交互式关闭键盘时.我对底部的 textview 有限制,以确保它始终完全显示在视图上.
Consider this scenario, I have a textview with keyboard Dismiss interactively set in storyboard, so when user scroll down and able to dismiss keyboard interactively. I have constraints on the textview to bottom to make sure it is always fully displayed on the view.
当前的问题是,当用户逐渐向下滚动以关闭键盘时,我无法检测到键盘框架的变化.我尝试了 UIKeyboardWillHideNotification
和 UIKeyboardWillChangeFrameNotification
,它们仅在键盘关闭后才被调用.
Current problem is, when user gradually scroll down to dismiss the keyboard, I can not detect the keyboard frame changes. I tried UIKeyboardWillHideNotification
and UIKeyboardWillChangeFrameNotification
, they were only called after the keyboard dismissed.
所以我的问题是,当以交互方式关闭键盘时,我们如何同时检测键盘框架的变化?
So my question is, how can we detect keyboard frame changes simultaneously when dismiss the keyboard interactively?
推荐答案
您不应更改 textView 高度以适合所有视图.相反 - 您应该更改 contentInset 字段,这样您的 textView 将保持相同的高度,并且您不必担心交互式键盘的跟踪框架.请参阅此处的答案:如何在出现键盘时滚动 UIScrollView?
You shouldn't change the textView height to fit all view. Instead - you should change contentInset field so your textView will stay the same height and you won't have to bother about tracking frame of the interactive keyboard. See answer here: How do I scroll the UIScrollView when the keyboard appears?
这篇关于以交互方式关闭键盘时如何检测键盘框架变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!