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

3
当用户在我的应用程序中使用屏幕键盘时,iOS导航栏会被隐藏。我该如何防止这种情况发生?当用户在搜索栏中或单击其中时,它都会发生。
我设法在用户单击取消或搜索/完成编辑后在搜索页面上显示导航栏,但搜索栏会被导航栏遮挡。
我在界面构建器中没有选择“如果键盘出现则隐藏栏”的选项。
请参考以下图片: enter image description here enter image description here

只需取一个布尔值,当键盘出现时将其设置为true,并调用prefersStatusBarHidden并返回YES,当键盘消失时返回NO以隐藏prefersStatusBar。 - Saurabh Prajapati
您IP地址为143.198.54.68,由于运营成本限制,当前对于免费用户的使用频率限制为每个IP每72小时10次对话,如需解除限制,请点击左下角设置图标按钮(手机用户先点击左上角菜单按钮)。 - Badal Shah
@Lizzeiy,你找到解决方案了吗? - d.ennis
3个回答

3

您也可以直接打开Xcode并取消勾选:

隐藏栏->“当键盘出现时”,这样就可以了。

enter image description here


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
}

我在Objective C中尝试了这个,当键盘出现时它仍然隐藏导航栏。 - Lizzeiy
是的,我已经尝试将其更改为false,但它并没有解决我的问题。无论如何还是谢谢 :) - Lizzeiy

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;

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接