在IQKeyboardManager中始终将视图保持在顶部(不要使用键盘滚动) [英] Keep a view always on top (Don't scroll with keyboard) in IQKeyboardManager
问题描述
我正在使用 IQKeyboardManager
,以便在使用键盘输入后保持文本字段显示。
I'm using IQKeyboardManager
to keep the text fields to go up after typing with the keyboard.
即使单击文本字段,我也不想滚动到特定视图。以下是设计的屏幕截图。我希望'标题'保持在最顶层。
I don't want to scroll to a specific view even when clicked on the text field. Below is the screenshot of the design. I want the 'header' to remain on top.
从他们的文档中,有办法保持导航栏保持在最顶层。
推荐答案
试试这个。禁用此viewController的IQKeyboardManager。
Try this. Disable the IQKeyboardManager for your this viewController.
为此,
IQKeyboardManager.sharedManager().disableInViewControllerClass(your view controller class name here)
并在那个viewController中写下面的码。它会根据键盘高度移动你的视图
And In that viewController write following code. It will move your view up as per keyboard height
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然后,
Now you want your "HEADER" view remain on TOP then,
这样做:
**
YourViewController.view - > [headerView] [contentView]
YourViewController.view -> [headerView][contentView]
**
在[contentView]中输入 textfield 并在上面的代码中更改[contentView] .y而不是Self.view。
Put textfield in [contentView] And change [contentView].y instead of Self.view in above code.
这篇关于在IQKeyboardManager中始终将视图保持在顶部(不要使用键盘滚动)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!