marcosgriselli / ViewAnimator

ViewAnimator brings your UI to life with just one line
MIT License
7.3k stars 488 forks source link

Animations don't work when presenting a ViewController #64

Closed d0hnj0e closed 4 years ago

d0hnj0e commented 4 years ago

Expected Behavior

Animation should work in every VC

Actual Behavior

Animation only works in initial VC

Steps to Reproduce the Problem

Creating two VCs, connecting them, using a code like

let fromAnimation = AnimationType.from(direction: .left, offset: 80)
headingTextLabel.animate(animations: [fromAnimation], delay: 0, duration: 0.5)
mainTextView.animate(animations: [fromAnimation], delay: 0, duration: 0.5)
continueButton.animate(animations: [fromAnimation], delay: 0.2, duration: 0.5)

and see the animation only on the initial VC

Specifications

marcosgriselli commented 4 years ago

@d0hnj0e does this happen on viewDidLoad()?

d0hnj0e commented 4 years ago

@marcosgriselli, yes. In viewDidLoad() I call a function which executes the code from above; moving the code directly to viewDidLoad() does not change the fact.

marcosgriselli commented 4 years ago

@d0hnj0e and it happens when pushing a UIViewController on a UINavigationController, right?

d0hnj0e commented 4 years ago

No, the segue is from an UIViewController to another UIViewController:

Screenshot 2020-01-23 at 13 37 42
marcosgriselli commented 4 years ago

Got it, I'll review it in the upcoming days.

d0hnj0e commented 4 years ago

Thanks, Marcos! Very kind!

d0hnj0e commented 4 years ago

I solved the problem, @marcosgriselli:

If you present a UIViewController with any segue, you must not call the animation functions within viewDidLoad() but rather in viewDidLayoutSubviews(). The following code executes flawlessly and shows the animation as it should:

override func viewDidLayoutSubviews() {

        let fromAnimation = AnimationType.from(direction: .left, offset: 80)
        headingTextLabel.animate(animations: [fromAnimation], delay: 0, duration: 0.5)
        mainTextView.animate(animations: [fromAnimation], delay: 0, duration: 0.5)
        continueButton.animate(animations: [fromAnimation], delay: 0.2, duration: 0.5)

}

Maybe you could briefly update the README.md accordingly. :)

And: Thanks for your great work with this library!

marcosgriselli commented 4 years ago

Thanks @d0hnj0e! I'll make sure to add a presentation example on the demo app. I'll close the issue.