美文网首页
红包动画

红包动画

作者: flyWhite | 来源:发表于2018-03-17 15:59 被阅读17次

- (void)wxRedPacket{ //深色背景 CAShapeLayer *redLayer = [[CAShapeLayer alloc] init]; UIBezierPath *pathFang = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(20, 80, screenW-40, screenH-160) cornerRadius:4]; redLayer.path = pathFang.CGPath; [self.view.layer addSublayer:redLayer]; [redLayer setFillColor:[UIColor colorWithRed:0.7968 green:0.2186 blue:0.204 alpha:1.0].CGColor]; //浅色红包口 CAShapeLayer *lineLayer = [[CAShapeLayer alloc] init]; UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(20, 80, screenW-40, screenH-320) byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight) cornerRadii:CGSizeMake(4, 4)]; CGPoint startPoint = CGPointMake(20, screenH-240); CGPoint endPoint = CGPointMake(screenW-20, screenH-240); CGPoint controlPoint = CGPointMake(screenW*0.5, screenH-180); //曲线起点 [path moveToPoint:startPoint]; //曲线终点和控制基点 [path addQuadCurveToPoint:endPoint controlPoint:controlPoint]; //曲线部分颜色和阴影 [lineLayer setFillColor:[UIColor colorWithRed:0.851 green:0.3216 blue:0.2784 alpha:1.0].CGColor]; [lineLayer setStrokeColor:[UIColor colorWithRed:0.9401 green:0.0 blue:0.0247 alpha:0.02].CGColor]; [lineLayer setShadowColor:[UIColor blackColor].CGColor]; [lineLayer setLineWidth:0.1]; [lineLayer setShadowOffset:CGSizeMake(6, 6)]; [lineLayer setShadowOpacity:0.2]; [lineLayer setShadowOffset:CGSizeMake(1, 1)]; lineLayer.path = path.CGPath; [self.view.layer addSublayer:lineLayer]; //发红包按钮 UIButton *sendBtn = [[UIButton alloc] initWithFrame:CGRectMake((screenW-100)/2, screenH-240-20, 100, 100)]; sendBtn.layer.masksToBounds = YES; sendBtn.layer.cornerRadius = sendBtn.bounds.size.height/2; [sendBtn setTitle:@"发红包" forState:UIControlStateNormal]; [sendBtn setBackgroundColor:[UIColor brownColor]]; [sendBtn addTarget:self action:@selector(moveAnimation:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:sendBtn]; }

-(void)moveAnimation:(UIButton *)sender{ CABasicAnimation *transformAnima = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"]; // transformAnima.fromValue = @(M_PI_2); transformAnima.toValue = [NSNumber numberWithFloat: M_PI]; transformAnima.duration = 0.5; transformAnima.cumulative = YES; transformAnima.autoreverses = NO; transformAnima.repeatCount = HUGE_VALF; transformAnima.fillMode = kCAFillModeForwards; transformAnima.removedOnCompletion = NO; transformAnima.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; sender.layer.zPosition = 5; sender.layer.zPosition = sender.layer.frame.size.width/2.f; [sender.layer addAnimation:transformAnima forKey:@"rotationAnimationY"]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [sender removeFromSuperview]; UIBezierPath *newPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(20, 80, screenW-40, screenH-620) byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight) cornerRadii:CGSizeMake(4, 4)]; CGPoint startPoint = CGPointMake(20, screenH-540); CGPoint endPoint = CGPointMake(screenW-20, screenH-540); CGPoint controlPoint = CGPointMake(screenW*0.5, screenH-480); //曲线起点 [newPath moveToPoint:startPoint]; //曲线终点和控制基点 [newPath addQuadCurveToPoint:endPoint controlPoint:controlPoint]; CGRect newFrame = CGRectMake(20, 80, screenW-40, screenH-620); CABasicAnimation* pathAnim = [CABasicAnimation animationWithKeyPath: @"path"]; pathAnim.toValue = (id)newPath.CGPath; CABasicAnimation* boundsAnim = [CABasicAnimation animationWithKeyPath: @"frame"]; boundsAnim.toValue = [NSValue valueWithCGRect:newFrame]; CAAnimationGroup *anims = [CAAnimationGroup animation]; anims.animations = [NSArray arrayWithObjects:pathAnim, boundsAnim, nil]; anims.removedOnCompletion = NO; anims.duration = 0.1f; anims.fillMode = kCAFillModeForwards; [self.lineLayer addAnimation:anims forKey:nil]; }); }

相关文章

  • 红包动画

    - (void)wxRedPacket{ //深色背景 CAShapeLayer *redLayer ...

  • iOS红包雨实现总结

    1、生成一个红包layer 2、添加layer的动画 3、定时生成红包 4、判断红包点击事件 5、停止红包雨 代码...

  • Android红包雨动画

    关于实现上面红包雨效果步骤如下: 1.创建一个红包实体类 上面就红包实体类的源码,重点就是在创建红包实体的时候,初...

  • iOS系统动画突然丢失

    背景:在做微信红包打开动画的场合使用了如下动画: NSTimeInterval duration = 0.5; U...

  • 属性动画之旋转——小红包动画

    本文主要内容:属性动画实现红包左右摇摆动画。 1.1 介绍 先来看看具体动画的表现形式: 需求是希望这个动画播放三...

  • 圆角动画实现小细节

    最近项目中有一个开红包的动画需要实现,具体为:开红包时,上下两部分打开的动画。本来觉得没什么难度,但是实现的时候发...

  • 动画| 金币抛入红包动画详解

    前言 这个动画效果很早就出来了,也是一个比较经典的关键帧动画和组合动画的运用,通过剖析源码,可以发现实际上这个酷炫...

  • Android 红包雨效果自定义控件

    思路:利用Path绘制动画轨迹,再使用PathMeasure获取轨迹中的坐标位置实时改变view的坐标完成红包动画...

  • 微博红包加载动画

    新浪微博的红包加载动画,过年在家里抢红包看到这个效果,就顺手仿照着写了一下。主要还是利用余弦函数曲线的特性实现的。...

  • 核心动画 - 红包雨

    新建一个 xcode 项目,然后在 ViewController.m 编写代码实现效果。 ViewControll...

网友评论

      本文标题:红包动画

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