Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
369 views
in Technique[技术] by (71.8m points)

ios - Don't hide input accessoryView when keyboard hides

i want inputAccessoryView to not to hide when keyboard dissmiss. I tried by changing the frame when keybaord hides but it not working

     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)
        
        
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to add that view on to current view. by setting it as inputAccessoryView, You are basically adding it on first responder's view which in this case is a keyboard.

Try this -

@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)
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...