首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CAEmitterLayer:在CAEmitterCell中使用@2x (视网膜) png图像

CAEmitterLayer:在CAEmitterCell中使用@2x (视网膜) png图像
EN

Stack Overflow用户
提问于 2013-02-02 00:40:25
回答 1查看 1.3K关注 0票数 5

使用CAEmitterLayer,@2x (视网膜)图像不会像iOS中的其他地方那样被缩放。我得到的结果是@2x版本是非视网膜图像的4倍大小,而不是缩小。

你知道怎么解决这个问题吗?我已经尝试过在UIImageView中测试图像痛点,结果和它们应该的一样,所以这似乎是CAEmitterLayer和CAEmitterCell的问题。图像具有正确的@2x.png说明符。

下面是我使用的代码:

代码语言:javascript
复制
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不起作用,至少不是我的解决方案

代码语言:javascript
复制
    [fallingCoinEmitter setContentsScale:[UIScreen mainScreen].scale];

我也试过了,但没有结果。

代码语言:javascript
复制
    emitter.shouldRasterize = YES;
    [emitter setRasterizationScale:[UIScreen mainScreen].scale];

并且设置比例范围不起作用。iPad 2和3的尺寸还是有区别的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-06 00:41:56

您应该尝试根据设备屏幕修改CAEmmitterCellscalescaleRange属性。

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

票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14650964

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档