我正在UITableView
上实施一个滑动图像演示,而且我正在使用UIPageControl
。当我在第一行上滑动图像时,页面控件会正确更改,但是当我滑动第二行页面控件的图像时,它从第一行的位置开始。
这是我的代码
-(void)seePhotosBtnClicked:(UIButton *)sender
{
photoView.hidden = NO;
CGPoint touchPoint = [sender convertPoint:CGPointZero toView:addressTable]; // maintable --> replace your tableview name
NSIndexPath *clickedButtonIndexPath = [addressTable indexPathForRowAtPoint:touchPoint];
NSString *areaToSearch = [[addressInfoArray valueForKey:@"IMAGEPATH"]objectAtIndex:clickedButtonIndexPath.row];
NSArray *urlArray = [areaToSearch componentsSeparatedByString: @","];
for (int i = 0; i<=2; i++)
{
NSURL *imageURL = [NSURL URLWithString:[urlArray objectAtIndex:i]];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage *image = [UIImage imageWithData:imageData];
CGRect frame;
frame.origin.x =pagedScrollView.frame.size.width * i;
frame.origin.y = 0;
frame.size = pagedScrollView.frame.size;
UIImageView *imgView=[[UIImageView alloc]initWithFrame:frame];
imgView.image = image;
[pagedScrollView addSubview:imgView];
}
pagedScrollView.contentSize = CGSizeMake(pagedScrollView.frame.size.width * 3, pagedScrollView.frame.size.height);
[pageControl addTarget:self action:@selector(changePage:) forControlEvents:UIControlEventValueChanged];
}
- (void)changePage:(id)sender
{
// update the scroll view to the appropriate page
CGRect frame;
frame.origin.x = pagedScrollView.frame.size.width * pageControl.currentPage;
frame.origin.y = 0;
frame.size = pagedScrollView.frame.size;
[pagedScrollView scrollRectToVisible:frame animated:YES];
}
答案 0 :(得分:0)
知道了,停止滚动照片的地方添加此代码。
pageControl.currentPage=0;
pagedScrollView.contentSize = CGSizeMake(0, pagedScrollView.frame.size.height);
现在,您的滚动视图将从第一个图像开始,页面控制从第一个刻度开始