Animating UITextInput's textInputView

流过昼夜 提交于 2019-12-07 03:04:14

问题


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?


回答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.




回答2:


  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 ;)



来源:https://stackoverflow.com/questions/14756334/animating-uitextinputs-textinputview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!