0
我有一個CALayer,我想在整個屏幕上進行動畫處理。我創建了兩種方法:一張幻燈片打開圖層,另一張幻燈片關閉。這些都通過將屬性分配給圖層的transform屬性來工作。CAAnimation和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;
}
}