【问题标题】:iOS Hiding navigation bar when on screen keyboard appears屏幕键盘出现时iOS隐藏导航栏
【发布时间】:2015-06-13 05:12:42
【问题描述】:

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

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

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

【问题讨论】:

  • 只取一个布尔值,当键盘出现时将其设置为 true 并调用 prefersStatusBarHidden 并返回 YES,当键盘消失时返回 NO 到 prefersStatusBar Hideen
  • 必须在导航栏或表格视图中使用搜索控制器吗?你能上传你的搜索栏的编码部分吗?或点击此链接。我在我的项目中包含了搜索栏,它工作得很好。 stackoverflow.com/questions/30752638/…
  • @Lizzeiy 你找到解决方案了吗?

标签: ios uinavigationbar uisearchbar uikeyboard


【解决方案1】:

你也可以继续 Xcode 并取消选中:

隐藏栏 -> “当键盘出现时” 效果很好。

【讨论】:

    【解决方案2】:

    试试这个,

    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中试过这个,当键盘出现时它仍然隐藏导航栏。
    • 是的,我已经尝试将其更改为 false,但这并不能解决我的问题。无论如何谢谢:)
    【解决方案3】:
    >  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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-28
      • 1970-01-01
      • 1970-01-01
      • 2020-11-15
      • 1970-01-01
      • 2019-01-22
      • 1970-01-01
      • 2017-08-24
      相关资源
      最近更新 更多