我有一个自定义图层(它是CALayer的子类)。在该课程中,我重写方法needsDisplayForKey:
,initWithLayer:
,actionForKey:
,如下所示:
-(id<CAAction>)actionForKey:(NSString *)event
{
if ([event isEqualToString:@"duration"]) {
return [self animationForKey:event];
}
return [super actionForKey:event];
}
- (CABasicAnimation *)animationForKey:(NSString *)key
{
NSString *animValue = [[self presentationLayer] valueForKey:key];
CABasicAnimation *anim;
if([key isEqualToString:@"duration"]) {
anim = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
anim.repeatCount = HUGE_VAL;
anim.autoreverses = YES;
anim.fromValue = [NSNumber numberWithFloat:0.5f];
}
anim.duration = 2;
return anim;
}
我使用此CALayer如下
@property(strong,nonatomic)ArcLayer *arcLayer;
self.arcLayer=[ArcLayer layer];;
self.arcLayer.duration=2;
self.arcLayer.frame = self.bounds;
self.arcLayer.backgroundColor = [UIColor greenColor].CGColor;
[self.layer addSublayer:self.arcLayer];
此代码在模拟器上正常工作,在模拟器上显示带动画的ArcLayer。但是,ArcLayer未显示在设备上。
为什么它不能在设备上运行?