当前位置:网站首页 > 图文广告 > 正文

ios 微信拼多多苹果手机微信打开有红包广告开红包动画

作者:admin发布时间:2021-09-02分类:图文广告浏览:评论:18


导读:模仿一波拼多多的开红包.主要用的就是绘制绘制(控制点起点和终点)基本动画未开启动画前,绘制两个显示不同的层次感.-(void){=[[]init];*pathFang=[U...

ios 微信拼多多开红包动画

模仿一波拼多多的开红包.

主要用的就是

绘制

绘制(控制点起点和终点)

基本动画

未开启动画前,绘制两个显示不同的层次感.

-(void){=[[]init];*pathFang=[UIBezierPathbezierPathWithRoundedRect:CGRectMake(20,10,self.frame.size.width-40,self.frame.size.height-20)cornerRadius:4];_redLayer.path=pathFang.CGPath;_redLayer.zPosition=1;[self.layeraddSublayer:_redLayer];[_redLayersetFillColor:[UIColorcolorWithRed:0.7968green:0.2186blue:0.204alpha:1.0].CGColor];//深色背景_lineLayer=[[CAShapeLayeralloc]init];UIBezierPath*path=[UIBezierPathbezierPathWithRoundedRect:CGRectMake(20,10,self.frame.size.width-40,self.frame.size.height*close_rate)byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)cornerRadii:CGSizeMake(4,4)];CGPointstartPoint=CGPointMake(20,self.frame.size.height*close_bot_rate+10);CGPointendPoint=CGPointMake(self.frame.size.width-20,self.frame.size.height*close_bot_rate+10);CGPointcontrolPoint=CGPointMake(self.frame.size.width*0.5,self.frame.size.height*close__bot_rate);//曲线起点[pathmoveToPoint:startPoint];//曲线终点和控制基点[pathaddQuadCurveToPoint:endPointcontrolPoint:controlPoint];//曲线部分颜色和阴影[_lineLayersetFillColor:[UIColorcolorWithRed:0.851green:0.3216blue:0.2784alpha:1.0].CGColor];[_lineLayersetStrokeColor:[UIColorcolorWithRed:0.9401green:0.0blue:0.0247alpha:0.02].CGColor];[_lineLayersetShadowColor:[UIColorblackColor].CGColor];[_lineLayersetLineWidth:0.1];[_lineLayersetShadowOffset:CGSizeMake(6,6)];[_lineLayersetShadowOpacity:0.2];[_lineLayersetShadowOffset:CGSizeMake(1,1)];_lineLayer.path=path.CGPath;_lineLayer.zPosition=1;[self.layeraddSublayer:_lineLayer];[selfaddTopText];[selfaddOpenButton];}

按钮添加的是CABasicAnimation动画

/***添加缩放动画*/-(void)addGrowAnimation:(UIButton*)sender{CABasicAnimation*scaleAnimation=[CABasicAnimationanimationWithKeyPath:@"transform.scale"];scaleAnimation.duration=0.5;scaleAnimation.fromValue=@(0.8);scaleAnimation.toValue=@(1.1);scaleAnimation.repeatCount=MAXFLOAT;scaleAnimation.autoreverses=YES;scaleAnimation.removedOnCompletion=NO;scaleAnimation.timingFunction=[CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];[sender.layeraddAnimation:scaleAnimationforKey:@"scaleAnimationDemo"];}/***给按钮添加了一个光晕添加外环*/-(void)addFlowAnimation:(UIButton*)sender{sender.layer.shadowPath=[UIBezierPathbezierPathWithRoundedRect:sender.boundsbyRoundingCorners:(UIRectCornerAllCorners)cornerRadii:CGSizeMake(sender.layer.cornerRadius,sender.layer.cornerRadius)].CGPath;sender.layer.shadowColor=[UIColorcolorWithHexString:@"#CD7F32"].CGColor;sender.layer.shadowOffset=CGSizeZero;sender.layer.shadowRadius=10;sender.layer.shadowOpacity=1;CABasicAnimation*animation=[CABasicAnimationanimationWithKeyPath:@"shadowRadius"];animation.fromValue=@(10);animation.toValue=@(0);animation.autoreverses=YES;animation.additive=NO;animation.duration=1.5;animation.fillMode=kCAFillModeForwards;animation.removedOnCompletion=NO;animation.repeatCount=INFINITY;[sender.layeraddAnimation:animationforKey:@"glowingAnimation"];}

其余的几个文案显示加的是label

/***添加恭喜发财文案*/-(void)addTopText{_topText=[[UILabelalloc]initWithFrame:CGRectMake(0,self.frame.size.height*0.2,self.frame.size.width,30)];_topText.text=@"五亿好礼开出来";_topText.tag=100;_topText.textColor=[UIColorcolorWithHexString:@"#e0ba88"];_topText.font=[UIFontboldSystemFontOfSize:25];_topText.textAlignment=NSTextAlignmentCenter;_topText.layer.zPosition=3;[selfaddSubview:_topText];_tips=[[UILabelalloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(_topText.frame)+10,self.frame.size.width,30)];_tips.text=@"点开即可获得100元大礼包";_tips.tag=101;_tips.textColor=[UIColorcolorWithHexString:@"#e0ba88"];_tips.font=[UIFontboldSystemFontOfSize:12];_tips.textAlignment=NSTextAlignmentCenter;_tips.layer.zPosition=3;[selfaddSubview:_tips];_botText=[[UILabelalloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(_tips.frame)+20,self.frame.size.width,30)];_botText.text=@"恭喜发财,大吉大利";_botText.tag=102;_botText.textColor=[UIColorcolorWithHexString:@"#e0ba88"];_botText.font=[UIFontboldSystemFontOfSize:20];_botText.textAlignment=NSTextAlignmentCenter;_botText.layer.zPosition=3;[selfaddSubview:_botText];}

点开动画

/***开红包后移动*/-(void)moveAnimation:(UIButton*)sender{CABasicAnimation*transformAnima=[CABasicAnimationanimationWithKeyPath:@"transform.rotation.y"];//transformAnima.fromValue=@(M_PI_2);transformAnima.toValue=[NSNumbernumberWithFloat:M_PI];transformAnima.duration=0.5;transformAnima.cumulative=YES;transformAnima.autoreverses=NO;transformAnima.repeatCount=HUGE_VALF;transformAnima.fillMode=kCAFillModeForwards;transformAnima.removedOnCompletion=NO;transformAnima.timingFunction=[CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionLinear];sender.layer.zPosition=5;sender.layer.zPosition=sender.layer.frame.size.width/2.f;[sender.layeraddAnimation:transformAnimaforKey:@"rotationAnimationY"];dispatch_after(dispatch_time(DISPATCH_TIME_NOW,(int64_t)(2*NSEC_PER_SEC)),dispatch_get_main_queue(),^{[senderremoveFromSuperview];UIBezierPath*newPath=[UIBezierPathbezierPathWithRoundedRect:CGRectMake(20,10,self.frame.size.width-40,self.frame.size.height*open_rate)byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)cornerRadii:CGSizeMake(4,4)];CGPointstartPoint=CGPointMake(20,self.frame.size.height*open_rate+10);CGPointendPoint=CGPointMake(self.frame.size.width-20,self.frame.size.height*open_rate+10);CGPointcontrolPoint=CGPointMake(self.frame.size.width*0.5,self.frame.size.height*open__rate);//曲线起点[newPathmoveToPoint:startPoint];//曲线终点和控制基点[newPathaddQuadCurveToPoint:endPointcontrolPoint:controlPoint];CGRectnewFrame=CGRectMake(20,10,self.frame.size.width-40,self.frame.size.height*open__rate);CABasicAnimation*pathAnim=[CABasicAnimationanimationWithKeyPath:@"path"];pathAnim.toValue=(id)newPath.CGPath;CABasicAnimation*boundsAnim=[CABasicAnimationanimationWithKeyPath:@"frame"];boundsAnim.toValue=[NSValuevalueWithCGRect:newFrame];CAAnimationGroup*anims=[CAAnimationGroupanimation];anims.animations=[NSArrayarrayWithObjects:pathAnim,boundsAnim,nil];anims.removedOnCompletion=NO;anims.duration=0.1f;anims.fillMode=kCAFillModeForwards;[self.topTextsetText:@"恭喜您获得"];NSMutableAttributedString*str=[[NSMutableAttributedStringalloc]initWithString:@"¥20.88"];[straddAttribute:NSFontAttributeNamevalue:[UIFontboldSystemFontOfSize:15]range:NSMakeRange(0,1)];self.botText.frame=CGRectMake(0,self.frame.size.height*open__rate+20,self.frame.size.width,35);[self.botTextsetFont:[UIFontboldSystemFontOfSize:30]];[self.botTextsetAttributedText:str];[selfaddGrowAnimation:self.botText];self.tips.frame=CGRectMake(0,self.frame.size.height*close__bot_rate+20,self.frame.size.width,20);[self.tipssetText:@"您要是不想使用可以转给我哟"];[self.lineLayeraddAnimation:animsforKey:nil];});}

©著作权归作者所有,转载或内容合作请联系作者


已有18位网友发表了看法:

欢迎 发表评论: