我正在添加AsyncImageView
以UIScrollView
从网络加载图像,它工作正常,我添加了 8 张图像。问题是paging
我已经启用pagingEnable
,YES
但它不会按照我想要的那样来,我正在尝试contentOffset
用不同的方式设置它,x
但它不会产生任何影响。我希望当我滚动或选择或选项时,每个图像都应该出现center
。UIScrollView
next
previous
这是我要添加图像的代码UIScrollView
arrImgUrls 是一个 NSArray
_currentImage, _imageCount 是整数
-(void)setImagesToScrollView
{
[btnPrev setEnabled:NO];
_currentImage = 0;
_imageCount = [arrImgUrls count];
int x=20;
int y=0;
int w=213;
int h=160;
for (int i=0; i<[arrImgUrls count]; i++)
{
AsyncImageView *asyncImageView = [[AsyncImageView alloc] initWithFrame:CGRectMake(x, y, w, h)];
[asyncImageView setDelegate:self];
[asyncImageView.layer setMasksToBounds:YES];
NSString *urlImage = [arrImgUrls objectAtIndex:i];
NSURL *url = [NSURL URLWithString:urlImage];
[asyncImageView loadImageFromURL:url];
[asyncImageView release];
[scrollImages addSubview:asyncImageView];
x=(x+w)+10;
}
scrollImages.contentSize=CGSizeMake(x, scrollImages.frame.size.height);
}
这是我用来显示的代码previous
或.next
UIScrollView
-(IBAction)prevImage:(id)sender
{
_currentImage--;
[btnNext setEnabled:YES];
if (_currentImage<=0)
{
_currentImage = 0;
[btnPrev setEnabled:NO];
}
[scrollImages setContentOffset:CGPointMake((_currentImage*imageWidth)+10, 0) animated:NO];
}
-(IBAction)nextImage:(id)sender
{
_currentImage++;
[btnPrev setEnabled:YES];
if (_imageCount-1 == _currentImage)
{
[btnNext setEnabled:NO];
}
[scrollImages setContentOffset:CGPointMake(_currentImage*imageWidth, 0) animated:NO];
}
All images loaded and added to UIScrollView
only problem is to show it in center
when user scrolls
or do previous
or next
.
Please point me where I'm doing wrong?
Thanks!