title: How to animate the width and height of a UIView in Xcode?
body: <p>I have this subview I want to add to my main view, but make it expand from the origin. I read some of the Apple documentation but I don't understand where I am making mistake. I can animate the origin of the frame, i.e. to get it slide in from wherever, but the width/height doesn't seem to animate. Code as follows:</p>
  
  <pre><code>[UIView beginAnimations:@"animateAddContentView" context:nil];
  [UIView setAnimationDuration:0.4];
  customView.frame= CGRectMake(self.view.frame.origin.x +5, self.view.frame.origin.y +5, 0, 150);
  [self.view addSubview:customView];
  
  customView.frame= CGRectMake(self.view.frame.origin.x +5, self.view.frame.origin.y +5, 310, 150);
  [UIView commitAnimations];
  </code></pre>
  
  <p>I have also tried putting only the setFrame part in the animation like this: </p>
  
  <pre><code>customView.frame= CGRectMake(self.view.frame.origin.x +5, self.view.frame.origin.y +5, 0, 150);
  [self.view addSubview:customView];
  [UIView beginAnimations:@"animateAddContentView" context:nil];
  [UIView setAnimationDuration:0.4];
  customView.frame= CGRectMake(self.view.frame.origin.x +5, self.view.frame.origin.y +5, 310, 150);
  [UIView commitAnimations];
  </code></pre>
  
  <p>But it still doesn't work! </p>
  
  <p>EDIT: </p>
  
  <p>As per the suggestions, I have moved it to a block based animation solution, and this is the exact code:</p>
  
  <pre><code>NSLog(@"yourview : %@",customView);
  customView.frame= CGRectMake(self.view.frame.origin.x +5, self.view.frame.origin.y +5, 0, 150);
  
  NSLog(@"yourview : %@",customView);
  [self.view addSubview:customView];
  NSLog(@"yourview : %@",customView);
  
  //    [customView setFrame:CGRectMake( 0.0f, 480.0f, customView.frame.size.width, customView.frame.size.height)];
  
  [UIView animateWithDuration:0.4
                        delay:0
                      options:UIViewAnimationCurveEaseInOut
                   animations:^ {
                       NSLog(@"yourview : %@",customView);
  
                       customView.frame = CGRectMake(self.view.frame.origin.x +5, self.view.frame.origin.y +5, 310, 150);
                       NSLog(@"yourview : %@",customView);
  
                   }completion:^(BOOL finished) {
  
                   }];
  </code></pre>
  
  <p>Which still doesn't work for some reason. Possible problems I see are:</p>
  
  <ol>
  <li>I am loading this customView from a <code>nib</code> that is specifically 310 by 150, perhaps that is causing a problem.</li>
  <li>I am not importing the correct frameworks, but since I can animate the frame.origin parts of this view, I am not sure that is the case...I have <code>QuartzCore</code> and <code>Core Graphics</code> all imported and stuff.</li>
  </ol>
  
  <p>At each point in the log it is giving the correct stuff: for example, before the target frame the size is 0, 150, and after I set the frame its 310, 150. But the animation doesn't work!</p>