【问题标题】:Why my whole image is not displayed while running app in iphone (Retina 4 inch)为什么在 iphone (Retina 4 英寸) 中运行应用程序时不显示我的整个图像
【发布时间】:2013-09-16 18:05:54
【问题描述】:

我将视图背景设置如下:

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:
@"backgr.png"]];

当我在 iphone 4(Retina 3.5-inch) 中运行它时它工作正常。 但是当我在 iphone 5(Retina 4-inch) 图像中运行它时未正确设置或显示。图像看起来像 4 倍放大/ 炸了。

编辑

 I have two different images for iphone 4(640x960) and 5(640x1136).

 What is the problem here? Is it scaling problem or another problem?
 Please guide me on this.

【问题讨论】:

    标签: iphone background-image retina-display iphone-5


    【解决方案1】:

    您需要为 iPhone 4 和 iPhone 5 使用两个不同的图像。因为这两个设备的分辨率不同。你需要像这样检查。

    if ([UIScreen mainScreen].bounds.size.height == 568)
        {
            // ------- iPhone 5
        }
        else
        {
            // ---------- iPhone 4
        }
    

    【讨论】:

    • iPhone 5 屏幕高度为 568 的朋友。
    • 请查看我更新的问题。我已经为 iphone 4 和 5 使用了两个不同的图像。
    • Ponting,你的项目中有@2x 图像吗?
    • @DharmbirChoudhary :最好你看看这个问题并这样回答你会知道天气我是一个iphone开发者或者你是stackoverflow.com/q/12446990/2695503
    • @eptdeveloper 我知道亲爱的,但我正在检查大于或等于 548。所以我认为它不应该是错误的。但如果你愿意,我可以做到。但在我看来它并没有错..
    【解决方案2】:

    两个显示器的分辨率不同,因此您需要设置条件并相应地为 iPhone 5(4 英寸视网膜)显示器设置更高分辨率的新图像。

    那个条件你可以像

    if ((int)[[UIScreen mainScreen] bounds].size.height == 568)
    {
        // This is iPhone 5 screen
        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"backgr_iPhone5.png"]];
    } else {
        // This is iPhone 4 screen
        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"backgr.png"]];
    }
    

    【讨论】:

      【解决方案3】:

      这里有一些可以很方便的东西:

      #define IS_PHONEPOD5() ([UIScreen mainScreen].bounds.size.height == 568.0f && 
      [UIScreen mainScreen].scale == 2.f &&
       UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
      

      - (void)viewDidLoad
      {
          [super viewDidLoad];
      
              if(IS_PHONEPOD5())
              {
                      self.imageView.image = [UIImage imageNamed:@"image-568h@2x"];
              }
              else
              {
                      self.imageView.image = [UIImage imageNamed:@"image"];
              }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-10-25
        • 1970-01-01
        • 1970-01-01
        • 2012-09-12
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多