0

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 enter image description here

Here's the custom method in the .M file enter image description here Here's the call to the method (still in the .M file) enter image description here

jrturton
  • 118,105
  • 32
  • 252
  • 268

2 Answers2

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

Community
  • 1
  • 1
matt
  • 515,959
  • 87
  • 875
  • 1,141
0

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]. 
Thomas Keuleers
  • 6,075
  • 2
  • 32
  • 35
  • That worked. but the view is moving slightly to the right before growing? Why is that? How can I fix it? – user3071579 Feb 24 '14 at 18:06
  • Also why do I need to call [super viewWillAppear]? Can you please explain? – user3071579 Feb 24 '14 at 18:11
  • 1
    @user3071579 Because the documentation says to do so. Do Not Disobey. – matt Feb 24 '14 at 18:24
  • "That worked. but the view is moving slightly to the right before growing" @user3071579 Because Thomas's answer, though clever, is wrong. Look at my answer. I'm explaining the problem and its cause. Thomas is cleverly postponing the transform until after the first round of auto layout, but auto layout is still fighting you. – matt Feb 24 '14 at 18:26
  • You can readily see this by reverting to your earlier code but turning off auto layout in your storyboard. Presto, the problem is solved (for real). Unfortunately that's not a good solution, but it show that auto layout was always the true cause of the problem. – matt Feb 24 '14 at 18:27