【问题标题】:Don't hide input accessoryView when keyboard hides键盘隐藏时不要隐藏输入附件视图
【发布时间】:2020-12-30 07:46:42
【问题描述】:

我希望 inputAccessoryView 在键盘关闭时不隐藏。我尝试在键盘隐藏时更改框架但它不起作用

     customView = UIView(frame: CGRect(x: 0, y: 0, width: 10, height: 88))
     customView.backgroundColor = UIColor.white
     textview.inputAccessoryView = customView



    // Tracking the keyboard status
     NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillBeHidden), name: UIResponder.keyboardWillHideNotification, object: nil)


    @objc func keyboardWillHide(sender: NSNotification) {        

        self.customView.frame = CGRect(x: 0, y: self.view.frame.size.height-88, width: 10, height: 88)
        
        
    }

【问题讨论】:

  • 谢谢@BlindNinja,我太笨了。我正在尝试,非常感谢您
  • 我已将其添加为答案。

标签: ios swift swift5 inputaccessoryview


【解决方案1】:

您需要将该视图添加到当前视图。通过将其设置为inputAccessoryView,您基本上是将其添加到第一响应者的视图中,在这种情况下是键盘。

试试这个 -

@objc func keyboardWillHide(sender: NSNotification) {        

    self.customView.frame = CGRect(x: 0, y: self.view.frame.size.height-88, width: 10, height: 88)
    
    self.view.addSubView(self.customView)
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-08
    • 2017-02-14
    • 2014-04-07
    • 2014-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多