Rya*_*n F 20 core-animation objective-c ios caemitterlayer ios7
奇怪的问题我似乎无法解决iOS 7只在哪里,CAEmitterLayer当出生率最初设置为非零值时,将错误地在屏幕上产生粒子.就像它计算未来该层的状态一样.
// Create black image particle
CGRect rect = CGRectMake(0, 0, 20, 20);
UIGraphicsBeginImageContext(rect.size);
CGContextFillRect(UIGraphicsGetCurrentContext(), rect);
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Create cell
CAEmitterCell *cell = [CAEmitterCell emitterCell];
cell.contents = (__bridge id)img.CGImage;
cell.birthRate = 100.0;
cell.lifetime = 10.0;
cell.velocity = 100.0;
// Create emitter with particles emitting from a line on the
// bottom of the screen
CAEmitterLayer *emitter = [CAEmitterLayer layer];
emitter.emitterShape = kCAEmitterLayerLine;
emitter.emitterSize = CGSizeMake(self.view.bounds.size.width,0);
emitter.emitterPosition = CGPointMake(self.view.bounds.size.width/2,
self.view.bounds.size.height);
emitter.emitterCells = @[cell];
[self.view.layer addSublayer:emitter];
Run Code Online (Sandbox Code Playgroud)
我在DevForums看到一个帖子里有几个人提到他们有类似的问题iOS 7和CAEmitterLayer,但没有人有任何想法如何解决它.现在iOS 7不再是测试版了,我想我应该在这里问一下,看看是否有人可以破解它.我真的希望这不仅仅是我们必须等待7.0.1或7.1修复的错误.任何想法将不胜感激.谢谢!
jac*_*ash 36
是!
我自己花了几个小时研究这个问题.
为了获得birthRate我们之前使用的几种策略的相同类型的动画.
首先,如果您希望图层看起来像添加到视图时开始发射,则需要记住它CAEmitterLayer是CALayer符合CAMediaTiming协议的子类.我们必须将整个发射器层设置为在当前时刻开始:
emitter.beginTime = CACurrentMediaTime();
[self.view.layer addSublayer:emitter];
Run Code Online (Sandbox Code Playgroud)
就像它计算未来该层的状态一样.
你是非常接近,但实际上它是发射器在过去开始.
其次,在0和n的出生率之间进行动画制作,以及我们之前可以操作生命属性的效果:
if (shouldBeEmitting){
emitter.lifetime = 1.0;
}
else{
emitter.lifetime = 0;
}
Run Code Online (Sandbox Code Playgroud)
请注意,我lifetime在发射器层上设置了它.这是因为当发射发射器单元时,此属性的版本乘以发射器层中的值.设置lifetime发射器层设置lifetime所有发射器单元的s的多个,允许您轻松地打开和关闭它们.
| 归档时间: |
|
| 查看次数: |
3268 次 |
| 最近记录: |