所以我有一个 UIScrollview,它可以水平滚动并通过一堆包含用户头像的不同 UIImageViews 进行分页。但是,我只想从他们实际显示在屏幕上的 URL IFF 加载头像(一次显示 4 个,但我可以滚动浏览 30 个或更多或更少)。有没有办法检测它在哪个 UIImageView/哪个页面上?或者有没有人对我应该如何解决这个问题有任何一般性的建议或想法?先感谢您。
问问题
387 次
1 回答
1
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
CPoint offset = scrollView.contentOffset;
int index = offset.x / pageWidth;
switch (index) {
case 0:
//first ImageView
break;
case 1:
//second ImageView
break;
default:
break;
}
}
Or If you tag your imageViews (starting at 1) you can retrieve them via:
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
CPoint offset = scrollView.contentOffset;
int index = offset.x / pageWidth;
UIImageView *visibileImageView = (id)[scrollView viewWithTag:index+1];
}
You can use scrollViewDidScroll to detect the position at any point if you use the modulus:
int index = (offset.x - offset.x % pageWidth)/pageWidth;
于 2012-07-13T19:00:27.927 回答