Reputation: 25993
I have a setter method for a property on a custom UIView
class. If it's set within a UIView
animation block, I'd like it to add a CABasicAnimation
to the view's layer with the same duration and easing as the UIView
animation. How do I find out whether I'm inside a UIView
animation block, and how do I get its duration and easing curve?
Upvotes: 1
Views: 2331
Reputation: 766
You can get the current animation easily enough. For instance, setting up a CATransaction
:
CAAnimation *animation = [self.layer animationForKey:self.layer.animationKeys.firstObject];
[CATransaction begin];
[CATransaction setAnimationDuration:animation.duration];
[CATransaction setAnimationTimingFunction:animation.timingFunction];
// CALayer animation here
[CATransaction commit];
Upvotes: 1
Reputation: 6342
Very simple.. You can get all animation keys applied to your view using
[self.YourView.layer animationKeys];
Upvotes: 2
Reputation: 8512
Based on this question I made this extension to UIView
block animations: UIView+AnimatedProperty.
It allows you to run CAAnimations
when the setter is called from animation block. Example with cornerRadius
is included.
Upvotes: 1
Reputation: 2001
The documentation for [UIView animateWithDuration] states that
This method performs the specified animations immediately using the UIViewAnimationOptionCurveEaseInOut and UIViewAnimationOptionTransitionNone animation options.
As for the duration, you set the duration yourself, so you already now that.
Upvotes: 0