Gij*_*ese 5 ios swift swift3 iqkeyboardmanager
我用来IQKeyboardManager在使用键盘输入后保持文本字段上升。
即使单击文本字段,我也不想滚动到特定视图。下面是设计的屏幕截图。我希望“标题”保留在顶部。
从他们的文档来看,有一种方法可以使导航栏保持在顶部。
禁用 ViewController 的 IQKeyboardManager。
为了那个原因,
IQKeyboardManager.sharedManager().disableInViewControllerClass(ViewController.self)
Run Code Online (Sandbox Code Playgroud)
并在该 viewController 中编写以下代码。它将根据键盘高度向上移动您的视图
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(ViewController.keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(ViewController.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
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在你希望你的“ HEADER ”视图保持在顶部,
这样做:
**
YourViewController.view -> [headerView][contentView]
**
将文本字段放入 [contentView] 中并更改 [contentView].y 而不是上面代码中的 Self.view。
| 归档时间: |
|
| 查看次数: |
6102 次 |
| 最近记录: |