最近我遇到一个问题,在ios开发中做一个类似于手机相册的功能,具体内容如下: 1.有一个200/300百张的图片数组放在沙河中,做一个左右手动的轮播图,每张图都要可以实现缩放问题。 2.差不多已经实现了,就是利用scrollView的嵌套,由于加载是一张张的,导致首次在滚动的过程中会出现空白。主要代码如下: //结束减速- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ if (scrollView == self.sv) { int index = scrollView.contentOffset.x / scrollView.frame.size.width; NSString *filePath = [fileDestination stringByAppendingString:@"/images"]; NSString *imagePath =[NSString stringWithFormat:@"/%@/%@",filePath,self.imageArr[index]]; UIImageView *imv = [self.imageViews objectAtIndex:index]; imv.image = [UIImage imageWithContentsOfFile:imagePath]; }}- (UIScrollView *)sv { if(_sv == nil) { _scrollViews = [[NSMutableArrayalloc] init]; _imageViews = [[NSMutableArrayalloc]init];
_sv = [[UIScrollView alloc] initWithFrame:(CGRectMake(0, 64, KScrollViewWidth, KScrollViewHeight - 128))];
_sv.contentSize = CGSizeMake(KScrollViewWidth * self.imageArr.count, KScrollViewHeight - 128);
_sv.delegate = self;
CGFloat x = self.index * KScrollViewWidth;
_sv.contentOffset = CGPointMake(x, 0);
_sv.pagingEnabled = YES;
//_sv是横向滚动的股东栏
[self.view addSubview:_sv];
for (int i = 0; i < self.imageArr.count; i ++) {
UIScrollView * scrollView = [[UIScrollView alloc] initWithFrame:(CGRectMake(KScrollViewWidth * i, 0, KScrollViewWidth, KScrollViewHeight - 128))];
scrollView.minimumZoomScale = 1;
scrollView.maximumZoomScale = 10;
[_sv addSubview:scrollView];
scrollView.delegate = self;
UIImageView *iv = [[UIImageView alloc] initWithFrame:(CGRectMake(0, 0, KScrollViewWidth, KScrollViewHeight - 128))];
NSString *filePath = [fileDestination stringByAppendingString:@"/images"];
[iv setImage:[UIImage imageNamed:@"789.png"]];
if (self.index == i) {
NSString *imagePath =[NSString stringWithFormat:@"/%@/%@",filePath,self.imageArr[i]];
iv.image = [UIImage imageWithContentsOfFile:imagePath];
}
self.icon = iv;
iv.contentMode = UIViewContentModeScaleAspectFit;
[scrollView addSubview:iv];
iv.tag = 1000;
[self.imageViews addObject:iv];
[self.scrollViews addObject:scrollView];
}
}
return _sv;
}
在这里我添加了一张默认的图片,但是在使用的时候还是很别扭,哪位大神帮帮忙呀?