scrollview not moving [duplicate]

2019-09-24 06:00发布

问题:

This question already has an answer here:

  • UIScrollView not scrolling 24 answers
  • UIScrollView not scrolling… 2 answers

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);