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

Support animations with timing functions #12

Closed
JakeLin opened this issue Dec 28, 2015 · 6 comments
Closed

Support animations with timing functions #12

JakeLin opened this issue Dec 28, 2015 · 6 comments

Comments

@JakeLin
Copy link
Member

JakeLin commented Dec 28, 2015

Currently, all animations are Spring animations, can support Easing animations as well.

@JakeLin JakeLin added this to the v5 milestone Feb 13, 2016
@phimage
Copy link
Member

phimage commented Apr 16, 2017

How about adding in Animatable

  /**
   Animation force (default value should be CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut))
   */
  var timingFunction: CAMediaTimingFunction { get set }

and to Animatable classes something like that

  @IBInspectable open var _timingFunction: String = kCAMediaTimingFunctionEaseInEaseOut {
    didSet {
      timingFunction = CAMediaTimingFunction(name: _timingFunction)
    }
  }
  open var timingFunction: CAMediaTimingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)

and in AnimationConfiguration

  let timingFunction: CAMediaTimingFunction

Instead of CAMediaTimingFunction we can have our own type TimingFunctionType enum or class which provide a CAMediaTimingFunction
So we can parse the string for custom CAMediaTimingFunction types
Wrapping allow providing optionnaly also multiple CAMediaTimingFunction for animation which requires multiples ones

@JakeLin
Copy link
Member Author

JakeLin commented Apr 17, 2017

@phimage Thanks for posting your idea. This is a useful feature. In one of my app, I slide a panel up and down. And I should use easeInEaseOut instead of Spring because using Spring will have a gap at the bottom (when bouncing) for a short period.

timingFunction property

I like your idea to have inspectable property timingFunction 👍. As you said, we may have our enum like TimingFunctionType. I can see two benefits of it.

Firstly, we can support more timing functions than linear, easeIn, easeOut, easeInEaseOut or easeOutEaseIn. We can have pre-defined timing functions like EaseOutQubic (CAMediaTimingFunction(controlPoints: 0.215, 0.61, 0.355, 1)).

Secondly, we can translate them into Core Animation or UIView Animation, In IBAnimatable, some of our animation uses Core Animation, and some use UIView Animation. In Core Animation, we use CAMediaTimingFunction. In UIView Animation, we use UIViewAnimationOptions. We need to provide a single enum and translate it into different timing function for Core Animation or UIView Animation.

Default value for timingFunction

For the default value for timingFunction, we may not able to set the default value to kCAMediaTimingFunctionEaseInEaseOut. Because timing function animation and Spring animation are conflicted each other. It means if we use timing function, we can't use Spring. iOS 10 introduced UIViewPropertyAnimator, we may be able to use both together but not at the same time. Therefore, we may treat timingFunction as a flag. If the user sets the animationType and timingFunction, then we use timing function to control the animation. If the user sets the animationType but not timingFunction, then we use damping, velocity and force for Spring animation as the current implementation.

timingFunction animation in code.

Adding timingFunction property is a great approach for support animation with timing function in Interface Builder. But we still need to provide nice programmatical API for using it in code. I don't know the exact solution yet, we may need to add new overload methods for Animatable.animate() and AnimationPromise.then(). We may need to spend some time to find the solution.

I think this is a great feature and do you think we should set it as the theme for release 5? Once we have it, we ship version 5.

@tbaranes can you also have a look at @phimage 's proposal?

@lastMove if you have time, can you have a look and provide some advice on timingFunction animation in code? It will be a great extension for your promise-like animation API.

@JakeLin JakeLin changed the title Easing animations Support animations with timing functions Apr 17, 2017
@phimage
Copy link
Member

phimage commented Apr 20, 2017

I will make the first move today
Create the feature branch and the enum, modify the Animatable classes, use enum when possible
Have already done the code yesterday, need some tests

I will add #12 to where I have questions

@phimage
Copy link
Member

phimage commented Apr 20, 2017

branch feature/timingfunction
https://github.com/IBAnimatable/IBAnimatable/tree/feature/timingfunction
https://github.com/IBAnimatable/IBAnimatable/compare/feature/timingfunction?expand=1

See all #12 in code for the question and work to do
Currently default value for animation is not well managed. There is a none case but I think about putting nil instead, depending on IBAnimatable philosophy. If none, when animating, default value must be used (not implemented)

@JakeLin
Copy link
Member Author

JakeLin commented Apr 20, 2017

@phimage great start 👍 Do you think we can create a PR like [WIP] Support timing function for animation? then we can make comments on the PR.

I think in IBAnimatable we use none for enums and nil for String value which maps to none case like MaskType and AnimationType.

If timingFunctionType is none, should we use the Spring animation as what we have already? If it is .default then use default timing?

@phimage
Copy link
Member

phimage commented Apr 21, 2017

PR #456 has been created
I will not have time this weekend to do more, so everybody could work on

@phimage phimage closed this as completed in 237e19c May 8, 2017
tbaranes added a commit that referenced this issue May 9, 2017
…nction

Revert "Support timing function for animation. Fix #12" #no-public-changes
phimage added a commit that referenced this issue May 11, 2017
phimage added a commit that referenced this issue May 17, 2017
…re/timingfunction

Support timing function for animation. Fix #12 #13
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

3 participants