Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUESTION] Custom logic during animation #501

Open
dzamani opened this issue Jun 18, 2017 · 8 comments
Open

[QUESTION] Custom logic during animation #501

dzamani opened this issue Jun 18, 2017 · 8 comments

Comments

@dzamani
Copy link

dzamani commented Jun 18, 2017

Hi,

I may have overlooked solutions and questions already in the issues but I think there isn't something like that. I was wondering if there was a way to add custom logic during an animation, for example take a UIView with some labels inside, I want a flip animation and when I flip I will switch the text inside the labels.

My current code (which is working) looks like this :

 contentView.animate(.flip(along: .y), duration: 1, damping: 1, velocity: 1, force: 1)
     UIView.animate(withDuration: 1, animations: { }) { (finished) in
       // do the text switch
     }

Of course I tried the completion block but it's not what I want since it will do the switch after the animation.
Also, while I could do my own custom transition or whatever but that wouldn't be very flexible like I want it.

Maybe there is another way I didn't get while reading the examples and docs or maybe there is no developed way to do that and in that case is there a good practice to follow ?

Thanks !

@JakeLin
Copy link
Member

JakeLin commented Jun 19, 2017

@dzamani I can't figure out a way how can we change the text during the animation using IBAnimatable. If you would like to have this feature. What kind of API would you like to see? another closure in the chainable API? Thanks.

@dzamani
Copy link
Author

dzamani commented Jun 19, 2017

Yes a closure would be perfect as it would allow nearly anything.
An equivalent of the UIView.animate that would allow running code during the animation.

@JakeLin
Copy link
Member

JakeLin commented Jun 19, 2017

@dzamani thanks, let's how can we improve it. We have some Core Animation as well. Since we already use animate method, can't find a good name for it 🤣

@dzamani
Copy link
Author

dzamani commented Jun 19, 2017

@JakeLin Adding 2 closures would be the perfect solution, one inside UIView.animate animations and one inside UIView.animate completion handler.
It would only take either some refactoring or another function definition for your API .animate

@JakeLin
Copy link
Member

JakeLin commented Jun 20, 2017

@dzamani we are using chainable API, it will be a promise-like method. And we already have completion method for completion handler

view.animate(.squeeze(way: .in, direction: .left))
    .completion { print("Animations finished!") }

how can we name the method to run one inside UIView.animate?

@dzamani
Copy link
Author

dzamani commented Jun 20, 2017

Well it's not the same behaviour, if the custom logic (switching text for example) was working with your completion handler I wouldn't need to user UIView.animate (like you can see in my example, the logic is inside the completion handler). If I use your completion handler, it switch way after the animation which is not what I want.

For the name we could call it animationHandler or animationCallback something like that.

@tbaranes
Copy link
Member

If I did understand well, you want another closure which will be called while the animation is running? Then, what about a animationFired or a name telling us that it will be called during the animation. Personally, I will have a hard time to differentiate the completion closure, and a animationHandler or animationCallback 🤔

@JakeLin
Copy link
Member

JakeLin commented Jun 20, 2017

may call it like .alsoRun{ label.text = "I am changing during the animation"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants