加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Swift——粒子效果

发布时间:2020-12-14 06:18:43 所属栏目:百科 来源:网络整理
导读:// 1、创建发射器 let emitterLayer=CAEmitterLayer() //2、设置位置 emitterLayer.emitterPosition=CGPoint(x: view.bounds.width*0.5,y: -200); //3、开启三维效果 emitterLayer.preservesDepth=true //4、设置 cell:对应一个粒子 //4.1创建粒子 let cell=
// 1、创建发射器
        let emitterLayer=CAEmitterLayer()
        
        //2、设置位置 
        emitterLayer.emitterPosition=CGPoint(x: view.bounds.width*0.5,y: -200);
        
        //3、开启三维效果
        emitterLayer.preservesDepth=true
        
        //4、设置 cell:对应一个粒子
        //4.1创建粒子
        let cell=CAEmitterCell()
        //4.2 设置每秒发出多少个粒子
        cell.birthRate=20
        
        //4.3设置粒子存活时间 
        cell.lifetime=5
        cell.lifetimeRange=1.5
        
        //4.4设置绽放比例
        cell.scale=0.7
        cell.scaleRange=0.2
        
        //4.5 设置粒子的方向 
        cell.emissionLongitude=CGFloat(M_PI_2)
        cell.emissionRange=CGFloat(M_PI_2 / 2)
        
        //4 .6 设置粒子的速度
        cell.velocity=150
        cell.velocityRange=100
        
        cell.spin=CGFloat(M_PI_2)
        
        //4.7 设置粒子的内容
        cell.contents=UIImage(named: "good9_30x30_")?.cgImage
        
        //4.8 将粒子设置到发射器中
        emitterLayer.emitterCells=[cell]
        
        // 5、将layer 添加到父layer 中
        view.layer.addSublayer(emitterLayer)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读