繁体   English   中英

iPhone / Objective-C TTLauncherView从URL加载高分辨率图像

[英]iPhone/Objective-C TTLauncherView loading high resolution images from a URL

我正在使用Three20的TTLauncherView ,想知道是否有人有加载高分辨率图像的经验?

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库进行更改,或者是否有更简单的方法来解决此类问题。

我通过在基于launcherButtonImage的three20样式表中添加新样式来实现此目的。 这是原始的...

     - (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。 希望这可以帮助。

我正在使用Three20的TTLauncherView

相反,请尝试使用SDWebImage:

https://github.com/rs/SDWebImage

您可以在UIImageView上发出两次加载,一次加载高分辨率图像,另一次加载低分辨率图像。 低分辨率应该先完成...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM