IOS uses the inputAccessoryView property of the input box to add a view on the keyboard

Often use the input message and send the message in the application functions, such as today’s headlines or UC headlines these bottom of the software will have, how to think to these applications like UITextField or UITextView can click on the pop-up keyboard and can be coupled with the input and send function on the keyboard?
Many iOS Tongren trigger keyboard pops and the folded height at the position to add the input message and sending messages to view or change the view by monitoring the height to achieve, so much trouble, how to achieve this function without monitoring key up and stowed in the case? Apple’s own UITextField and UITextView attributes can be achieved as shown in the following figure:
IOS uses the inputAccessoryView property of the input box to add a view on the keyboard
17.gif
UITextField and UITextView have an auxiliary attribute inputAccessoryView, through which you can add a view on the keyboard, and to achieve the first off function, the method is very simple, as shown in the following code:
Import UIKit class ViewController: UIViewController let UIScreen.main.bounds.size.width let toolBar: {kScreenWidth = UIToolbar = tmpToolBar = let {/ / create ToolBar (frame: UIToolbar CGRect (x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: 70) tmpToolBar.backgroundColor) = UIColor.gray return tmpToolBar textView: UITextView (VaR)}! @IBOutlet weak var inputTextField: UITextField override func (viewDidLoad) {! Super.viewDidLoad (textView = UITextView) / / create UITextView (frame: CGRect (x: 0, y: 5, width: kScreenWidth/4*3, height: 60) textView.backgroundColor) = UIColor.lightGray let inputItem = UIBarButtonItem (customView: textView) / / create the send button (frame: = let sendBtn UIButton CGRect (x: 0, y: 5, width: kScreenWidth/4-40, height: 50) sendBtn.contentMode.Center (sendBtn.setTitle) = "send", for:.Normal) sendBtn.setTitleColor (UIColor.blue, for:.Normal sendBtn.addTarget (self), action: #selector (handleSend (event:)), for:.TouchUpInside let sendItem = UIBarButtonItem) (customView: sendBtn) //ToolBar textView and add the send button to toolBar.items = [inputItem, sendItem] / UITextField inputAccessoryView assigned to inputTextField.inputAccessoryView = toolBar func handleSend} (event: UIButton) (->); print (textView.text view.endEditing) {(true)}}
Is not very simple. Open var UIView inputAccessoryView: can be seen, because it is inherited UIView, so you can put the View you want to put and set the height to set.
Students interested in inputAccessoryView, you can try the next inputView will be pleasantly surprised oh!

Source code –> GitHub