CGAffineTransform and NSLayoutConstraint conflict

I have a view ( mainView

) that has 4 constraints on it that make it stick to all 4 of its edges for it. In other words, I am doing it so that the size is exactly the same as above it, above it.

The problem is when I do this:

CGAffineTransform scaleT = CGAffineTransformMakeScale(0.7f, 0.7f);
self.mainView.transform = scaleT;

      

to reduce it I expect it to conflict with constraints, however there will be no exceptions.

The reason I expect it to clash with constraints is because it mainView

is 70% smaller now, so it cannot stick to its supervisor boundaries.

Chances are that he centers himself in this supervision!

What am I missing here?

Thank!

+3


source to share


2 answers


Since iOS 8.0, auto-layout works in a predictable way with transformations. Automatic layout sets the view center

and bounds.size

which are traversed to become the presentation layer position

and bounds.size

. Auto Layout does not look at transform

or change the view . The transformation is applied after the automatic layout is done by 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 simply shouldn't try to combine auto-layout and transforms.



You can find more information in "Constraints and Transformations: How Auto Layout Became Harmless to Conversion in iOS 8" by Vlas Voloshin .

+3


source


Try to paste your described code under

  • (voids) viewDidLayoutSubviews

How:



 - (void)viewDidLayoutSubviews
{
    CGAffineTransform scaleT = CGAffineTransformMakeScale(0.7f, 0.7f);
    self.mainView.transform = scaleT;
}

      

Because autolayout can make any changes to the transform property of viewDidLoad.

0


source







All Articles