且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何创建无限滚动的 UIScrollView?

更新时间:2023-11-18 09:14:34

很简单&有点棘手...

It's very easy & somewhat tricky...

你不需要为 ScrollView 定义具体的大小.....

You don't need to define the specific size for the ScrollView.....

一般我们用...来定义...根据苹果的例子

Generally we use to define ....as per the Examples of Apple

//#define SCROLLVIEW_CONTENT_HEIGHT 460

//#define SCROLLVIEW_CONTENT_WIDTH  320

这没用……如果你需要无限的高度……

which is of no use...if you need the infinite height..

只需根据添加到 ScrollView 的对象动态设置 ScrollView 的高度......

just set the height of the ScrollView dynamically as per the Objects added to the ScrollView....

不需要为此设置预定义的高度...取动态高度....

No need to set the predefined height for this...take the dynamic height....

scrollview.contentSize = CGSizeMake(320, txtView.contentSize.height+450);
 CGPoint topOffset = CGPointMake(0,0);
 [scrollview setContentOffset:topOffset animated:YES];

希望这肯定对你有用..

Hope this will surely work for you..

祝你好运:)