Reputation: 35112
I have this scrollview with autolayout. Scroll view has the blue color. In landscape mode it looks good.
But in portrait mode instead of let horizontally scroll I would reduce the width of the view with orange color to keep 20px distance from right edge too.
How? I set up 20px constrain on right side also, but the contentSize not get updated when rotating. I know that I am not allowed to set contentSize programmatically in case of autolayout.
Here you can see the constrains I set up:
Upvotes: 2
Views: 850
Reputation: 35112
I figured out. Instead of setting the right constrains, I created constrain for the width of view, created an IBOutlet for the constrain, and in code I set the constant of the constrain.
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{
if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
//self.scrollView.contentSize = CGSizeMake(944, 1600);
_viewWidthConstrain.constant = 944;
} else {
//self.scrollView.contentSize = CGSizeMake(500, 1600);
_viewWidthConstrain.constant = 500;
}
}
And here is the result:
Upvotes: 1