直播間點(diǎn)贊,直播間鼓掌動(dòng)畫?
通過隨機(jī)數(shù)動(dòng)設(shè)定隨機(jī)的貝塞爾曲線,實(shí)現(xiàn)變化無窮式凌波微步般的漂移動(dòng)畫?
代碼實(shí)現(xiàn)很簡介,如果動(dòng)效不能滿足需求,可通過修改相關(guān)參數(shù)進(jìn)行調(diào)整 直到滿足PM同學(xué)的需求為止
gitHub地址:https://github.com/KKKiller/KKHeartFlyAnimation
實(shí)現(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;//動(dòng)畫路徑高度
heartView.transform=CGAffineTransformMakeScale(0,0);
heartView.alpha=0;
//彈出動(dòng)畫
[UIViewanimateWithDuration:0.2delay:0.0usingSpringWithDamping:0.6initialSpringVelocity:0.8options:UIViewAnimationOptionCurveEaseOutanimations:^{
heartView.transform=CGAffineTransformIdentity;
heartView.alpha=0.9;
}completion:NULL];
//隨機(jī)偏轉(zhuǎn)角度
NSIntegeri =arc4random_uniform(2);
NSIntegerrotationDirection =1- (2*i);// -1 OR 1,隨機(jī)方向
NSIntegerrotationFraction =arc4random_uniform(10);//隨機(jī)角度
[UIViewanimateWithDuration:4animations:^{
heartView.transform=CGAffineTransformMakeRotation(rotationDirection *M_PI/(4+ rotationFraction*0.2));
}completion:NULL];
//動(dòng)畫路徑
UIBezierPath*heartTravelPath = [UIBezierPathbezierPath];
[heartTravelPathmoveToPoint:heartView.center];
//隨機(jī)終點(diǎn)
CGPointendPoint =CGPointMake(ViewX + rotationDirection*10, ViewY - AnimH);
//隨機(jī)control點(diǎn)
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];
}];
}