gpt4 book ai didi

ios - 具有 3D 旋转功能的 CAEmitterCell

转载 作者:行者123 更新时间:2023-11-29 05:22:43 27 4
gpt4 key购买 nike

我正在尝试使用 CAEmitterLayer 和 CAEmitterCell 重现从顶部掉落的小纸片效果。

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

如何对每个粒子应用随机旋转?我尝试过 3D Transform,到目前为止没有成功。

这就是我得到的:

animation gif

-(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 附加到各个对象以实现所需的效果。

iOS confetti example

关于ios - 具有 3D 旋转功能的 CAEmitterCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58511718/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com