UI 动画之CALayer+CAAnimation 之 CABasicAnimation

87 篇文章 0 订阅
11 篇文章 0 订阅

#pragma mark CALayer+CAAnimation 准备视图

    

    self.customLabel1 = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];

    _customLabel1.backgroundColor = [UIColor cyanColor];

    

    [self.view addSubview:_customLabel1];

    

    self.customView = [[UIView alloc]initWithFrame:CGRectMake(200, 200, 100, 150)];

    

    _customView.backgroundColor = [UIColor magentaColor];

    

    [self.view addSubview:_customView];


===========================


#pragma mark 模拟 动画

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

    

    

    //CALayer 影响属性:cornerRadius圆角、shadowolor阴影颜色、ShadowOffset阴影偏移距离、ShadowRadius阴影模糊程度、ShadowOpacit阴影透明度、BorderWidth描边粗细、BorderColor描边颜色、anchorPoint锚点、position位置信息、transform使CALayer产生3D空间内的平移.缩放.旋转等变化。

#pragma mark CABasicAnimation

    //这里的keyPath需要强打

    CABasicAnimation *basicAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];

    

    //设定变换初始值 都是id对象类型的,所以用字面量。

    basicAnimation.fromValue = @0;


    //设定变换后的结束值

    basicAnimation.toValue = @(M_PI_4);

    

    //设定动画间隔

    basicAnimation.duration = 4;

    

    //必须把动画添加到layer层上

    //这里的key是随便取的,主要是因为移除动画的时候,需要用到这个key

    [_customView.layer addAnimation:basicAnimation forKey:@"basic"];

    

    //解决旋转后要回到原始位置。--思想就是在动画刚好结束后,让他停在这个角度上。

    [self performSelector:@selector(stain) withObject:nil afterDelay:4];



=========================


-(void)stain

{

    _customView.transform = CGAffineTransformRotate(_customView.transform, M_PI_4);

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值