ios隐性动画---移动某点到某点

//动画开始和结束都会有delegate回调,具体回调内容可以使用setvalue的方式带参过去!
//[animation setValue:@(index) forKey:@"AnimationViewIndex"];
//另外可以通过下面函数来画出想要的行动轨迹。
//CGPathMoveToPoint、CGPathAddLineToPoint、CGPathAddArc、CGPathAddRect'

//------------------------------------凌乱的分割线----------------------------------------
//如果你只是想简单的移动某点到某点的话,可以使用CABasicAnimation能更简单点

  • (CABasicAnimation *)getMoveAnimation:(CGPoint)tpoint fromPoint:(CGPoint)fpoint index:(int)index type:(NSString *)type {
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
    // 设定动画起始帧和结束帧
    animation.fromValue = [NSValue valueWithCGPoint:fpoint]; // 起始点
    animation.toValue = [NSValue valueWithCGPoint:tpoint]; // 终点
    animation.fillMode = kCAFillModeForwards;
    animation.removedOnCompletion = NO;
    animation.repeatCount = 0;
    animation.delegate = self;
    [animation setValue:@(index) forKey:@"AnimationViewIndex"];
    [animation setValue:type forKey:@"AnimationKeyType"];

    float d = sqrtf ((fpoint.x-tpoint.x)(fpoint.x-tpoint.x)+(fpoint.y-tpoint.y)(fpoint.y-tpoint.y));
    animation.duration = d/500;
    return animation;
    }
    //速度控制函数(CAMediaTimingFunction)
    //1> kCAMediaTimingFunctionLinear(线性):匀速,给你一个相对静态的感觉
    //2> kCAMediaTimingFunctionEaseIn(渐进):动画缓慢进入,然后加速离开
    //3> kCAMediaTimingFunctionEaseOut(渐出):动画全速进入,然后减速的到达目的地
    //4> kCAMediaTimingFunctionEaseInEaseOut(渐进渐出):动画缓慢的进入,中间加速,然后减速的到达目的地。

//移动简单的移动外还有启动的动画,只需要修改keyPath值就行
//@"position":位置移动
//@"transform.scale":缩放
//@"transform.rotation.x":x轴旋转
//@"transform.rotation.y":y轴旋转
//@"transform.rotation.z":z轴旋转
//默认以layer中心为圆心,可以通过下面方式修改
//[yourView.layer setAnchorPoint:CGPointMake(0.5, 0.5)];

//组合动画
//
///* 动画组 */
//CAAnimationGroup *group = [CAAnimationGroup animation];
//group.delegate = self;
//group.duration = 5.0;
//group.repeatCount = 1;
//
//// 动画结束后不变回初始状态
//group.removedOnCompletion = NO;
//group.fillMode = kCAFillModeForwards;
//
//// 添加动画
//group.animations = [NSArray arrayWithObjects:animation1, animation2, nil];
//[imageView.layer addAnimation:group forKey:@"move-rotate-layer"];

你可能感兴趣的:(ios隐性动画---移动某点到某点)