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

来源:互联网 发布:怎么做淘宝联盟分享赚 编辑:程序博客网 时间:2024/05/14 00:31

动画:平移,旋转,缩放

缩放:

//创建动画对象    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