scrollRectToVisible不滚动

时间:2015-04-13 16:47:45

标签: ios uiscrollview

我试图scrollRect UIScrollView,但它没有滚动。

我的代码是:

[scrollGeral setContentSize:CGSizeMake(scrollGeral.contentSize.width, scrollGeral.contentSize.height + 200)];

这里是scrollRect代码:

 [scrollGeral scrollRectToVisible:CGRectMake(scrollGeral.frame.origin.x, scrollGeral.frame.origin.y + [_listaComentarios count] * 200, scrollGeral.frame.size.width, scrollGeral.frame.size.height) animated:NO];

2 个答案:

答案 0 :(得分:0)

确保scrollGeral不是nil,并且正确连接到你的xib / storyboard。

如果之前未设置,

contentSize可能为0,请在将内容大小设置为比现有大小高200pts之前检查此值。如果它为0,并且您已将其设为200,则滚动视图不会在手机或平板电脑上滚动,因为它已经适合屏幕。

答案 1 :(得分:0)

您应该使用bounds代替frame

[scrollGeral scrollRectToVisible:
    CGRectMake(scrollGeral.bounds.origin.x,
               scrollGeral.bounds.origin.y + [_listaComentarios count] * 200,
               scrollGeral.bounds.size.width,
               scrollGeral.bounds.size.height) animated:NO];

请参阅here

您也不应该将目标rect设置为UIScrollView边界的完整大小 - 不会发生滚动。