6

UIKit text input components, such as UITextView and UITextField have a property inputView to add a custom keyboard. There are two questions I have relating to this.

  1. If the keyboard is currently visible and the property is set to a new input view, nothing happens. Resigning and regaining first responder status refreshes the input and displays the new view. Is this the best way to do it? If so it might answer my bigger question:

  2. Is it possible to animate the transition between two input views?

Anthony Mattox
  • 7,048
  • 6
  • 43
  • 59
  • The `textInputView` property is read-only. It can't be changed. When focus changes from one field to another, you are dealing with a whole new instance of a `UITextInput` based object. – rmaddy Feb 07 '13 at 17:06
  • Subclasses can override the property to make it writable. From UITextField.h: `@property (readwrite, retain) UIView *inputView;` Switching it works just fine, it just doesn't update the view hierarchy until the next time the input becomes first responder. – Anthony Mattox Feb 07 '13 at 19:38
  • 3
    You are confusing `UITextField inputView` and `UITextInput textInputView`. They are not the same thing. But you are correct that changing the `inputView` property of `UITextField` and `UITextView` doesn't take affect if the field/view is already the first responder. – rmaddy Feb 07 '13 at 20:49
  • Totally right! Edited the question accordingly. There is no way to to get finer grained control on the `inputView`? – Anthony Mattox Feb 07 '13 at 22:29
  • So, what are you trying to accomplish by animating between the two input views? – Chris Livdahl Feb 21 '13 at 19:44

2 Answers2

1

From the UIResponder docs:

Responder objects that require a custom view to gather input from the user should redeclare this property as readwrite and use it to manage their custom input view. When the receiver subsequently becomes the first responder, the responder infrastructure presents the specified input view automatically. Similarly, when the view resigns its first responder status, the responder infrastructure automatically dismisses the specified view.

So unfortunately the answer to 1 is Yes and 2 is No.

Rikkles
  • 3,372
  • 1
  • 18
  • 24
0
  1. Actually there is a method to do it cleanly: UIResponder's reloadInputViews, available from iOS 3.2!

  2. I think you can animated it with some extra work:

    • Create a clear background window of a higher UIWindowLevel than the keyboard window.
    • Add your custom keyboard there and animate its frame into place.
    • Then set it as your text input's inputView and refresh the first responder as you do.

Your custom keyboard will change its parent view from your custom window to the keyboard one, but hopefully the user won't notice ;)

Rivera
  • 10,792
  • 3
  • 58
  • 102