2011-03-21 38 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