I'm trying to apply a slow motion effect to my application, much like the way you can slow down most of the Mac OS graphic effects if you press Shift.
My application uses CoreAnimation, so I thought it should not be a biggie: set it speedto some slower value (for example 0.1) and put it back 1as soon as I finish, and here I go.
Unfortunately, this seems to be the wrong way. Slowing works fine, however, when I want to return to normal speed, it resumes, as if the speed were 1all the time. This basically means that if I held Shift long enough as soon as I released it, the animation would instantly end.
I found a QA tech page explaining how to pause and resume animations, but I can't figure out if this is right if it doesn't completely stop the animation. I am definitely not very good at warping time.
What would be the right way to slow down and then resume animation using CoreAnimation?
Here is a useful code:
-(void)flagsChanged:(NSEvent *)theEvent
{
CALayer* layer = self.layer;
[CATransaction begin];
CATransaction.disableActions = YES;
layer.speed = (theEvent.modifierFlags & NSShiftKeyMask) ? 0.1 : 1;
[CATransaction commit];
}
zneak source
share