简体   繁体   中英

Setting ContentOffset of a UIScrollView while Scrolling

This is the first question I have asked here so bear with me


. I've done quite a bit of looking into this but have been unsuccessful in finding a solution that worked so I figured I'd toss it out here.

I am using a UIScrollView to try and display a bunch of UIImageViews.

I have 20 UIImageViews loaded into the Scroll View at any one time. What I'm doing at the moment to show more than just 20 photo's is to have the UIImageViews update with new UIImages every time a certain ContentOffset it reached. Whenever the user scrolls down past a ContentOffset of 95 the Offset is reset to 0 and the new pictures are loaded. I picked a number that gave the illusion of continual scrolling so the user does not see the reloading/resetting of the view. The same thing happens when you scroll upwards past 0.

My problem is that when you flick the UIScrollView (so that it continues to scroll by itself) it seems as if the ContentOffset is not resetting like it's supposed to be. The view itself is resetting properly and for 1 iteration the offset is 0, but in the next iteration ( a split second later ) the offset is up in the 120's or 130's and it's jumping down as if I've reached the end of the next screen.

Anyone have any idea how to properly reset the ContentOffset while the UIScrollView is scrolling?

Apparently the inertia algorithm isn't compatible with what you're doing. Why not let it scroll freely and instead recycle the Imageviews that scroll outside of the visible rect for the ones that appear at the other side? (just like a tableview works)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM