ios – CAEmitterLayer:在CAEmitterCell中使用@ 2x(视网膜)png
发布时间:2020-12-14 17:50:22 所属栏目:百科 来源:网络整理
导读:使用CAEmitterLayer,@ 2x(视网膜)图像不像iOS中的其他地方那样具有缩放属性.我得到的结果是@ 2x版本的显示尺寸是非视网膜图像的4倍,而不是按比例缩小. 知道怎么解决这个问题吗?我已经尝试在UIImageView中测试图像疼痛,结果是应该的,所以这似乎是CAEmitterLa
使用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)的尺寸仍然存在差异. 解决方法
您应该尝试根据设备的屏幕修改CAEmmitterCells的scale和scaleRange属性.
cell.scale = cell.scale / [[UIScreen mainScreen] scale]; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |