开发者

How to know which image is being viewed in UIScrollView? Also, is it possible to loop scrolling for an endless effect?

This is what I'm trying to do, and I'm not sure if it's possible using UIScrollView. First, I don't care about zooming, all I care is that the user is able to scroll through images just like t开发者_高级运维he Photo App, this I got. But how do I know which image he is viewing while using UIScrollView? For instance, if he stops on the 3rd image out of 10 images in the view, how do I know he's on that image? I can't find a way to access the index (is this accessible)??

Also, bonus question, once the user scrolls to the last image, I don't want the scrolling to stop but I want it to loop so that image 1 comes after image 10. And vice versa, if you scroll left passed image 1, you'll see image 10. I'm not asking for the logic, I can do this in an array very simply, I just don't know how to access (if it's even possible) the indexing of the images in the scroll view.

If it's not, does anyone have a solution to do this?

thanks in advance!


Hope this will help you.

// scrollview is the view in which you are loading the images.

CGFloat pageWidth = scrollView.frame.size.width;
int page = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;

Thanks,
jim.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜