OXXY
OXXY

Reputation: 1047

Understanding UIScrollView Constraints

I have a UIScrollView with a UIView inside it and 3 UITableViews inside the view and I have the following constraints for the view :

enter image description here

In my code, exactly in ViewDidLayoutSubviews I have the following code

- (void)viewDidLayoutSubviews {
    [_containerScrollView setContentSize:CGSizeMake(SCREEN_WIDTH * 3, [_containerScrollView frame].size.height)];

    [_contentViewWidthLayoutcontraint setConstant:SCREEN_WIDTH * 3];
    [[self view] layoutIfNeeded];
}

Which change the view width realtivly to the screen width.

My question is why there is no conflict between the width constraint and the leading/trailing constraints ?

Upvotes: 1

Views: 58

Answers (1)

eric long
eric long

Reputation: 660

With your layout constraints, View's frame size is now become ScrollView's contentSize. So if you change _contentViewWidthLayoutcontraint's constant, it is same as you change ScrollView contentSize.width.

Note that ScrollView.frame.size and ScrollView.contentSize are totally different.

Upvotes: 2

Related Questions