Reputation: 402
I have UIPageViewController
that contains simple UIViewController
s. The View of the VC contains an UIImageView
(aspect fit) at the top and a UITextView at the bottom.
The LayoutConstraints for the ImageView are:
The LayoutConstraints for the ImageView are:
This works as expected.
But when the VC is loaded and has the image to display, I want to change the size of the imageView. There is a minimum and a maximum size and if a image view is smaller or larger it needs to be resized. Otherwise the the imageview has to get the size of the image.
So I calculate the size for the actual image and set the constant for the two LayoutConstraints. The values are correct but the ImageView does not change.
I tried to set them in viewWillLayoutSubviews
but no change.
What am I doing wrong?
Upvotes: 1
Views: 934
Reputation: 2413
Try update your views inside viewDidLayoutSubviews:
- (void) viewDidLayoutSubviews {
// setup your constraints here
}
Hope this helps.
Upvotes: 2
Reputation: 11
Try changing the vertical spacing between the ImageView and the textfield to be flexible (>=0). If that doesn't solve the issue, add:
[view setNeedsLayout];
[view layoutIfNeeded];
After you adjust the size of the imageview to size of the new image.
Upvotes: 0
Reputation: 827
Write your change constraint code in the below provided block
dispatch_async(dispatch_get_main_queue(), {
})
Upvotes: 0