Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIScrollView will not scroll, even after content size set

My UIScrollView is a ~4500px horizontal view that the user needs to scroll horizontally through to view the content.

I have set it up as follows:

- (void)viewDidLoad
{

    [super viewDidLoad];

    sview.frame = CGRectMake(0, 0, 568, 320);
    sview.contentSize = CGSizeMake(4500, 320);
    [sview setScrollEnabled:YES];
}      

Yet the scroll view does nothing. Is there something obvious I missed? i've tried literally every tutorial on the web.

like image 206
nworksdev Avatar asked Jan 16 '23 07:01

nworksdev


1 Answers

I got similar issue. I did following modifications and the scrollView started scrolling for me:

  1. Select to check the 'Bounce Horizontally' property for UIScrollView in xib.
  2. Move the code following code to viewDidAppear instead of viewDidLoad:
-(void) viewDidAppear:(BOOL)animated
{

    [super viewDidAppear:animated];
    sview.frame = CGRectMake(0, 0, 568, 320);
    sview.contentSize = CGSizeMake(4500, 320);
    [sview setScrollEnabled:YES];

}

I think this should help you.

like image 197
user_1989 Avatar answered Jan 17 '23 21:01

user_1989