【发布时间】:2010-04-14 20:51:51
【问题描述】:
我有一个想要在屏幕上设置动画的 CALayer。我创建了两种方法:一种滑动打开图层,另一种滑动关闭。这些都通过为图层的变换属性分配一个属性来工作。
现在我想使用 CAKeyFrameAnimation 来滑动打开图层。我得到了这个工作,所以图层滑动打开,但现在我不能使用我的旧方法滑动图层关闭。我试图弄清楚为什么会这样。任何帮助都会很棒。
我的 CALayer 的代码:
- (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;
}
}
【问题讨论】:
标签: iphone uikit core-animation calayer caanimation