我有一个视图控制器,其中有表格视图和表格下方的 textView
当我点击 textView 时,键盘出现,当我点击 textView 外部时,键盘消失 这工作正常,但我有一个问题,即当我拖动(向下滚动)表格视图时,textView 不会随键盘向下移动,并且我在键盘后面看到黑色背景,如下图所示
如何在 Swift 中解决这个问题
更新: 这是我当前观察 keyboardFrameChanges 的代码
func keyboardFrameChanged(notification: NSNotification) {
let dict = NSDictionary(dictionary: notification.userInfo!)
let keyboardValue = dict.objectForKey(UIKeyboardFrameEndUserInfoKey) as! NSValue
let bottomDistance = mainScreenSize().height - keyboardValue.CGRectValue().origin.y
let duration = Double(dict.objectForKey(UIKeyboardAnimationDurationUserInfoKey) as! NSNumber)
UIView.animateWithDuration(duration, animations: {
self.inputViewConstraint!.constant = -bottomDistance
self.view.layoutIfNeeded()
}, completion: {
(value: Bool) in
self.chatTableView.scrollToBottom(animation: true)
})
}
Run Code Online (Sandbox Code Playgroud)
更新 2: 我通过将 keyboardDismissMode 从Interactive更改为OnDrag找到了解决方案
chatTableView.keyboardDismissMode = UIScrollViewKeyboardDismissMode.OnDrag
Run Code Online (Sandbox Code Playgroud)
一旦观察到表格中的任何拖动移动,这将立即将键盘和 textView 向下移动,但是如何在交互模式下执行此操作,例如在 whatsapp …
如何在Swift中检测当前设备(iPhone)是否有物理主页按钮或者没有,例如:iPhone X,iPhone Xs,iPhone Xs Max,iPhone Xr?