On my UITextField the rightView property animates in (slides in) from the left when it's shown.
I'm unsure how to stop this behaviour from happening?
I had this happen recently on iOS 8.
It turns out that the initial position of the rightView
was at (0,0) relative to the UITextField
, and when it is being displayed for the first time, it is then set to its correct location. If the keyboard is being displayed at the same time, the position of the rightView
somehow get animated together with the animation of the keyboard. You can see this clearly in the simulator if you turn on "Slow Animations" (⌘ + T).
The solution is to set the rightView
to its final position before the keyboard animation starts. For example, in viewDidLoad
or viewWillAppear
, call:
textField.rightView.frame = [textField rightViewRectForBounds:textField.bounds]
Swift:
textField.rightView?.frame = textField.rightViewRect(forBounds: textField.bounds)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With