美文网首页
核心动画 - 红包雨

核心动画 - 红包雨

作者: 君幸食j | 来源:发表于2020-09-19 20:54 被阅读0次

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

ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    //1. 设置CAEmitterLayer
    CAEmitterLayer * emitterLayer = [CAEmitterLayer layer];
    
    //2.在背景图上添加粒子图层
    [self.view.layer addSublayer:emitterLayer];
    
    //3.发射形状--线性
    emitterLayer.emitterShape = kCAEmitterLayerLine;
    emitterLayer.emitterMode = kCAEmitterLayerSurface;
    emitterLayer.emitterSize = self.view.frame.size;
    emitterLayer.emitterPosition = CGPointMake(self.view.frame.size.width * 0.5, -10);
    
    //2. 配置cell
    CAEmitterCell * emitterCell = [CAEmitterCell emitterCell];
    emitterCell.contents = (id)[UIImage imageNamed:@"hongbao"].CGImage;
    emitterCell.birthRate = 1.0f;
    emitterCell.lifetime = 30.0f;
    emitterCell.speed = 2.0f;
    emitterCell.velocity = 10.0f;
    emitterCell.velocityRange = 10.0f;
    emitterCell.yAcceleration = 60.0f;
    emitterCell.scale = 0.05f;
    emitterCell.scaleRange = 0.0f;
    
    emitterLayer.emitterCells = @[emitterCell];
}


@end

运行效果如下:

红包雨.png

相关文章

  • 核心动画 - 红包雨

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

  • Android红包雨动画

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

  • iOS红包雨实现总结

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

  • 红包动画

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

  • IOS 核心动画CoreAniamation总结

    iOS 核心动画是基于CALayer层的动画,UIView动画是系统对核心动画的封装,核心动画相对UIView来说...

  • iOS基础 - 核心动画(转)

    iOS基础 - 核心动画 一、核心动画 l核心动画基本概念 l基本动画 l关键帧动画 l动画组 l转场动画 lCo...

  • iOS核心动画高级技巧 - 8

    iOS核心动画高级技巧 - 1iOS核心动画高级技巧 - 2iOS核心动画高级技巧 - 3iOS核心动画高级技巧 ...

  • iOS动画(Core Animation)

    1.核心动画(Core Animation):强大的动画API 核心动画所在的位置如下图 核心动画位于UIKit的...

  • IOS 常用动画的实现方式整理

    一、CoreAnimation(核心动画) 1.核心动画介绍 1.什么是核心动画 Core Animation可以...

  • UIview动画和核心动画的区别

    UIView和核心动画的区别 核心动画只能添加到CALayer,UIView没有办法使用核心动画 核心动画一切都是...

网友评论

      本文标题:核心动画 - 红包雨

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