我想滑動一個文本框,它位於tableview的底部(實際上,在其頁腳視圖中)。所以我嘗試了兩種方法:鍵盤顯示時滑動tableview
- 要動態自動佈局約束的tableview
仍然
動畫contentInsets
func keyboardWillShow(notification: NSNotification) { if let keyboardHeight = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue.height { UIView.animate(withDuration: 0.2, animations: { self.tableView.contentInset = UIEdgeInsetsMake(0, 0, keyboardHeight, 0) }) } } func keyboardWillHide(notification: NSNotification) { UIView.animate(withDuration: 0.2, animations: { self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0) }) }
動畫效果自動佈局約束
所以在第一個例子中,我從來沒有注意到animati上,也不tableview內容移動。在第二個示例中,我創建了一個自動佈局約束(底部垂直間距)的出口,但我得到了一些奇怪的結果。例如,tableview向上移動,但不完全,只有第一次。
如果我放了一個斷點,keyboardHeight
等於471
。我錯過了一些明顯的東西?
使用[IQKeyboardManager](https://github.com/hackiftekhar/IQKeyboardManager#installation- with-cocoapod-) – pkc456
@ pkc456對不起,沒有第三方是我的選擇。 – Whirlwind
爲什麼你不能在模擬器上測試? – Devster101