Animating UITextInput's textInputView
Asked Answered
A

2

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?

Abutment answered 7/2, 2013 at 16:43 Comment(5)
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.Winsome
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.Abutment
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.Winsome
Totally right! Edited the question accordingly. There is no way to to get finer grained control on the inputView?Abutment
So, what are you trying to accomplish by animating between the two input views?Euryale
H
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.

Harmonicon answered 28/2, 2013 at 9:55 Comment(0)
G
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 ;)

Gilliam answered 28/2, 2014 at 1:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.