带选定页面的ScrollView

fai*_*sal 2 iphone paging uiscrollview

我有一个scrollViewWith大小宽度= 320x10和高度= 460.我在scrollview中添加了10个大小为width = 320和height = 460的图像并启用了分页.现在我可以通过滚动从第1张图像滚动到第10张图像.

当scrollView显示时,它始终显示在第1页.我想首先显示scrollView的任何随机页面,这样我可以从最初滚动上一页和下一页.我怎样才能做到这一点?

小智 7

[scrollView setContentOffset: CGPointMake(0, y) animated: YES];
Run Code Online (Sandbox Code Playgroud)

您只需要将y变量设置为要滚动到的位置即可.例如:

[scrollView setContentOffset: CGPointMake(0, 920) animated: YES];
Run Code Online (Sandbox Code Playgroud)

应滚动到第3张图片.