在使用键盘输入后,我正在使用IQKeyboardManager
来保持文本字段的显示。
即使单击文本字段,我也不想滚动到特定视图。以下是设计的屏幕截图。我希望'标题'保持在最顶层。
从他们的文档中there is a way to keep the navigation bar remain on top.
答案 0 :(得分:2)
试试这个。禁用此viewController的IQKeyboardManager。
为此,
IQKeyboardManager.sharedManager().disableInViewControllerClass(your view controller class name here)
并在那个viewController中编写以下代码。它将根据键盘高度移动您的视图
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(Login.keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(Login.keyboardWillHide), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
}
func keyboardWillShow(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
if self.view.frame.origin.y == 0{
self.view.frame.origin.y -= keyboardSize.height
}
}
}
func keyboardWillHide(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
if self.view.frame.origin.y != 0{
self.view.frame.origin.y += keyboardSize.height
}
}
}
现在你想要你的" HEADER "视图保持在TOP,
这样做:
**
YourViewController.view - > [headerView] [内容查看]
**
在[contentView]中放置 textfield 并在上面的代码中更改[contentView] .y而不是Self.view。
答案 1 :(得分:1)
禁用IQKeyboardManager
的{{1}}:
viewController
处理键盘:
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
IQKeyboardManager.sharedManager().enable = false
NotificationCenter.default.addObserver(self, selector: #selector(Login.keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(Login.keyboardWillHide), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
}
删除观察者:
func keyboardWillShow(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
if self.view.frame.origin.y == 0{
self.table_view.frame.origin.y -= keyboardSize.height
}
}
}
func keyboardWillHide(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
if self.view.frame.origin.y != 0{
self.table_view.frame.origin.y += keyboardSize.height
}
}
}