InputAccessoryView docked at bottom InputAccessoryView docked at bottom ios ios

InputAccessoryView docked at bottom


I was just shown "the" solution by Jason Foreman (@threeve). On your view controller (yes, view controller) add inputAccessoryView: and return the view you want to dock at the bottom and move with the keyboard. It just works. The view doesn't actually need to be in your view hierarchy it will be inserted by the view controller automatically.

edit: also implement canBecomeFirstResponder and return YES (as noted by Max Seelemann). reloadInputViews can be handy too.


Jonathan Badeen's aforementioned solution worked for me. Here's code from Arik showing how to implement it (this should go in your appropriate view controller):

    - (BOOL)canBecomeFirstResponder{        return YES;    }    - (UIView *)inputAccessoryView{        return self.inputAccessoryToolbar;       // where inputAccessoryToolbar is your keyboard accessory view    }


For those looking for Swift version:

Connect your toolbar (in my case 'myToolBar') on to your view controller. Then override canBecomeFirstResponder method and override the getter inputAccessoryView variable. Also don't forget to add the self.myToolBar.removeFromSuperview() or else xcode will complain.

class ViewController: UIViewController {    @IBOutlet var myToolBar: UIToolbar!    override func canBecomeFirstResponder() -> Bool {        return true    }    override var inputAccessoryView:UIView{        get{            return self.myToolBar        }    }    override func viewDidLoad() {        super.viewDidLoad()        self.myToolBar.removeFromSuperview()    }}