Leaving inputAccessoryView visible after keyboard is dismissed Leaving inputAccessoryView visible after keyboard is dismissed ios ios

Leaving inputAccessoryView visible after keyboard is dismissed


It's done like this:

Assign your UIToolbar to a property in your view controller:

@property (strong, nonatomic) UIToolbar *inputAccessoryToolbar;

In your top view controller, add these methods:

- (BOOL)canBecomeFirstResponder{    return YES;}- (UIView *)inputAccessoryView{    return self.inputAccessoryToolbar;}

And then (optionally, as it usually shouldn't be necessary), whenever the keyboard gets hidden, just call:

[self becomeFirstResponder];

That way, your inputAccessoryToolbar will be both your view controller's and your text view's input accessory view.


I've ended up with UIToolBar that is not assigned as input accessory view, and slide up and down on UIKeyboardWillShowNotification / UIKeyboardWillHideNotification


Update to Swift 4, based on prior answers. If you add toolbar via storyboards you can do this

class ViewController: UIViewController {    @IBOutlet weak var textField: UITextField!    @IBOutlet var toolbar: UIToolbar!    override var canBecomeFirstResponder: Bool {        get {            return true        }    }    override var inputAccessoryView: UIView {        get {            return self.toolbar        }    }    override func viewDidLoad() {        super.viewDidLoad()        textField.inputAccessoryView = toolbar    }}

In this case, whenever text field resigns first responder, it defaults first responder to main view. Keep in mind, you might want to explicitly resign first responder, and set main view as first responder if there are multiple UI elements and first responder defaults to undesired view after resignation.