核心动画允许自定义动画通过实现您的CALayer基于类的actionForKey方法:如何在Core Animation中使用onOrderOut的自定义动画?
- (id<CAAction>)actionForKey:(NSString *)key {
// Custom animations
return [super actionForKey:key];
}
然后我就可以创建一个动画,并返回其为onOrderIn
动作(即当图层添加到另一层) 。这工作得很好。如果我对onOrderOut
执行相同操作(即,该层从其超级层上移除),则返回的动画将被忽略,并且会应用默认动画。
我的目标是,以放大层(onOrderIn
)和出(onOrderOut
):
- (id<CAAction>)actionForKey:(NSString *)key {
if ([key isEqualToString:@"onOrderIn"] || [key isEqualToString:@"onOrderOut"]) {
CABasicAnimation *a = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
a.duration = 0.25;
a.removedOnCompletion = NO;
a.fillMode = kCAFillModeBoth;
if ([key isEqualToString:@"onOrderIn"]) {
a.fromValue = [NSNumber numberWithFloat:0.0];
a.toValue = [NSNumber numberWithFloat:1.0];
} else {
a.fromValue = [NSNumber numberWithFloat:1.0];
a.toValue = [NSNumber numberWithFloat:0.0];
}
return a;
}
return [super actionForKey:key];
}
在作品放大,缩小不。相反,使用默认的淡出动画。
该代码可能包含一些拼写错误,因为我在另一台机器上输入了该错误。
任何人都可以帮忙吗?
啊,谢谢。我会测试这个,如果我再次需要它,意思是我们用Qt Jambi编写了一个完全不同版本的软件。 ;) – Lemming 2009-11-06 22:20:01