Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make UITextView parent be its own inputAccessoryView

I'm trying to achieve a similar keyboard interaction that Messages has in iOS 7. I have a UIView which contains a UITextView, and when the user selects it to start typing, I want to make this UIView the inputAccessoryView. This would take care of the animation for me, as well as the new UIScrollView keyboard dismiss interaction in iOS 7.

When the UITextView begins editing, I'm trying to set its inputAccessoryView to its parent UIView (which is already in the view hierarchy). The keyboard appears but not with an accessory view.

I've read some people are using a duo of UITextFields to make this work, but that seems like a bad way to achieve this.

Any suggestions?

like image 206
Ricky Avatar asked Nov 20 '13 22:11

Ricky


1 Answers

A much easier solution is to make your input field the input accessory view of your view controller:

- (BOOL)canBecomeFirstResponder
{
    return YES;
}

- (UIView *)inputAccessoryView
{
    return self.yourInputField;
}

The view will be on screen at the bottom of the screen and when it becomes first responder in response to a user tapping it, the keyboard will be presented. The view will be animated such that it remains immediately above the keyboard.

like image 61
pr1001 Avatar answered Oct 17 '22 01:10

pr1001