Why is my UIView not growing with CGAffineTransfor

2020-05-06 15:07发布

问题:

My goal is to make a view grow double in size. The result I get with the code I have is "nothing happens". The view displays but doesn't grow. Any help would be appreciated.

Here's the .H file

Here's the custom method in the .M file Here's the call to the method (still in the .M file)

回答1:

When you see the square on screen, the transformation is already happened. Try putting the scaling code in viewDidAppear instead of viewWillAppear.

Another small remark: you forgot to call

[super viewWillAppear]. 


回答2:

The problem is that this is a view transform and you are using auto layout. Auto layout works by setting the frame of your view. Thus you apply a transform and then auto layout comes along and changes it back again.

I regard this as a major bug ever since the introduction of auto layout; it's as if the auto layout people did not think deeply enough about how iOS works before they introduced this feature. See my "essay" on this topic here: https://stackoverflow.com/a/14105757/341994