2011-03-21 41 views
0

我使用Three20的TTLauncherView,並想知道是否有人有加載高分辨率圖像的經驗?iPhone/Objective-C TTLauncherView從URL加載高分辨率圖像

http://three20.info/showcase/launcher

我使用下面的方法來設置我TTLauncherItem的:

NSString *imageUrl = [self displayImageUrl:@"http://foo.com/lowres.png" withHighResUrl:@"http://foo.com/hires.png"; 
TTLauncherItem *launcherItem = [[[TTLauncherItem alloc] initWithTitle:@"Icon1" 
                   image:imageUrl 
                    URL:@"Icon1" 
                  canDelete:NO] autorelease]; 

這是我用它來確定它是否是一個iOS4的方法。

- (NSString *)displayImageUrl:(NSString *)standardResUrl withHighResUrl:(NSString *)highResUrl { 
    NSString *imageUrl = nil; 
    if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2) { 
     imageUrl = highResUrl; 
    } else { 
     imageUrl = standardResUrl; 
    } 

    return imageUrl; 
} 

的問題是,圖像被實際上得到顯示在他們的全部尺寸上的iPhone 4,而一個iPhone 4的下方任何iOS設備越來越正確顯示。想知道是否需要對TTLauncherView庫進行更改,或者是否有更簡單的方法來解決此類問題。

回答

2

我通過添加一個新的樣式到我的three20樣式表基於launcherButtonImage完成了這一點。原來這是...

 - (TTStyle*)launcherButtonImage:(UIControlState)state { 
     TTStyle* style = 
     [TTBoxStyle styleWithMargin:UIEdgeInsetsMake(-7, 0, 11, 0) next: 
     [TTShapeStyle styleWithShape:[TTRoundedRectangleShape shapeWithRadius:8] next: 
     [TTImageStyle styleWithImageURL:nil defaultImage:nil contentMode:UIViewContentModeCenter 
         size:CGSizeZero next:nil]]]; 

     if (state == UIControlStateHighlighted || state == UIControlStateSelected) { 
      [style addStyle: 
      [TTBlendStyle styleWithBlend:kCGBlendModeSourceAtop next: 
      [TTSolidFillStyle styleWithColor:RGBACOLOR(0,0,0,0.5) next:nil]]]; 
     } 

    return style; 
} 

...這是更新的版本...

- (TTStyle*)favoriteLauncherButtonImage:(UIControlState)state { 

    TTStyle* style = 
    [TTShapeStyle styleWithShape:[TTRoundedRectangleShape 
            shapeWithRadius:4.0] next: 
    [TTBoxStyle styleWithMargin:UIEdgeInsetsMake(0, 0, 0, 0) 
         padding:UIEdgeInsetsMake(16, 16, 16, 16) 
         minSize:CGSizeMake(0, 0) 
         position:TTPositionStatic next: 
     [TTImageStyle styleWithImageURL:nil defaultImage:nil contentMode:UIViewContentModeScaleAspectFit 
           size:CGSizeMake(64, 64) next: nil 
     ]]]; 

    if (state == UIControlStateHighlighted || state == UIControlStateSelected) { 
     [style addStyle: 
     [TTBlendStyle styleWithBlend:kCGBlendModeSourceAtop next: 
      [TTSolidFillStyle styleWithColor:RGBACOLOR(0,0,0,0.5) next:nil]]]; 
    } 

    return style; 
} 

有可能在那裏的東西,你不需要像圓潤的邊角圖像。執行部分是TTImageStyle指令,它將圖像大小鎖定爲64x64。希望這可以幫助。

1

我使用Three20的TTLauncherView

相反,嘗試使用SDWebImage:

https://github.com/rs/SDWebImage

你可以只發出兩個負載上一個UIImageView,一個是高一的低分辨率圖像。低分辨率應該先完成...

+0

感謝這一點,問題是不加載/緩存圖像。就我所知,TTLauncherView沒有加載高分辨率圖像的功能? – fuzz 2011-03-21 05:31:05

+1

你正在使用ThreeTwenty的這個事實本身就是一個問題,如果你甚至考慮對它做出改變,這意味着你需要轉移到別的東西,即使你必須改變它來做你想做的事情。 ThreeTwenty是第一個框架,沒有寫得很好,大部分方面都被更好的框架所取代,以應付它離開的地方。 – 2011-03-21 06:04:39

+0

蘇里,不明白你最後一個問題的含義。我通常使用SDWebImage的方式是本地佔位符,以及在後臺加載高分辨率圖像的URL。我通常會將UIImageView設置爲scaleAspectFit,因此如果圖像較大,它在Retina和非Retina顯示屏上都會顯示良好(並且iPad類似於用於以2倍大小運行iPhone應用程序的視網膜) – 2011-03-21 07:18:31