Issue with CAAnimation and CALayer Transforms
Posted
by Brian
on Stack Overflow
See other posts from Stack Overflow
or by Brian
Published on 2010-04-14T20:51:51Z
Indexed on
2010/04/14
20:53 UTC
Read the original article
Hit count: 418
I have a CALayer that I want to animate across the screen. I have created two methods: one slide open the layer and one to slide close. These both work by assigning a property to the layer's transform property.
Now I want to use a CAKeyFrameAnimation to slide open the layer. I got this working so the layer slides open, but now I can't slide the layer close using my old method. I am trying to figure out why this is. Any help would be great.
Code:
- (id)init
{
if( self = [super init] )
{
bIsOpen = NO;
closeTransform = self.transform;
openTransform = CATransform3DMakeTranslation(-235.0, 0.0, 0.0);
}
return self;
}
- (void)closeMenu
{
if( bIsOpen )
{
self.transform = closeTransform;
bIsOpen = !bIsOpen;
}
}
- (void)openMenu
{
if( !bIsOpen )
{
CAKeyframeAnimation *closeAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
closeAnimation.duration = 1.0;
closeAnimation.removedOnCompletion = NO;
closeAnimation.fillMode = kCAFillModeForwards;
closeAnimation.values = [NSArray arrayWithObjects:[NSValue valueWithCATransform3D:closeTransform],[NSValue valueWithCATransform3D:openTransform],nil];
closeAnimation.timingFunctions = [NSArray arrayWithObject:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
[self addAnimation:closeAnimation forKey:@"transform"];
bIsOpen = !bIsOpen;
}
}
© Stack Overflow or respective owner