使用CAEmitterLayer,@ 2x(视网膜)图像不像iOS中的其他地方那样具有缩放属性。我得到的结果是@ 2x版本的显示尺寸是非视网膜图像的4倍,而不是按比例缩小。
知道怎么解决这个问题吗?我已经尝试在UIImageView中测试图像疼痛,结果是应该的,所以这似乎是CAEmitterLayer和CAEmitterCell的问题。图像具有正确的@ 2x.png说明符。
以下是我使用的代码:
CAEmitterLayer *fallingCoinEmitter = [CAEmitterLayer layer];
fallingCoinEmitter.emitterPosition = CGPointMake(self.view.bounds.size.width / 2.0, -30);
fallingCoinEmitter.emitterSize = CGSizeMake(self.view.bounds.size.width * 2.0, 0.0);;
// Spawn points for the flakes are within on the outline of the line
fallingCoinEmitter.emitterMode = kCAEmitterLayerOutline;
fallingCoinEmitter.emitterShape = kCAEmitterLayerLine;
// Configure the snowflake emitter cell
CAEmitterCell *coin = [CAEmitterCell emitterCell];
coin.birthRate = 8.0;
coin.lifetime = 5.0;
coin.velocity = -180; // falling down slowly
coin.velocityRange = 80;
coin.yAcceleration = 40;
coin.emissionRange = 0.4 * M_PI; // some variation in angle
coin.spinRange = 0.45 * M_PI; // slow spin
coin.contents = (id) [[UIImage imageNamed:@"Coin_Generic_Emitter"] CGImage];
coin.scale = 1.0;
coin.scaleRange = 0.0;
// Make the flakes seem inset in the background
fallingCoinEmitter.shadowOpacity = 1.0;
fallingCoinEmitter.shadowRadius = 4.0;
fallingCoinEmitter.shadowOffset = CGSizeMake(0.0, 3.0);
UIColor *darkGreenColor = [UIColor colorWithRed:0.005 green:0.163 blue:0.005 alpha:1.000];
fallingCoinEmitter.shadowColor = [darkGreenColor CGColor];
[fallingCoinEmitter setContentsScale:[UIScreen mainScreen].scale];
//fallingCoinEmitter.shouldRasterize = YES;
//[fallingCoinEmitter setRasterizationScale:[UIScreen mainScreen].scale];
//fallingCoinEmitter.scale = fallingCoinEmitter.scale / [[UIScreen mainScreen] scale];
// Add everything to our backing layer below the UIContol defined in the storyboard
fallingCoinEmitter.emitterCells = [NSArray arrayWithObject:coin];
[self.view.layer insertSublayer:fallingCoinEmitter atIndex:0];
谢谢!
更新
@Fabian,设置contentScale不起作用,至少不是我的解决方案
[fallingCoinEmitter setContentsScale:[UIScreen mainScreen].scale];
我也尝试了这个没有结果..
emitter.shouldRasterize = YES;
[emitter setRasterizationScale:[UIScreen mainScreen].scale];
设置比例范围不起作用。 iPad 2和3(w RD)的尺寸之间仍有差异。
答案 0 :(得分:6)
您应该尝试修改CAEmmitterCell
s scale
和scaleRange
属性,具体取决于设备的屏幕。
cell.scale = cell.scale / [[UIScreen mainScreen] scale];