How to have an unbounded UIScrollView
I would like to be able to build a scroll view capable of scrolling an unbounded (infinite) distance (this is question number one, h开发者_如何学Goow to do this with the contentSize property). The reason for this is so that I can implement a scrolling calendar view, which the user can use to scroll through time along a single axis.
Now, I need to put a view/s in there to mark the dates as they scroll by. My second question is how to implement a view like this in a scroll view. I could have a long view, 3 or 4 times wider than the scrollview frame and just reposition and update that every time the scrolling stops, faking a continuous bar. Any other ideas?
Thanks!
I know it's been a while since you posted this question, but just for future reference:
At WWDC 2011, Apple gave a great presentation called "Session 104 - Advanced Scroll View Techniques". The video can be seen from developer.apple.com or from iTunes.
The main concept:
1 - Start off with a subview that is larger than your scrollView's bounds.
2 - In -layoutSubViews
from the scrollView, you check whether the contentOffset in the direction you want to scroll infinitely is past some threshold that you specify (this doesn't have to be any specific value, it could be 1 point in the extreme).
3 - If this is the case, you reset the contentOffset to zero, and you adjust the subview's frame by the same amount.
These last two steps happen within the same run loop cycle, hence the transition will not be visible. Beware that the scrollBar will jump, though. But as your scrollView is infinite, there is no visual feedback the scrollBars could give, anyway, so you'd better hide them when you've finished implementing this.
Not sure it can be... You could try CGSizeZero
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIScrollView_Class/Reference/UIScrollView.html#//apple_ref/occ/instp/UIScrollView/contentSize
contentSize
The size of the content view. @property(nonatomic) CGSize contentSize Discussion
The unit of size is points. The default size is CGSizeZero.
The real question is do you truely want "infinate" or do you want mostly infinate and just make the view ungodly large? Or do you want auto-resizing.
Also a continuous bar for an infinite scrollview? The bar would never move as it wouldn't get any closer to the beginning or the end... You could make a bar that dragging to the right would go into the future and dragging it to the left would go back and then just always reposition it in the center.... Other then that I dunno what would make sense here.
Looping UIScrollView Horizontally sounds like the same sort of problem, hopefully my comments there might give you some ideas as well.
Making an 'infinite' scrollview doesn't work - the memory requirements get way too large. The best way to do it is fake it.
3 screen scrollview:
|---|---|---|
| | | |
|---|---|---|
Make a scrollview that is 3 times as large as one screen, then when the user finishes scrolling to the next third of the scrollview, move the scroll position back to the center third and scoot the content over to the left. This happens so fast that there is no visible feedback to the user that the scrollview & content was just recentered.
Similarly, when the user scrolls back to the first third, change the scroll position to the center third and move all the content to the right.
For memory management, you should only load as much content as will fit onto those three screens. When you scroll to the next third, you'll reposition, and load the next screen of content.
精彩评论