我有一个CALayer来动画其图像内容的变化。现在,如何更改动画播放的时间?

最佳答案

它或多或少简单。您有一个ivar CALayer *yourLayer。然后设置委托并实现委托方法-(id<CAAction>)actionForLayer:forKey:

- (void)awakeFromNib {
    yourLayer.delegate = self;
    yourLayer.name = @"yourLayer";
}
- (id <CAAction>)actionForLayer:(CALayer *)layer forKey:(NSString *)event {
    if([layer.name isEqualToString yourLayer.name]) { // Check for right layer

        CABasicAnimation *ani = [CABasicAnimation animationWithKeyPath:event]; // Default Animation for 'event'
        ani.duration = .5; // Your custom animation duration
        return ani;

    } else return nil; // Default Animation
}

09-07 13:22