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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With