粒子动画

<li><a href = "http://weibo.com/u/2807556803/home?wvr=5">占位符</a><li>

   //1. 创建发射器
        let emitter = CAEmitterLayer()
        //2. 位置
        emitter.emitterPosition = CGPoint(x: view.bounds.width * 0.5, y: view.bounds.height - 20)
        //3. 开启三维效果
        emitter.preservesDepth = true
        
        //4.1 创建例子
        let cell = CAEmitterCell()
        
        //4.2 设置例子速度
        cell.velocity = 150
        cell.velocityRange = 100  //速度范围 50 -- 250
        
        //4.3 设置例子大小
        cell.scale = 0.7
        cell.spinRange = 0.3  // 0.4 -- 1.0
        
        //4.4 设置例子方向
//        cell.emissionLatitude                         //维度     水平方向
        cell.emissionLongitude = CGFloat(-M_PI_2)       //经度     垂直方向
        cell.emissionRange = CGFloat(M_PI_2/6)          // 左右偏移15度
        
        //4.5 设置例子存活时间
        cell.lifetime = 3
        cell.lifetimeRange = 1.5  //1.5--4.5
        
        
        //4.6 设置例子的旋转
        cell.spin = CGFloat(M_PI_2)  //每秒中旋转M_PI_2度
        cell.spinRange = CGFloat(M_PI_2 / 2)
        
        //4.7 设置例子每秒弹出的个数
        cell.birthRate = 10
        
        //4.8 设置例子展示的图片
        cell.contents = UIImage(named: "")?.cgImage
        
        //5. 将例子加入发射器
        emitter.emitterCells = [cell]
        
        //6. 发射器加入父layer
        view.layer.addSublayer(emitter)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容