Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

Very simple.. You can get all animation keys applied to your view using

[self.YourView.layer animationKeys];

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];

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top