object-c 基础动画的学习总结

动画:平移,旋转,缩放

缩放:

//创建动画对象
    CABasicAnimation *animation = [CABasicAnimation animation];
    animation.keyPath = @"bounds";//缩放动画类型
<pre name="code" class="objc">    animation.keyPath = @"position";//平移动画类型
  animation.fromValue = [NSValue valueWithCGRect:CGRectMake(0, 0, 50, 50)];//起始值 animation.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0, 300, 300)];//结束值 animation.duration = 2;//执行时间 animation.repeatCount = 0;//设置动画次数 animation.beginTime = CACurrentMediaTime();//延时执行 animation.removedOnCompletion = NO;//保持动画后的状态 animation.fillMode = kCAFillModeForwards;//保持动画后状态 [self.imageViewBall.layer addAnimation:animation forKey:nil];//给图层添加动画

 

旋转:

CABasicAnimation *animation = [CABasicAnimation animation];
    animation.keyPath = @"transform.rotation";//动画类型
    animation.fromValue = [NSNumber numberWithFloat:M_PI*2];//旋转多大
    
    animation.duration = 0.00001;//动画时长
    animation.repeatCount = MAXFLOAT;//重复次数
    
    animation.removedOnCompletion = NO;
    animation.fillMode = kCAFillModeForwards;//这两句是保持动画结束后的状态
    
    [self.imageViewBall.layer addAnimation:animation forKey:nil];

帧动画:

CAKeyframeAnimation *keyAnimation = [[CAKeyframeAnimation alloc]init];
    keyAnimation.keyPath = @"position";
    
    NSMutableArray *tempArray = [NSMutableArray array];//数组为每一次移动的CGRect
    NSMutableArray *tempArrayTime = [NSMutableArray array];//对应动画数组长度,设置每一个动画的百分比时间

    keyAnimation.values = tempArray;//动画数组
    keyAnimation.keyTimes = tempArrayTime;//动画总的时长
    keyAnimation.duration = 3;//总动画时长
    
    keyAnimation.removedOnCompletion = NO;
    keyAnimation.fillMode = kCAFillModeForwards;
    
    [self.imageViewBall.layer addAnimation:keyAnimation forKey:nil];

贝赛尔曲线(实现效果是一个视图一直不停的围绕一个中心点转圈圈):

CAKeyframeAnimation *keyframeA = [[CAKeyframeAnimation alloc]init];
    keyframeA.keyPath = @"position";
    
//    //设置动画路径范围,这个动画再旋转的时候会停止然后继续旋转
//    UIBezierPath *bezier = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(50, 100, 250, 250)];
    keyframeA.path = bezier.CGPath;//类型转换
//    [bezier closePath];//关闭路径
    
    UIBezierPath *bezier2 = [UIBezierPath bezierPathWithArcCenter:CGPointMake(150, 200) radius:50 startAngle:0 endAngle:M_PI*2 clockwise:YES];//这个旋转动画不会暂停
    keyframeA.path = bezier2.CGPath;//类型转换
    
    keyframeA.duration = 0.5;
    keyframeA.repeatCount = MAXFLOAT;
    [self.imageViewBall.layer addAnimation:keyframeA forKey:nil];//给视图图层添加动画
    
    keyframeA.removedOnCompletion = NO;
    keyframeA.fillMode = kCAFillModeForwards;//操持原位


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值