UIScrollView contentSize does not work, it's not autolayout

advertisements

I have a UIScrollView with a contentView with stuff inside the contentView. Everything is created programmatically, not in IB (my way of avoiding different screen size constraint messes in IB). Autolayout is OFF on the corresponding NIB, so that's not a problem. All code below is located in viewDidAppear:

CGRect screenBound = [[UIScreen mainScreen] bounds];
CGSize screenSize = screenBound.size;
CGFloat screenHeight = screenSize.height;

self.scrollView = [[UIScrollView alloc] initWithFrame:
    CGRectMake(0, 65, 320, screenHeight)];
scrollView.backgroundColor = [UIColor clearColor];

UIView *contentView = [[UIView alloc] initWithFrame:
    CGRectMake(0, 0, 320, 1200)];
[scrollView addSubview: contentView];
[scrollView setContentSize:contentView.frame.size];

scrollView.contentSize = CGSizeMake(320, 1200);
[self.view addSubview:scrollView];

It scrolls a little bit on iPhone 5, but only about 20 pixels more than the screen size. On iPhone 4 it scrolls all the way down to 1200 pixels, no problem.


Figured it out on my own. I was loading all of my elements inside the viewDidAppear, not just the scrollView.

By moving contentView declaration and all the elements inside of contentView into it's own function then declared in viewDidLoad, it resolved the issue and everything loads just fine.