键盘隐藏时不隐藏输入 accessoryView

Don't hide input accessoryView when keyboard hides

我希望 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)
        
        
    }

您需要将该视图添加到当前视图。通过将其设置为 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)
}