1

我成功地将 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];
4

1 回答 1

4

你确定发射器的超级视图有clipsToBounds = YES吗?

于 2014-01-24T08:15:53.427 回答