2013-03-26 98 views
0

我正在使用Xcode 4.5.2,該應用的目標是iOS 6.0。 在我的應用程序中,我無法顯示iPad Retina圖像。我知道我必須使用@ 2x〜ipad.png擴展名才能讓它們正確顯示,並且我這樣做。我的圖像被命名,因此除了每個設備的擴展名之外,它們的名稱都相同。 下面是我如何命名它。如何正確顯示@ 2x視網膜圖像

enter image description here

然而,

NSString *[email protected]"appearanceConnection.png"; 
//NSString *[email protected]"appearanceConnection"; //I did check this 
//I did check the target 
UIImage *image = [UIImage imageNamed:name]; 
NSLog(@"%f",image.size.width); 

顯示我的@ 1X圖像的寬度。

,如果我嘗試手動設置適當的圖像名稱:

if ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)] && 
      ([UIScreen mainScreen].scale == 2.0)) { 
      // Retina display 
      [email protected]"[email protected]~ipad.png"; 

      NSLog(@"retina"); 
     } 
     else 
     { 
      [email protected]"appearanceConnection.png"; 
      NSLog(@"non-retina"); 
     } 
    UIImage *image = [UIImage imageNamed:name]; 
    NSLog(@"%f",image.size.width); 

正確@ 2X挑選,然後通過2.0當我將它添加到瀏覽縮放。

我清理/重建我的項目多次,我重置IOS模擬器設置,沒有結果。
我在做什麼錯?
非視網膜

enter image description here

視網膜:

更新

NSLog(@"%f", image.scale) 

imageNamed方法給了我1.0

enter image description here

更新2: 我想優化我的動畫外觀,所以我想加載一個大的圖像一次,並剪裁它的框架。 首先,我負荷大圖像(@ 2倍或1 @ x),則使用循環

for (int i = 0; i<numberOfFrames; i++) 
    { 
     CGImageRef imageRef = CGImageCreateWithImageInRect(image.CGImage, 
                  CGRectMake(i*width, 0.0f, width, height)); 
     UIImage *animationImage = [UIImage imageWithCGImage:imageRef]; 

     if (isFlip) 
     { 
      [animationImages insertObject:animationImage atIndex:0]; 
     } 
     else 
     { 
      [animationImages addObject:animationImage]; 
     } 

     CGImageRelease(imageRef); 
    } 

我切這個大圖像和創建動畫。 如果是視網膜顯示,寬度和高度乘以2。

也許這裏是一個警告?

UIImage *animationImage = [UIImage imageWithCGImage:imageRef];

返回我的圖像縮放兩次?然而,如果我縮放(0.5,0.5)UIImageView,它是通過這個圖像初始化它適合。有什麼想法爲什麼縮放兩次?

回答

3

當用作UIImage或類似物時,視網膜和非視網膜圖像將具有相同的寬度和高度,將其視爲在視網膜顯示上圖像的DPI加倍,而不是寬度或高度。

這是爲了在編碼視網膜和非視網膜時保持透明。

+3

您可以檢查[scale](http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImage_Class/Reference/Reference。['UIImage']上的html#// apple_ref/doc/uid/TP40006890-CH3-SW39)屬性(http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImage_Class/Reference/Reference .html)來查看系統是否加載了視網膜版本。 – rckoenes 2013-03-26 09:30:12

+0

有你。我用了不正確的條款。當我在非視網膜模擬器內建立我的項目時,一切都可以,在視網膜顯示器中,某些視圖太大,我沒有適當地組織我的視圖。 – 2013-03-26 09:34:00

+0

啊,也許更改'name = @「[email protected]~ipad.png」;'只是'name = @「appearanceConnection.png」;'我不認爲你是要指定圖像的'大小'來加載,它會爲你選擇正確的一個 – Fonix 2013-03-26 09:38:33

相關問題