直播間點贊,直播間鼓掌動畫

直播間點贊,直播間鼓掌動畫?


通過隨機數(shù)動設定隨機的貝塞爾曲線,實現(xiàn)變化無窮式凌波微步般的漂移動畫?

代碼實現(xiàn)很簡介,如果動效不能滿足需求,可通過修改相關參數(shù)進行調(diào)整 直到滿足PM同學的需求為止

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

實現(xiàn)功能代碼如下:

- (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];

}];

}

最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容