更改CALayer的属性的动画时间 [英] Change animation time for properties of a CALayer

查看:257
本文介绍了更改CALayer的属性的动画时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CALayer,用于动画更改其图片内容。现在,我如何改变这个动画发生的时间?

I have a CALayer to animate a change in its image contents. Now, how can I change how long it takes for this animation to take place?

推荐答案

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

It's more or less simple. You have an ivar CALayer *yourLayer. Then you set the delegate and implement the delegate method -(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
}

这篇关于更改CALayer的属性的动画时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆