具有3D旋转的CAEmitterCell [英] CAEmitterCell with 3D rotation

查看:104
本文介绍了具有3D旋转的CAEmitterCell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用CAEmitterLayer& CAEmitterCell.

I'm trying to reproduce pieces of small paper falling from top effect, using CAEmitterLayer & CAEmitterCell.

到目前为止,我已经获得了它的2D动画,但是我很难使每个单元格在掉落时旋转.

So far, I got the 2D animation of it, But I'm having difficulty to make each cell to rotate when falling.

如何对每个粒子应用随机旋转?到目前为止,我尝试使用3D变换均未成功.

How to I apply random rotation on each particle? I tried with 3D Transform with no success so far.

这就是我得到的:

-(void) configureEmitterLayer {
    self.emitterLayer = [CAEmitterLayer layer];
    self.emitterLayer.emitterPosition =  CGPointMake(self.backgroundContainer.bounds.size.width /2, 0);
    self.emitterLayer.emitterZPosition = 10;
    self.emitterLayer.emitterSize = self.backgroundContainer.bounds.size;
    self.emitterLayer.emitterShape = kCAEmitterLayerLine;

    CAEmitterCell *emitterCell = [CAEmitterCell emitterCell];

    emitterCell.contents = (__bridge id)([UIImage imageWithColor:[UIColor whiteColor]].CGImage);

    emitterCell.lifetime = CGFLOAT_MAX;
    emitterCell.lifetimeRange = 4.0;
    emitterCell.birthRate = 2.5;

    emitterCell.color = [[UIColor colorWithRed:1.0f green:1.0 blue:1.0 alpha:1.0] CGColor];
    emitterCell.redRange = 1.0;
    emitterCell.blueRange = 1.0;
    emitterCell.greenRange = 1.0;
    emitterCell.alphaRange = 0.3;

    emitterCell.velocity = 10;
    emitterCell.velocityRange = 3;
    emitterCell.emissionRange = (CGFloat) M_PI_2;
    emitterCell.emissionLongitude = (CGFloat) M_PI;
    emitterCell.yAcceleration = 1;
    emitterCell.zAcceleration = 4;

    emitterCell.spinRange = 2.0;
    emitterCell.scale = 7.0;
    emitterCell.scaleRange = 4.0;

    self.emitterLayer.emitterCells = [NSArray arrayWithObject:emitterCell];

    [self.backgroundContainer.layer addSublayer:self.emitterLayer];
}

推荐答案

该库不使用发射器框架,但值得一试. UIDynamics附着在单个对象上以达到理想的效果.

This library doesn't use the emitter framework but is worth looking at for inspiration. UIDynamics is attached to individual objects to achieve the desired effect.

iOS五彩纸屑示例

这篇关于具有3D旋转的CAEmitterCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆