SkyFloatingLabelTextField icon indicating copy to clipboard operation
SkyFloatingLabelTextField copied to clipboard

Trying to animate input view container using layoutIfNeeded causes field animation to trigger also

Open mania3908 opened this issue 8 years ago • 8 comments

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?

mania3908 avatar Jan 25 '17 02:01 mania3908

You can try to empty the queue of waiting layout operations with layoutIfNeeded and use it again when you try to grow your view.

bogren avatar Feb 05 '17 09:02 bogren

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.

skerkewitz avatar Feb 06 '17 09:02 skerkewitz

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.

intonarumori avatar Feb 06 '17 10:02 intonarumori

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

skerkewitz avatar Feb 06 '17 13:02 skerkewitz

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?

intonarumori avatar Feb 06 '17 15:02 intonarumori

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

k0nserv avatar Apr 19 '17 09:04 k0nserv

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.

skerkewitz avatar Apr 19 '17 09:04 skerkewitz

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.

abdurrahmansanli avatar Jun 24 '19 13:06 abdurrahmansanli