ios -- 如何限制 CAEmitter 粒子轨迹的范围?
Posted
技术标签:
【中文标题】ios -- 如何限制 CAEmitter 粒子轨迹的范围?【英文标题】:ios -- How to limit extent of CAEmitter particle trajectories? 【发布时间】:2014-01-24 07:59:06 【问题描述】:我成功地将 CAEmitter 添加到子视图内的 UIView 中,但该层发出的粒子延伸到该视图之外。请参阅下面的代码以获取 cookiecutter 代码和参数。我的问题是如何防止生成的粒子退出父视图?
我尝试过使用特定框架初始化子视图,甚至调整边界大小。在这两种情况下,发射的粒子都在边界内开始,但在视图框架之外飞行,似乎没有边界。在我限制生命周期之前,它们不会消失,或者直到它们到达屏幕的尽头。有没有办法防止发射器与视图外的对象进行交互?
CAEmitterLayer *emitterLayer = (CAEmitterLayer*)self.layer;
emitterLayer.name = @"emitterLayer";
emitterLayer.emitterPosition = CGPointMake(self.frame.size.width/2, 0);
emitterLayer.emitterZPosition = 0;
emitterLayer.emitterSize = CGSizeMake(1.00, 1.00);
emitterLayer.emitterDepth = 0.00;
emitterLayer.emitterShape = kCAEmitterLayerCuboid;
emitterLayer.renderMode = kCAEmitterLayerAdditive;
emitterLayer.seed = 3534563912;
// Create the emitter Cell
CAEmitterCell *emitterCell = [CAEmitterCell emitterCell];
emitterCell.name = @"StatSap";
emitterCell.enabled = YES;
emitterCell.contents = (id)[[UIImage imageNamed:@"mysprite.png"] CGImage];
emitterCell.contentsRect = CGRectMake(0.00, 0.00, 1.00, 1.00);
emitterCell.magnificationFilter = kCAFilterTrilinear;
emitterCell.minificationFilter = kCAFilterLinear;
emitterCell.minificationFilterBias = 0.00;
emitterCell.scale = 1.00;
emitterCell.scaleRange = 0.00;
emitterCell.scaleSpeed = -0.24;
emitterCell.color = [[UIColor colorWithRed:1.00 green:0.28 blue:0.26 alpha:1.00] CGColor];
emitterCell.redRange = 1.00;
emitterCell.greenRange = 0.34;
emitterCell.blueRange = 0.31;
emitterCell.alphaRange = 0.46;
emitterCell.redSpeed = 2.03;
emitterCell.greenSpeed = 0.00;
emitterCell.blueSpeed = 0.00;
emitterCell.alphaSpeed = 0.00;
emitterCell.lifetime = 2.65;
emitterCell.lifetimeRange = 1.02;
emitterCell.birthRate = 267;
emitterCell.velocity = 155.32;
emitterCell.velocityRange = 25.00;
emitterCell.xAcceleration = 0.00;
emitterCell.yAcceleration = 911.00;
emitterCell.zAcceleration = 0.00;
// these values are in radians, in the UI they are in degrees
emitterCell.spin = -0.175;
emitterCell.spinRange = 12.566;
emitterCell.emissionLatitude = 0.000;
emitterCell.emissionLongitude = 0.000;
emitterCell.emissionRange = 6.283;
emitterLayer.emitterCells = @[emitterCell];
【问题讨论】:
【参考方案1】:你确定发射器的superview有clipsToBounds = YES
吗?
【讨论】:
joshd,感谢您的建议。如果我将发射器层包装在它自己的 UIView 中并将 UIView clipsToBounds 设置为 YES,它就可以工作。不想在其父视图上更进一步,因为它还会剪切图像和其他子视图。 优秀。是的,我的意思是超级查看发射器(即 UIView)。感谢您的检查!以上是关于ios -- 如何限制 CAEmitter 粒子轨迹的范围?的主要内容,如果未能解决你的问题,请参考以下文章