Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIScrollView doesn't scroll vertically

I made iPhone app in which I have this hierarchy,

: When I try to scroll my scrollview it doesn't scroll I am using Autolayout in my project

content size of my scrollview is greater then the height of my scrollview still it doesn't scroll.

Here is my code snippet wrote in viewDidLoad

    UIView *tempo = (UIView *)[scrollVw viewWithTag:6];//View which is inside Scrollview

    float sizeOfContent = 0;
    for (int i = 0; i < [tempo.subviews count]; i++) {
        UIView *view =[tempo.subviews objectAtIndex:i];
        sizeOfContent += view.frame.size.height;

    }

    NSLog(@"sizeOfContent = %f", sizeOfContent);
    scrollVw.contentSize = CGSizeMake(scrollVw.frame.size.width, 1500);

    NSLog(@"scrollVw width = %f -- scrollVw height =%f",scrollVw.frame.size.width, scrollVw.frame.size.height);

    NSLog(@"tempo width = %f -- tempo height =%f",tempo.frame.size.width, tempo.frame.size.height);

Log Result:

sizeOfContent = 1500
scrollVw width = 320.000000      scrollVw height = 416.000000 
tempo width = 320.000000         tempo height =  416.000000

Where I am doing mistake?

like image 420
Krunal Avatar asked Dec 08 '22 06:12

Krunal


1 Answers

If you are using autolayout, then your views are ultimately layed out after viewDidLoad. So move your code into viewWillAppear or viewDidLayoutSubviews and you should be fine.

like image 58
Martin Koles Avatar answered Dec 15 '22 03:12

Martin Koles