0

I'm trying to scrollRect the UIScrollView but it is not scrolling.

There's my code:

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

and here's the scrollRect code:

 [scrollGeral scrollRectToVisible:CGRectMake(scrollGeral.frame.origin.x, scrollGeral.frame.origin.y + [_listaComentarios count] * 200, scrollGeral.frame.size.width, scrollGeral.frame.size.height) animated:NO];
TomCho
  • 3,204
  • 6
  • 32
  • 83
Chucrutes
  • 43
  • 9

2 Answers2

0

Make sure scrollGeral is not nil and is correctly hooked up to your xib/ storyboard.

contentSize could be 0 if it has not been set before, check this value before you set you content size to be 200pts taller that the existing one. If it is 0, and you've made it 200, the scrollview wont scroll on phone or pad as it already fits on screen.

Dan Atherton
  • 161
  • 6
  • The scrollContentSize.height log is 5087 and I`m setting the scrollRect to ` [scrollGeral scrollRectToVisible:CGRectMake(scrollGeral.frame.origin.x, scrollGeral.contentSize.height, scrollGeral.frame.size.width, scrollGeral.frame.size.height) animated:NO]; ` now – Chucrutes Apr 13 '15 at 17:01
  • so it looks like you want it to scroll to beond the bottom to the scrollcontent size? – Dan Atherton Apr 13 '15 at 17:14
  • you could use [scrollView setContentOffset:CGPointMake(0, 0) animated:YES] - you can your own content offset in – Dan Atherton Apr 13 '15 at 17:15
  • [scrollView setContentOffset:CGPointMake(0, 0) animated:YES] wouldnt move to top? – Chucrutes Apr 13 '15 at 17:21
  • yes it would. You can put whatever value you would like in the content offset – Dan Atherton Apr 13 '15 at 17:26
0

You should use bounds instead of 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];

See here.

You also should not set the target rect to full size of UIScrollView bounds - no scrolling will happen.

Community
  • 1
  • 1
bteapot
  • 1,897
  • 16
  • 24