我想用下面的代码动画一个UIView的层的子层:iphone:动画一个CALayer的子层
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"];
确实为视图的主图层设置了动画效果。
谢谢。