抛物动画

作者: K__M | 来源:发表于2016-09-13 13:24 被阅读14次

    此动画在于运用 CAKeyframeAnimation 关键帧动画,以及贝塞尔关键帧动画

    - (void)throwObject:(UIView *)obj fromPoint:(CGPoint)startPoint toPoint:(CGPoint)endPoint height:(CGFloat)height duration:(CGFloat)duration {

    self.showingView = obj;

    // 初始化抛物线 path

    CGMutablePathRef path = CGPathCreateMutable();

    CGFloat cpx = (startPoint.x + endPoint.x)/2;

    CGFloat cpy = -height;

    CGPathMoveToPoint(path, NULL, startPoint.x, startPoint.y);

    CGPathAddQuadCurveToPoint(path, NULL, cpx, cpy, endPoint.x, endPoint.y);

    CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];

    animation.path = path;

    CFRelease(path);

    CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];

    scaleAnimation.autoreverses = YES;

    scaleAnimation.toValue = [NSNumber numberWithFloat:(CGFloat)((arc4random()%4) + 4)/10.0];

    CAAnimationGroup *groupAnimation = [CAAnimationGroup animation];

    groupAnimation.delegate = self;

    groupAnimation.repeatCount = 1;

    groupAnimation.duration = duration;

    groupAnimation.removedOnCompletion = NO;

    groupAnimation.animations = @[scaleAnimation,animation];

    [obj.layer addAnimation:groupAnimation forKey:@"position scale"];

    }

    代码地址:抛物线动画 

    相关文章

      网友评论

        本文标题:抛物动画

        本文链接:https://www.haomeiwen.com/subject/geemettx.html