在我的应用程序中激活屏幕键盘时,隐藏iOS导航栏。我怎样才能防止这种情况发生?当用户在搜索栏中时以及用户点击它时,就会发生这种情况。
用户点击取消或搜索/完成编辑后,我设法在搜索页面上显示导航栏,但搜索栏会进入导航栏。
如果出现键盘,我没有"隐藏栏"在界面构建器上选择。
答案 0 :(得分:2)
答案 1 :(得分:0)
试试这个,
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShowNotification:", name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillHideNotification:", name: UIKeyboardWillHideNotification, object: nil)
}
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillHideNotification, object: nil)
}
func keyboardWillShowNotification(notification: NSNotification) {
self.navigationController?.navigationBarHidden = false
}
func keyboardWillHideNotification(notification: NSNotification) {
self.navigationController?.navigationBarHidden = false
}
答案 2 :(得分:0)
> NSDictionary* info = [note userInfo];
> CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
> UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height+80, 0.0);
> _scrollBackground.contentInset = contentInsets;
> _scrollBackground.scrollIndicatorInsets = contentInsets;