CAEmitterCell with 3D rotation

徘徊边缘 提交于 2020-01-30 08:11:26

问题


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

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

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

This is what I got:

-(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];
}

回答1:


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 confetti example



来源:https://stackoverflow.com/questions/29272216/caemittercell-with-3d-rotation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!