【问题标题】:Setting retina background images appear zoomed in设置视网膜背景图像放大显示
【发布时间】:2013-09-23 08:40:13
【问题描述】:

我正在通过加载图像并将其添加到我的视图中为我的应用设置随机背景图像:

UIImageView *background = [[UIImageView alloc] 
                               initWithImage:[UIImage imageNamed:
                               [NSString stringWithFormat:@"bg%u.jpg", 1+arc4random_uniform(15)]]];
    [self.view addSubview:background];
    [self.view sendSubviewToBack:background];

我的图像是 640x1136 分辨率为 326 ppi,但由于某种原因,图像显示为放大了。任何关于为什么的想法都会受到赞赏。

模拟器

实际图片:

谢谢。

【问题讨论】:

  • 尝试使用 png 文件。可能是转换问题
  • @Nick background.frame = self.view.frame;然后添加子视图:
  • 不幸的是,@b3ginneriOS 转换为 png 似乎根本不起作用。
  • @Spynet 这工作得很好。谢谢!你能把它添加为答案吗?我会接受的。
  • @Nick 欢迎继续提问

标签: iphone ios objective-c ios7


【解决方案1】:

这是因为您使用图像分配 init,而不是固定大小。

int screenHeight = [UIScreen mainScreen].bounds.size.height;
int screenWidth = [UIScreen mainScreen].bounds.size.width;


UIImageView *background = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight)];

background.image = [UIImage imageNamed:[NSString stringWithFormat:@"bg%u.jpg",1+arc4random_uniform(15)]]

[self.view addSubview:background];
[self.view sendSubviewToBack:background];

这样做

【讨论】:

  • 什么是 screenWidth 和 screenHeight ?
  • 基于您对下采样正确的假设更改了对此的答案,尽管图像在 iphone 屏幕上看起来相同(可能太小而无法看到)。它在您的编辑后工作。谢谢。
  • 这个答案不是我的,而且这个解决方案与 spynet 的解决方案没有任何不同!事实上,我认为我可能错了(我正在测试几件事)
  • 我根本看不到你的解决方案,只是 cmets 没有一个是正确的。
【解决方案2】:

你好,试试这样,

UIImageView *background = [[UIImageView alloc] 
                               initWithImage:[UIImage imageNamed:
                               [NSString stringWithFormat:@"bg%u.jpg", 1+arc4random_uniform(15)]]];

    background.frame = self.view.frame; // this is the only line you have missed 
    [self.view addSubview:background];
    [self.view sendSubviewToBack:background];

【讨论】:

  • 这不是正确的解决方案。图像将被下采样,看起来就像在非视网膜手机上的样子。
  • 我正在 iPhone5 上进行测试,图像显示为高分辨率,有什么想法吗?
  • 我不知道下采样(或 Spynet 代码不好),但我知道,我的答案是正确的。
  • @micantox 什么是下采样?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-04-15
  • 1970-01-01
  • 1970-01-01
  • 2012-11-07
  • 1970-01-01
  • 1970-01-01
  • 2014-07-27
相关资源
最近更新 更多