SkyFloatingLabelTextField
SkyFloatingLabelTextField copied to clipboard
Trying to animate input view container using layoutIfNeeded causes field animation to trigger also
I have a UIview as a container for a SkyFloatingLabelTextField and another uiview that can grow its height. Im trying to animate that growing but when i use layoutIfNeeded for the container, i also can see the text for the input animating from the top to its position in the input field.
Is there a way to prevent the animation in this case?
You can try to empty the queue of waiting layout operations with layoutIfNeeded
and use it again when you try to grow your view.
I have the same problem. @mania3908 did you found a solution?
To be honest: this is a bug in SkyFloatingTextField for me and I should not worry to workaround it.
Thanks guys for reporting, I can take a look. If you can provide a sample project to reproduce it would make it much faster to track it down.
Thanks.
I can fix my issues by adding a simple layoutIfNeeded()
before the animation block in -[SkyFloatingLabelTextField updateTitleVisibility:completion:]
. As far as I know you should add such a call in front of an animation block anyways.
See http://stackoverflow.com/a/12664093/5385140 - unfortunately the Apple link is down.
@mania3908 can you give it a try and check if your problem is also gone?
Pull Request: https://github.com/Skyscanner/SkyFloatingLabelTextField/pull/101
Calling layoutIfNeeded
is usually needed when you want to animate constraint based layout changes. It's usually not required before regular UIView animations.
Can you provide a stripped down example to demonstrate the problem?
As @moogle19 identified the fix in #101 broke animations so I reverted it. I'll take a stab at investigating this case further and finding a fix that doesn't break animations
Hmm, I never notice that it breaks the animation. But I took another look and you are right.
Would be nice to find a solution that solve both animation problems.
I have tried calling a layoutIfNeeded() just before my UIView animated layoutIfNeeded() method but it didn't solve anything.
I've achieved a solution by doing so:
textField.delegate = self
extension YoutViewController: UITextFieldDelegate {
func textFieldDidEndEditing(_ textField: UITextField) {
self.view.layoutIfNeeded()
}
}
This triggers just right in time before the keyboard hiding/showing animations and vice versa. All the animations in the page works correctly without interrupting the textField.