直播间点赞,直播间鼓掌动画

作者: 安若宸king | 来源:发表于2016-09-05 15:33 被阅读502次

    直播间点赞,直播间鼓掌动画 

    通过随机数动设定随机的贝塞尔曲线,实现变化无穷式凌波微步般的漂移动画 

    代码实现很简介,如果动效不能满足需求,可通过修改相关参数进行调整 直到满足PM同学的需求为止

    gitHub地址:https://github.com/KKKiller/KKHeartFlyAnimation

    实现功能代码如下:

    - (void)showThePlauseInView:(UIView*)view blewView:(UIImageView*)v{

    NSIntegerindex =arc4random_uniform(7);

    NSString*image = [NSStringstringWithFormat:@"plause_%zd",index];

    UIImageView*heartView = [[UIImageViewalloc]initWithFrame:CGRectMake(App_Width-15-50,App_Height-135,40,40)];

    [viewinsertSubview:heartViewbelowSubview:v];

    heartView.image= [UIImageimageNamed:image];

    CGFloatViewX = heartView.center.x;

    CGFloatViewY = heartView.center.y;

    CGFloatAnimH =250;//动画路径高度

    heartView.transform=CGAffineTransformMakeScale(0,0);

    heartView.alpha=0;

    //弹出动画

    [UIViewanimateWithDuration:0.2delay:0.0usingSpringWithDamping:0.6initialSpringVelocity:0.8options:UIViewAnimationOptionCurveEaseOutanimations:^{

    heartView.transform=CGAffineTransformIdentity;

    heartView.alpha=0.9;

    }completion:NULL];

    //随机偏转角度

    NSIntegeri =arc4random_uniform(2);

    NSIntegerrotationDirection =1- (2*i);// -1 OR 1,随机方向

    NSIntegerrotationFraction =arc4random_uniform(10);//随机角度

    [UIViewanimateWithDuration:4animations:^{

    heartView.transform=CGAffineTransformMakeRotation(rotationDirection *M_PI/(4+ rotationFraction*0.2));

    }completion:NULL];

    //动画路径

    UIBezierPath*heartTravelPath = [UIBezierPathbezierPath];

    [heartTravelPathmoveToPoint:heartView.center];

    //随机终点

    CGPointendPoint =CGPointMake(ViewX + rotationDirection*10, ViewY - AnimH);

    //随机control点

    NSIntegerj =arc4random_uniform(2);

    NSIntegertravelDirection =1- (2*j);// -1 OR 1

    NSIntegerm1 = ViewX + travelDirection*(arc4random_uniform(20) +50);

    NSIntegerm2 = ViewX - travelDirection*(arc4random_uniform(20) +50);

    NSIntegern1 = ViewY -60+ travelDirection*arc4random_uniform(20);

    NSIntegern2 = ViewY -90+ travelDirection*arc4random_uniform(20);

    CGPointcontrolPoint1 =CGPointMake(m1, n1);

    CGPointcontrolPoint2 =CGPointMake(m2, n2);

    [heartTravelPathaddCurveToPoint:endPointcontrolPoint1:controlPoint1controlPoint2:controlPoint2];

    CAKeyframeAnimation*keyFrameAnimation = [CAKeyframeAnimationanimationWithKeyPath:@"position"];

    keyFrameAnimation.path= heartTravelPath.CGPath;

    keyFrameAnimation.timingFunction= [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionDefault];

    keyFrameAnimation.duration=2;// endPoint.y/viewHeight;

    [heartView.layeraddAnimation:keyFrameAnimationforKey:@"positionOnPath"];

    //Alpha & remove from superview

    [UIViewanimateWithDuration:2animations:^{

    heartView.alpha=0.0;

    }completion:^(BOOLfinished) {

    [heartViewremoveFromSuperview];

    }];

    }

    相关文章

      网友评论

        本文标题:直播间点赞,直播间鼓掌动画

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