I have a view (mainView) that has 4 constraints on it that make it stick all 4 of it's edges to it's superview. In other words, I am making it so it's size is exact same as it's superview sitting right above it.
The problem is, when I do this:
CGAffineTransform scaleT = CGAffineTransformMakeScale(0.7f, 0.7f);
self.mainView.transform = scaleT;
to make it smaller, I am expecting it to conflict with the constraints, however there are no exceptions being thrown.
The reason why I am expecting it to conflict with the constraints is because now mainView is 70% smaller so it cannot possibly stick to it's superview's edges.
Rather what it does is it centres itself in it's superview!
What am i missing here?
Thanks!
Since iOS 8.0, auto layout works in a predictable way with transforms. Auto layout sets the view's center and bounds.size, which are passed through to become the view's layer's position and bounds.size. Auto layout doesn't look at the view's transform or modify it. The transform is applied after auto layout is done positioning the view.
Prior to iOS 8.0, auto layout tried to take the transform into account, but the result was difficult to understand and generally meant that you should just not try to combine auto layout and transforms.
You can find more details in “Constraints & transformations: How Auto Layout quietly became transform-friendly in iOS 8” by Vlas Voloshin.
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