粒子动画

  • 占位符
  •    //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)
    
    
  • 你可能感兴趣的:(粒子动画)