我是 iPhone 编程的新手。使用下面的代码,我可以在后台快速异步地从服务器获取图像。
我想分批下载 15 张图片。一旦用户向下滚动,他就可以下载并查看接下来的 15 张图像。我还想卸载和删除不再显示的图像。所以我想批量下载图片,如果有 1000 张图片,我希望它们下载为 0-15、15-30、30-45、.. 等等。
我该如何实施?
并且使用 Lazyloading 或 SDWebimage 源代码项目,我可以像我所说的那样获取图像,但我想以 3*3 缩略图显示图像(意味着我想显示 3 个图像的每一行)请告诉我我该怎么做。我想要一些像 Android 中的通用库这样的库
//remote image URLs
URLs = [[NSMutableArray alloc]init];
for (NSString *path in latestiamge)
{
NSURL *URL = [NSURL URLWithString:path];
if (URL)
{
[URLs addObject:URL];
}
else
{
}
}
self.imageURLs = URLs;
UISwipeGestureRecognizer* swipeUpGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeUpFrom:)];
swipeUpGestureRecognizer.direction = UISwipeGestureRecognizerDirectionUp;
[myScrollView addGestureRecognizer:swipeUpGestureRecognizer];
float horizontal = 2.0;
float vertical = 2.0;
for(int i=0; i<[imageURLs count]; i++)
{
if((i%3) == 0 && i!=0)
{
horizontal = 5.0;
vertical = vertical + 100.0 + 5.0;
}
CGRect frame;
frame.size.width=100.0;
frame.size.height=100.0;
frame.origin.x=0;
frame.origin.y=0;
AsyncImageView *imageView = [[AsyncImageView alloc] initWithFrame:frame];
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.clipsToBounds = YES;
imageView.tag = i;
//load the image
imageView.imageURL = [imageURLs objectAtIndex:i];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(actionHandleTapOnImageView:)];
imageView.userInteractionEnabled = YES;
[imageView addGestureRecognizer:singleTap];
[myScrollView addSubview:imageView];
buttonImage1 = [UIButton buttonWithType:UIButtonTypeCustom];
[buttonImage1 setFrame:CGRectMake(horizontal, vertical, 100.0, 100.0)];
[buttonImage1 setTag:i];
[buttonImage1 setImage:[idURLs objectAtIndex:i] forState:UIControlStateNormal];
[buttonImage1 setImage:[UIImage imageNamed:@"Overlay.png"] forState:UIControlStateSelected];
[myScrollView addSubview:buttonImage];
[buttonImage1 addSubview:imageView];
[myScrollView addSubview:buttonImage1];
horizontal = horizontal + 100.0 + 5.0;
}
[myScrollView setContentSize:CGSizeMake(320.0, vertical + 3900.0)];