2015-06-13 97 views
3

在我的应用程序中激活屏幕键盘时,隐藏iOS导航栏。我怎样才能防止这种情况发生?当用户在搜索栏中,并且用户点击它时,就会发生这种情况。iOS在屏幕键盘出现时隐藏导航栏

一旦用户点击取消或搜索/完成编辑,我设法在搜索页面上显示导航栏,但搜索栏随后进入导航栏。

我没有在界面生成器上选择“隐藏栏,如果键盘出现”。

enter image description here

enter image description here

+0

只取一个布尔值,当键盘出现时将其真实的,并呼吁prefersStatusBarHidden并返回YES,当键盘消失返回NO来prefersStatusBar Hideen –

+0

不得不在导航栏或tableview中采取搜索控制器?你能上传你的搜索栏的编码部分吗?或者按照这个链接。我在我的项目中包含了搜索栏,并且它完美地工作。 http://stackoverflow.com/questions/30752638/ios-swift-how-to-make-a-floating-search-bar-with-drop-down-list-like-this-i/30753256#30753256 –

+0

@Lizzeiy你找到了解决方案吗? –

回答

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 
} 
+0

我在目标C中试过这个,当键盘出现时它仍然隐藏导航栏。 – Lizzeiy

+0

是的,我已经尝试改变为false,它不能解决我的问题。不管怎么说,还是要谢谢你 :) – Lizzeiy

2

你也可以去Xcode和取消:

隐藏栏 - > “当键盘出现”和罚款。

enter image description here

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;