6

使用 CAEmitterLayer,@2x (retina) 图像不会像在 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 和 iPad 3 (w RD) 的尺寸仍然存在差异。

4

1 回答 1

8

您应该尝试根据设备的屏幕修改您CAEmmitterCell的 s'scale和属性。scaleRange

cell.scale = cell.scale / [[UIScreen mainScreen] scale];

于 2013-02-05T16:41:55.963 回答