【发布时间】:2010-11-16 21:36:01
【问题描述】:
我正在尝试使用以下代码为 UIView 图层的子图层设置动画:
CALayer *sublayer = [[CALayer alloc] init];
[sublayer setFrame:myRect]; // myRect is a portion of the view's frame rectangle
[self.layer addSublayer:sublayer];
后来在我的 drawRect: 方法中:
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"opacity"];
anim.duration = 1.0f;
anim.fromValue = [NSNumber numberWithFloat:1];
anim.toValue = [NSNumber numberWithFloat:.5];
anim.delegate = self;
[sublayer addAnimation:anim forKey:@"animateOpacity"];
我不明白为什么我的子层没有动画,因为代码 [self.layer addAnimation:anim forKey:@"animateOpacity"]; 确实为视图的主层设置了动画。
谢谢。
【问题讨论】:
标签: iphone objective-c core-animation calayer