gpt4 book ai didi

ios - 在 CAEmitterLayer 中悬浮粒子

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:18:28 26 4
gpt4 key购买 nike

我有以下代码,将粒子添加到位于其他一些 UIView 中心的名为 ParentViewUIView:

CAEmitterLayer *emitterLayer = [CAEmitterLayer layer];
emitterLayer.emitterPosition = CGPointMake(view.center.x, view.center.y - view.frame.size.height / 3);
emitterLayer.emitterZPosition = 10;
emitterLayer.emitterSize = CGSizeMake(view.bounds.size.width, 0);
emitterLayer.emitterShape = kCAEmitterLayerSphere;

CAEmitterCell *emitterCell = [CAEmitterCell emitterCell];
emitterCell.scale = 0.1;
emitterCell.scaleRange = 0.2;
emitterCell.emissionRange = 45;
emitterCell.lifetime = 0.75;
emitterCell.birthRate = 60;
emitterCell.velocity = 200;
emitterCell.velocityRange = 50;
emitterCell.yAcceleration = 250;
emitterCell.contents = (id)[[UIImage imageNamed:@"particle.png"] CGImage];

emitterLayer.emitterCells = [NSArray arrayWithObject:emitterCell];
[parentView.layer addSublayer:emitterLayer];

一切正常,但现在我想暂停或暂停动画,所以粒子“卡住”。这能做到吗?

最佳答案

我认为暂停图层会起作用,

-(void)pauseLayer:(CALayer*)layer
{
CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil];
layer.speed = 0.0;
layer.timeOffset = pausedTime;
}

关于ios - 在 CAEmitterLayer 中悬浮粒子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22883494/

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