iOS之路11-核心动画

核心动画忘得差不多了,特地翻出代码,重新写了一遍,以下是核心动画的步骤

@interface ViewController ()
@property (nonatomic,weak)CALayer *layer;
@end


- (void)viewDidLoad {
    [super viewDidLoad];
    // 核心动画的步骤
    // 创建图层
    CALayer *layer = [CALayer layer];
    // 赋值属性
    self.layer = layer;
    // 图层的背景颜色
    layer.backgroundColor = [UIColor redColor].CGColor;
    // frame
    layer.frame = CGRectMake(100, 100, 100, 100);
    // 添加到layer
    [self.view.layer addSublayer:layer];
}


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    CABasicAnimation *anim = [CABasicAnimation animation];
    // 更改layer的哪个属性进行核心动画,scale代表缩放,rotation代表旋转
    anim.keyPath = @"transform.scale";
    // 改变什么样的值
    anim.toValue = @0.5;;;
    // 设置动画的执行次数,MAXFLOAT最大的执行次数,默认为0
    anim.repeatCount = 1;
    // 把核心动画添加到图层
    [self.layer addAnimation:anim forKey:nil];
}


转载于:https://my.oschina.net/u/2617794/blog/610462

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值