问题
Quite a simple bug. Unable to resolve.
I added a scrollview to my application. Next I added a view to this scrollview which is out of scrollview bounds. I was hoping the scrollview would allow my view to be scrolled.
but the view is not scrollable. i.e. I added a button to it, to see it is scrolling horizontally. However its not.
The kind of functionality I'm looking is like infinite scrolling with a long list of buttons, similar to http://www.cocoacontrols.com/controls/infinitescrollview
How can I achieve this?
回答1:
You can set the property
[scrollview setContentSize:CGRectMake(x, y, width,height)];
width = 320*no of views you want to add in scrollview
height = You can put it height view e.g. 460;
and set frame
scrollview.frame=CGRectMake(x, y, self.view.frame.size.width, height) //self.view.frame.size.width=320 (iphone)
This is the simplest way to achieve above
and if you want it with the button click then use scrollview property
[scrollview setContentOffset:(CGPoint) animated:BOOL]
or
[scrollview setContentOffset:(CGPoint)]
hope it'll help
回答2:
try
scr.contentSize = CGSizeMake(scr.frame.size.width, contentHeight);
来源:https://stackoverflow.com/questions/15612591/scrollview-not-moving