Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios CAEmitterLayer:使用带有CAEmitterCell的@2x(视网膜)png图像_Ios_Xcode_Calayer_Caemitterlayer_Caemittercell - Fatal编程技术网

Ios CAEmitterLayer:使用带有CAEmitterCell的@2x(视网膜)png图像

Ios CAEmitterLayer:使用带有CAEmitterCell的@2x(视网膜)png图像,ios,xcode,calayer,caemitterlayer,caemittercell,Ios,Xcode,Calayer,Caemitterlayer,Caemittercell,使用CAEmitterLayer,@2x(视网膜)图像不会像iOS中其他地方那样进行缩放。我得到的结果是@2x版本显示为非视网膜图像大小的4倍,而不是缩小 你知道怎么解决这个问题吗?我曾尝试在UIImageView中测试图像疼痛,结果与预期一致,因此这似乎是CAEmitterLayer和CAEmitterCell的问题。图像具有正确的@2x.png说明符 以下是我使用的代码: CAEmitterLayer *fallingCoinEmitter = [CAEmitterLayer layer];

使用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];

设置和比例范围不起作用。iPad2和iPad3(w-RD)上的尺寸仍然存在差异。

您应该尝试根据设备屏幕修改您的
CAEmmitterCell
s
scale
scalerage
属性


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

我确信这会奏效。。。如果您只是更改emmitter细胞的初始比例和比例范围会怎么样?也尝试过了,请参见上文。您可以在设置比例和比例范围的位置添加代码吗?您需要在视网膜设备上将细胞的比例设置为0.5。我会尝试。我想知道,是否有一个“合适的”解决方案,而不是每次都破解它。好吧,这是一个合适的解决方案。核心动画不知道也不关心屏幕的点到像素比例<代码>内容缩放
只需确保图层内容(图像)的缩放正确即可。当您使用
CAEmmitterLayer
时,您必须自己缩放emmitted单元格,因为emmitter单元格不关心其内容是否应缩放。这并不意味着降低您的答案。我简直不敢相信苹果会为UIImageView这样的东西添加视网膜支持,而不支持其他东西。正如我所说,核心动画对缩放一无所知。阅读有关
contentsScale
属性的文档:文档中说,对于附着到视图的图层,将自动设置
contentsScale
,但是对于您创建的图层,您负责设置它
CAEmmitterLayer
是例外,因为@2x图像是
CAEmmitterCell
的一部分,
CAEmmitterLayer
使用抽象对象渲染粒子。我希望你明白我的意思。顺便说一句,设置
比例
有效吗?