Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS在屏幕键盘出现时隐藏导航栏_Ios_Uinavigationbar_Uisearchbar_Uikeyboard - Fatal编程技术网

iOS在屏幕键盘出现时隐藏导航栏

iOS在屏幕键盘出现时隐藏导航栏,ios,uinavigationbar,uisearchbar,uikeyboard,Ios,Uinavigationbar,Uisearchbar,Uikeyboard,当在我的应用程序中激活屏幕键盘时,iOS导航栏将隐藏。我怎样才能防止这种情况发生?当用户在搜索栏中时,以及当用户在搜索栏中单击时,都会发生这种情况 当用户单击“取消”或“搜索/完成编辑”时,我设法在搜索页面上显示导航栏,但搜索栏随后会位于导航栏下 我没有在界面生成器上选择“键盘出现时隐藏栏” 试试这个 override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) NSNotificat

当在我的应用程序中激活屏幕键盘时,iOS导航栏将隐藏。我怎样才能防止这种情况发生?当用户在搜索栏中时,以及当用户在搜索栏中单击时,都会发生这种情况

当用户单击“取消”或“搜索/完成编辑”时,我设法在搜索页面上显示导航栏,但搜索栏随后会位于导航栏下

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

试试这个

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
}

您也可以只使用Xcode并取消选中:

当键盘出现时隐藏栏->”,这样做很有效


只需取一个布尔值,当键盘出现时,将其设置为真,调用prefersStatusBarHidden并返回YES,当键盘消失时,返回NO到prefersStatusBar Hidden必须在导航栏或tableview中使用搜索控制器?你能上传搜索栏的编码部分吗?或者点击这个链接。我在我的项目中包括了搜索栏,它工作得非常好@Lizzeiy你找到解决方案了吗?我在objective C中尝试过,当键盘出现时,它仍然隐藏导航栏。是的,我已经尝试更改为false,但它无法解决我的问题。无论如何,谢谢你:)
>  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;