My storyboard has UIImageView which is automatically positioned and scaled by autolayout constraints.
When application runs, this UIImageView is properly resized and positioned according to device screen size and autolayout constraints.
How I can get UIImageView frame after it is displayed on the screen? Common UIImageView.bounds and UIImageView.frame values return original values which were used in storyboard and does not reflect new UIImageView size.
A vanilla UIView instance, for example, does not have an intrinsic content size. This means that you need to add four explicit constraints to describe the size and position of a UIView instance in a user interface.
Multiplier is there for creating Proportional Constraint. Auto Layout calculates the first item's attribute to be the product of the second item's attribute and this multiplier . Any value other than 1 creates a proportional constraint. replace : with / - you will understand what it means.
Auto layout is a property you can add to frames and components. It lets you create designs that grow to fill or shrink to fit, and reflow as their contents change. This is great when you need to add new layers, accommodate longer text strings, or maintain alignment as your designs evolve.
There are three main options for setting up Auto Layout constraints in Interface Builder: You can control-drag between views, you can use the Pin and Align tools, and you can let Interface Builder set up the constraints for you and then edit or modify the results.
In order to get the right frame/bounds of your UIImageView
after resizing, you need first ask auto-layout to update that layout using [yourImageView layoutIfNeeded]
. that will solve your constraints and update your yourImage.bounds
.
[myImageView layoutIfNeeded];
NSLog(@"w: %f, h: %f", myImageView.bounds.size.width, myImageView.bounds.size.height);
Check these methods:
- (void)viewWillAppear:(BOOL)animated {
// view is about to be added to hieararchy
}
- (void)viewDidAppear:(BOOL)animated {
// view was added
}
- (void)viewDidLayoutSubviews {
// VC just laid off its views
}
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