常規思路流程
#define PADDING 20
- (NSInteger)loadPhotos
{
//清理之前照片
for (UIView *v in [_scrollView subviews]) {
[v removeFromSuperview];
}
workingFrame = [[UIScreen mainScreen]bounds];
workingFrame.origin.x = PADDING;
for (int i = 0; i < int_total; i++) {
CGRect frame = workingFrame;
WQPhoto *photoView = [[WQPhoto alloc] initWithFrame:frame];
[photoView setScroller:self];
[photoView setIndex:i];
WQAlbumPhoto *photo = [albumObject._photos objectAtIndex:i];
[photo cleanThumbnail];
if (i == int_current) {
//加載原圖
[photoView setImage:photo.oriImage];
[photoView setIsLoad:YES];
}else if (int_current - 10 < i && i < int_current + 10){
//加載左右臨近的縮略圖
[photoView setImage:photo.thumbnail4view];
}
[_scrollView addSubview:photoView];
workingFrame.origin.x = workingFrame.origin.x + 2 * PADDING
+ workingFrame.size.width;
}
//實現可滾動
[_scrollView setContentSize:CGSizeMake(workingFrame.origin.x, workingFrame.size.height / 2)];
[_scrollView setContentOffset:CGPointMake(360 * int_current, 0)];
//加載其餘縮略圖
loadThread = [[NSThread alloc]initWithTarget:self selector:@selector(loadImages) object:nil];
return 0;
}
使用低分辨率圖
多線程任務
優化快速翻閱體驗
在頁面跳轉時間允許的範圍內,加載用戶選定的那張圖片的高清原圖的同時,儘可能多的加載幾張左右臨近的圖片的低分辨率圖。
-(BOOL)loadImages
{
for (int i = int_current - 10, j = int_current + 10 ; !( i < 0 && int_total - 1 < j); --i, ++j) {
if (!(i < 0)) {
WQPhoto *photo_pre = [_scrollView.subviews objectAtIndex:i];
WQAlbumPhoto *photoPre = [albumObject._photos objectAtIndex:i];
[photo_pre setImage:photoPre.thumbnail4view];
}
if (!(int_total - 1 < j)) {
WQPhoto *photo_next = [_scrollView.subviews objectAtIndex:j];
WQAlbumPhoto *photoNext = [albumObject._photos objectAtIndex:j];
[photo_next setImage:photoNext.thumbnail4view];
}
}
return YES;
}