我能想到的唯一方法是使用核心动画分别为每个粒子制作动画,但这样既低效又耗时.
有没有其他方法可以做同样的事情?解决方法 以下是Erica Susan的烹饪书中的解决方案.看到这个适合你.
You can add visual interest to your interfaces by using emitters in tandem with user touches. The following class demonstrates how to follow a touch over its lifetime,adding a little sparkle to wherever the user touches on-screen.
The class begins as soon as the user touches the screen,creating an emitter layer and a single emitter cell. The cell defines the particles — their color,their birth rate,their lifetime,veLocity,and so forth.
As the user’s touch progresses,this class updates the emitter’s location,removing the emitter once the touch is removed from the screen. Although this example is written for single touch interaction,you can easily update the code to add an array of emitters (rather than a single instance) for multi-touch interaction.
Emitters are easily added to your projects and efficIEnt to run. While too much animation is never a good design IDea,a little sparkle used judicIoUsly can add life and movement.
@interface sparkletouchVIEw : UIVIEw { CAEmitterLayer *emitter;}@end@implementation sparkletouchVIEw- (voID) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { float multiplIEr = 0.25f; CGPoint pt = [[touches anyObject] locationInVIEw:self]; //Create the emitter layer emitter = [CAEmitterLayer layer]; emitter.emitterposition = pt; emitter.emitterMode = kCAEmitterLayerOutline; emitter.emitterShape = kCAEmitterLayerCircle; emitter.renderMode = kCAEmitterLayerAdditive; emitter.emitterSize = CGSizeMake(100 * multiplIEr,0); //Create the emitter cell CAEmitterCell* particle = [CAEmitterCell emitterCell]; particle.emissionLongitude = M_PI; particle.birthRate = multiplIEr * 1000.0; particle.lifetime = multiplIEr; particle.lifetimeRange = multiplIEr * 0.35; particle.veLocity = 180; particle.veLocityRange = 130; particle.emissionRange = 1.1; particle.scaleSpeed = 1.0; // was 0.3 particle.color = [[COOKBOOK_PURPLE_color colorWithAlphaComponent:0.5f] CGcolor]; particle.contents = (__brIDge ID)([UIImage imagenamed:@"spark.png"].CGImage); particle.name = @"particle"; emitter.emitterCells = [NSArray arrayWithObject:particle]; [self.layer addSublayer:emitter];}- (voID) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint pt = [[touches anyObject] locationInVIEw:self]; // disable implicit animations [CATransaction begin]; [CATransaction setValue:(ID)kcfBooleanTrue forKey:kCATransactiondisableActions]; emitter.emitterposition = pt; [CATransaction commit]; } - (voID) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { [emitter removeFromSuperlayer]; emitter = nil; }- (voID) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { [self touchesEnded:touches withEvent:event];}@end
不要忘记创建一个名为spark.png的png文件来创建动画.
总结以上是内存溢出为你收集整理的闪耀效果iOS全部内容,希望文章能够帮你解决闪耀效果iOS所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)