ios – 当它结束CAEmitterLayer的CAEmitter单元格的生命周期时如何删除CAEmitterLayer – 而不是重复直到从超级图层中删除它

ios – 当它结束CAEmitterLayer的CAEmitter单元格的生命周期时如何删除CAEmitterLayer – 而不是重复直到从超级图层中删除它,第1张

概述我正在以略微改变的方式使用通用代码(来自iOS Fireworks演示).我在UIView的子类中有以下内容.我想要的是让烟花出现在用户触摸的位置(不是很难),并播出CAEmitterLayer / CAEmitterCells’生命周期’的长度.相反,当我将它添加到addSublayer时,这会立即开始 – 就像我确定它的意思.但是,我想以稍微不同的方式使用它.有没有办法可以改变这个,所以有一个 我正在以略微改变的方式使用通用代码(来自iOS Fireworks演示).我在UIVIEw的子类中有以下内容.我想要的是让烟花出现在用户触摸的位置(不是很难),并播出CAEmitterLayer / CAEmitterCells’生命周期’的长度.相反,当我将它添加到addSublayer时,这会立即开始 – 就像我确定它的意思.但是,我想以稍微不同的方式使用它.有没有办法可以改变这个,所以有一个带有完成块的CATransaction(要删除.FromSuperlayer)或类似的东西?欢迎任何想法.

#import "FireworksVIEw.h"    @implementation FireworksVIEw - (voID)launchFirework{    //Load the spark image for the particle    CAEmitterLayer *mortor = [CAEmitterLayer layer];    mortor.emitterposition = CGPointMake(self.bounds.size.wIDth/2,self.bounds.size.height*(.75));    mortor.renderMode = kCAEmitterLayerAdditive;    //Invisible particle representing the rocket before the explosion    CAEmitterCell *rocket = [CAEmitterCell emitterCell];    rocket.emissionLongitude = -M_PI / 2;    rocket.emissionLatitude = 0;    rocket.lifetime = 1.6;    rocket.birthRate = 1;    rocket.veLocity = 400;    rocket.veLocityRange = 100;    rocket.yacceleration = 250;    rocket.emissionRange = M_PI / 4;    rocket.color = CGcolorCreatecopy([UIcolor colorWithRed:.5 green:.5 blue:.5 Alpha:.5].CGcolor);    rocket.redRange = 0.5;    rocket.greenRange = 0.5;    rocket.blueRange = 0.5;    //name the cell so that it can be animated later using keypath    [rocket setname:@"rocket"];    //Flare particles emitted from the rocket as it flys    CAEmitterCell *flare = [CAEmitterCell emitterCell];    flare.contents = (ID)[UIImage imagenamed:@"tspark.png"].CGImage;    flare.emissionLongitude = (4 * M_PI) / 2;    flare.scale = 0.4;    flare.veLocity = 100;    flare.birthRate = 45;    flare.lifetime = 1.5;    flare.yacceleration = 350;    flare.emissionRange = M_PI / 7;    flare.AlphaSpeed = -0.7;    flare.scaleSpeed = -0.1;    flare.scaleRange = 0.1;    flare.beginTime = 0.01;    flare.duration = 0.7;    //The particles that make up the explosion    CAEmitterCell *firework = [CAEmitterCell emitterCell];    firework.contents = (ID)[UIImage imagenamed:@"tspark.png"].CGImage;    firework.birthRate = 9999;    firework.scale = 0.6;    firework.veLocity = 130;    firework.lifetime = 2;    firework.AlphaSpeed = -0.2;    firework.yacceleration = 80;    firework.beginTime = 1.5;    firework.duration = 0.1;    firework.emissionRange = 2 * M_PI;    firework.scaleSpeed = -0.1;    firework.spin = 2;    //name the cell so that it can be animated later using keypath    [firework setname:@"firework"];    //preSpark is an invisible particle used to later emit the spark    CAEmitterCell *preSpark = [CAEmitterCell emitterCell];    preSpark.birthRate = 80;    preSpark.veLocity = firework.veLocity * 0.70;    preSpark.lifetime = 1.7;    preSpark.yacceleration = firework.yacceleration * 0.85;    preSpark.beginTime = firework.beginTime - 0.2;    preSpark.emissionRange = firework.emissionRange;    preSpark.greenSpeed = 100;    preSpark.blueSpeed = 100;    preSpark.redSpeed = 100;    //name the cell so that it can be animated later using keypath    [preSpark setname:@"preSpark"];    //The 'sparkle' at the end of a firework    CAEmitterCell *spark = [CAEmitterCell emitterCell];    spark.contents = (ID)[UIImage imagenamed:@"tspark.png"].CGImage;    spark.lifetime = 0.05;    spark.yacceleration = 250;    spark.beginTime = 0.8;    spark.scale = 0.4;    spark.birthRate = 10;    preSpark.emitterCells = [NSArray arrayWithObjects:spark,nil];    rocket.emitterCells = [NSArray arrayWithObjects:flare,firework,preSpark,nil];    mortor.emitterCells = [NSArray arrayWithObjects:rocket,nil];    [self.layer addSublayer:mortor];        }
解决方法 答案是,使用CAEmitter,没有WAY – 委托等 – 在结束循环时停止发射器.当你认为应该删除它时,你唯一能做的就是优雅地将它从图层中移除. 总结

以上是内存溢出为你收集整理的ios – 当它结束CAEmitterLayer的CAEmitter单元格的生命周期时如何删除CAEmitterLayer – 而不是重复直到从超级图层中删除它全部内容,希望文章能够帮你解决ios – 当它结束CAEmitterLayer的CAEmitter单元格的生命周期时如何删除CAEmitterLayer – 而不是重复直到从超级图层中删除它所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1037301.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存