I have a UIImageView
embedded in a UIView
. My entire app uses AutoLayout
, but I want to remove constraints
for the
You can't not have constraints - you must have enough constraints in place to unambiguously size and position every view
You can create a resizable view that is laid out using Autolayout.
For example, in your case, you can create positioning constraints - say, pin the centre of the image view horizontally and vertically in the centre of its superview.
You can also create size constraints, horizontally and vertically. See my answer here for how to do this. Create outlets to these two constraints (if using interface builder). You can have height and width constraints of a specific number, or use the multiplier to make a fixed aspect ratio.
In response to pinch gestures, you can adjust the .constant
properties of the two size constraints, and call setNeedsLayout
. This will resize your image view whilst keeping its centre pinned.
If you do the fixed aspect ratio suggestion above, resizing a view using constraints is actually much simpler than setting the frame.