iOS在输入框键盘收起时,页面整体上移,露出了底部的黑底,目测一下,上移的高度大约是顶部的状态栏加导航条的高度,应该是键盘收起后navigationBar.translucent改变导致的。
解决方案:
- OC代码
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[IQKeyboardManager sharedManager].enable = NO;
[self.searchTitleView.searchBar becomeFirstResponder];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[IQKeyboardManager sharedManager].enable = YES;
}
- Swift代码
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
IQKeyboardManager.shared().isEnabled = false
searchTitleView.searchBar.becomeFirstResponder()
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
IQKeyboardManager.shared().isEnabled = true
}