IOS如何实现签到散花效果(ios,移动开发)

时间:2024-05-04 03:48:55 作者 : 石家庄SEO 分类 : 移动开发
  • TAG :

本文讲述了IOS实现签到特效(散花效果)实例代码。分享给大家供大家参考,具体如下:

IOS如何实现签到散花效果

IOS如何实现签到散花效果

散花特效

#import<Foundation/Foundation.h>///领取奖励成功@interfaceRewardSuccess:NSObject/***成功动画*/+(void)show;@end
#import"RewardSuccess.h"#import"RewardSuccessWindow.h"#defineEmitterColor_Red[UIColorcolorWithRed:255/255.0green:0blue:139/255.0alpha:1]#defineEmitterColor_Yellow[UIColorcolorWithRed:251/255.0green:197/255.0blue:13/255.0alpha:1]#defineEmitterColor_Blue[UIColorcolorWithRed:50/255.0green:170/255.0blue:207/255.0alpha:1]@implementationRewardSuccess+(void)show{UIWindow*window=[UIApplicationsharedApplication].keyWindow;UIView*backgroundView=[[UIViewalloc]initWithFrame:window.bounds];backgroundView.backgroundColor=[UIColorcolorWithRed:0green:0blue:0alpha:0.8];[windowaddSubview:backgroundView];RewardSuccessWindow*successWindow=[[RewardSuccessWindowalloc]initWithFrame:CGRectZero];[backgroundViewaddSubview:successWindow];//缩放successWindow.transform=CGAffineTransformMakeScale(0.01f,0.01f);successWindow.alpha=0;[UIViewanimateWithDuration:0.4animations:^{successWindow.transform=CGAffineTransformMakeScale(1.0f,1.0f);successWindow.alpha=1;}];//3s消失doubledelayInSeconds=3;dispatch_time_tdelayInNanoSeconds=dispatch_time(DISPATCH_TIME_NOW,delayInSeconds*NSEC_PER_SEC);dispatch_after(delayInNanoSeconds,dispatch_get_main_queue(),^(void){[UIViewanimateWithDuration:0.4animations:^{successWindow.transform=CGAffineTransformMakeScale(.3f,.3f);successWindow.alpha=0;}completion:^(BOOLfinished){[backgroundViewremoveFromSuperview];}];});//开始粒子效果CAEmitterLayer*emitterLayer=addEmitterLayer(backgroundView,successWindow);startAnimate(emitterLayer);}CAEmitterLayer*addEmitterLayer(UIView*view,UIView*window){//色块粒子CAEmitterCell*subCell1=subCell(imageWithColor(EmitterColor_Red));subCell1.name=@"red";CAEmitterCell*subCell2=subCell(imageWithColor(EmitterColor_Yellow));subCell2.name=@"yellow";CAEmitterCell*subCell3=subCell(imageWithColor(EmitterColor_Blue));subCell3.name=@"blue";CAEmitterCell*subCell4=subCell([UIImageimageNamed:@"success_star"]);subCell4.name=@"star";CAEmitterLayer*emitterLayer=[CAEmitterLayerlayer];emitterLayer.emitterPosition=window.center;emitterLayer.emitterPosition=window.center;emitterLayer.emitterSize=window.bounds.size;emitterLayer.emitterMode=kCAEmitterLayerOutline;emitterLayer.emitterShape=kCAEmitterLayerRectangle;emitterLayer.renderMode=kCAEmitterLayerOldestFirst;emitterLayer.emitterCells=@[subCell1,subCell2,subCell3,subCell4];[view.layeraddSublayer:emitterLayer];returnemitterLayer;}voidstartAnimate(CAEmitterLayer*emitterLayer){CABasicAnimation*redBurst=[CABasicAnimationanimationWithKeyPath:@"emitterCells.red.birthRate"];redBurst.fromValue=[NSNumbernumberWithFloat:30];redBurst.toValue=[NSNumbernumberWithFloat:0.0];redBurst.duration=0.5;redBurst.timingFunction=[CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionLinear];CABasicAnimation*yellowBurst=[CABasicAnimationanimationWithKeyPath:@"emitterCells.yellow.birthRate"];yellowBurst.fromValue=[NSNumbernumberWithFloat:30];yellowBurst.toValue=[NSNumbernumberWithFloat:0.0];yellowBurst.duration=0.5;yellowBurst.timingFunction=[CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionLinear];CABasicAnimation*blueBurst=[CABasicAnimationanimationWithKeyPath:@"emitterCells.blue.birthRate"];blueBurst.fromValue=[NSNumbernumberWithFloat:30];blueBurst.toValue=[NSNumbernumberWithFloat:0.0];blueBurst.duration=0.5;blueBurst.timingFunction=[CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionLinear];CABasicAnimation*starBurst=[CABasicAnimationanimationWithKeyPath:@"emitterCells.star.birthRate"];starBurst.fromValue=[NSNumbernumberWithFloat:30];starBurst.toValue=[NSNumbernumberWithFloat:0.0];starBurst.duration=0.5;starBurst.timingFunction=[CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionLinear];CAAnimationGroup*group=[CAAnimationGroupanimation];group.animations=@[redBurst,yellowBurst,blueBurst,starBurst];[emitterLayeraddAnimation:groupforKey:@"heartsBurst"];}CAEmitterCell*subCell(UIImage*image){CAEmitterCell*cell=[CAEmitterCellemitterCell];cell.name=@"heart";cell.contents=(__bridgeid_Nullable)image.CGImage;//缩放比例cell.scale=0.6;cell.scaleRange=0.6;//每秒产生的数量//cell.birthRate=40;cell.lifetime=20;//每秒变透明的速度//snowCell.alphaSpeed=-0.7;//snowCell.redSpeed=0.1;//秒速cell.velocity=200;cell.velocityRange=200;cell.yAcceleration=9.8;cell.xAcceleration=0;//掉落的角度范围cell.emissionRange=M_PI;cell.scaleSpeed=-0.05;////cell.alphaSpeed=-0.3;cell.spin=2*M_PI;cell.spinRange=2*M_PI;returncell;}UIImage*imageWithColor(UIColor*color){CGRectrect=CGRectMake(0,0,13,17);UIGraphicsBeginImageContext(rect.size);CGContextRefcontext=UIGraphicsGetCurrentContext();CGContextSetFillColorWithColor(context,[colorCGColor]);CGContextFillRect(context,rect);UIImage*image=UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();returnimage;}@end

领取奖励成功提示框

#import<UIKit/UIKit.h>///领取奖励成功提示框@interfaceRewardSuccessWindow:UIView@end
#import"RewardSuccessWindow.h"staticCGFloatSuccessWindow_width=270;staticCGFloatSuccessWindow_hight=170;@implementationRewardSuccessWindow(instancetype)initWithFrame:(CGRect)frame{CGSizescreenSize=[UIScreenmainScreen].bounds.size;self=[superinitWithFrame:CGRectMake((screenSize.width-SuccessWindow_width)/2.0,(screenSize.height-SuccessWindow_hight)/2.0,SuccessWindow_width,SuccessWindow_hight)];if(self){[selfconfigSubViews];}returnself;}-(void)configSubViews{self.backgroundColor=[UIColorwhiteColor];self.layer.cornerRadius=10;self.layer.masksToBounds=YES;UILabel*titleLabel=[[UILabelalloc]initWithFrame:CGRectMake(0,45,SuccessWindow_width,22)];titleLabel.text=@"恭喜您,领取成功!";titleLabel.font=[UIFontsystemFontOfSize:19.0];titleLabel.textAlignment=NSTextAlignmentCenter;[selfaddSubview:titleLabel];UILabel*expLabel=[[UILabelalloc]initWithFrame:CGRectMake(0,75,SuccessWindow_width,43)];expLabel.font=[UIFontsystemFontOfSize:15];expLabel.textAlignment=NSTextAlignmentCenter;[selfaddSubview:expLabel];NSString*string=@"获得经验:+6";NSMutableAttributedString*attributedString=[[NSMutableAttributedStringalloc]initWithString:string];[attributedStringaddAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:15]range:NSMakeRange(0,string.length)];[attributedStringaddAttribute:NSFontAttributeNamevalue:[UIFontfontWithName:@"MarkerFelt-Thin"size:35]range:NSMakeRange(5,2)];NSShadow*shadow=[[NSShadowalloc]init];shadow.shadowOffset=CGSizeMake(1,3);[attributedStringaddAttribute:NSShadowAttributeNamevalue:shadowrange:NSMakeRange(5,2)];[attributedStringaddAttribute:NSForegroundColorAttributeNamevalue:[UIColoryellowColor]range:NSMakeRange(5,2)];expLabel.attributedText=attributedString;UILabel*bottomLabel=[[UILabelalloc]initWithFrame:CGRectMake(0,135,SuccessWindow_width,22)];bottomLabel.text=@"可以在我的->我的奖励中查看获得奖励";bottomLabel.font=[UIFontsystemFontOfSize:13.0];bottomLabel.textAlignment=NSTextAlignmentCenter;bottomLabel.textColor=[UIColorcolorWithRed:177/255.0green:177/255.0blue:177/255.0alpha:1];[selfaddSubview:bottomLabel];}@end
 </div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:IOS如何实现签到散花效果的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:springboot添加全局异常捕获类的示例下一篇:

8 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18