Reputation: 471
I have a ViewController
with a UIScrollView
that contains a View
that contains variable-sized content.
- ViewController
-ScrollView
-View
-label1
-label2
- ...
When the controller's viewDidLoad
is called, I set the UIScrollView
's content size to the appropriate height, but the view doesn't scroll. If I call the same line from an action on a button, it does update the contentSize
and scrolls correctly. I am using autolayout
. Any idea why and how to fix it?
The view won't scroll:
- (void)viewDidLoad
{
[super viewDidLoad];
[_scrollView setContentSize:CGSizeMake(100,500)];
}
The view will scroll correctly:
- (IBAction)test:(id)sender
{
[_scrollView setContentSize:CGSizeMake(100,500)];
}
Upvotes: 2
Views: 291
Reputation: 9
First ScrollView add new contraints and next label1 and label2 add contraints then final View view can add contraints.
Upvotes: 0
Reputation: 3908
ViewDidAppear also Guarantees that your view has been loaded and initialized But viewdidAppear fires after viewDidLayoutSubviews. if you do large coding in ViewDidLoad Realted to UI your ViewController delayed in display
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:NO];
[_scrollView setContentSize:CGSizeMake(100,500)];
}
Upvotes: 1