title: Creating a custom view with an animation
body: <p>Im trying to make a custom view where one of it's elements(a UILabel) has animation that when a button of the custom view is tapped the label should expand and then contract. The first part of the animation happens correctly but not the second. Im using this method.</p>
  
  <pre><code>[UIView animateWithDuration:1.3 animations:^{
      CGRect frame = CGRectMake(50, 15, 140, 20);
      [labelFav setFrame:frame];
  } completion:^(BOOL finished) {
      //[labelFav setHidden:YES];
      [UIView animateWithDuration:1.3 animations:^{
          CGRect frame = CGRectMake(50, 15, 0, 20);
          [labelFav setFrame:frame];
      }];
  
  }];
  </code></pre>
  
  <p>I believe it's a problem with how the methods Refresh and LayoutSubviews are implemented.
  I did it following this tutorial, <a href="http://www.raywenderlich.com/1768/uiview-tutorial-for-ios-how-to-make-a-custom-uiview-in-ios-5-a-5-star-rating-view" rel="nofollow noreferrer">ray wenderlinch</a></p>
  
  <p>The problem comes when after the first animation is called, LayoutSubviews is called, so all the items are set to the initial position, and when the first animation is finished the second one starts but the items are set to the original state, so I believe the animation doesnt happen because there's been a change between animations.</p>
  
  <p>I would like to know how to implement this correctly, can you lend me a hand?</p>
  
  <p>Thanks.</p>
  
  <p>PS: This is a second question about the same problem but with a different angle.<a href="https://stackoverflow.com/questions/19248659/make-2-animations-in-custom-view/19250212">my previous question</a></p>
  
  <p>[UPDATE]</p>
  
  <p>This is my code for LayoutSubviews:</p>
  
  <pre><code>- (void)layoutSubviews {
  [super layoutSubviews];
  
  if(_idEvent == 0) return;
  
  _buttonFav = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];
  [_buttonFav setImage:[UIImage imageNamed:@"fav.png"] forState:UIControlStateNormal];
  [_buttonFav addTarget:self action:@selector(pressedFavButton:) forControlEvents:UIControlEventTouchDown];
  
  _labelButton = [[UILabel alloc]initWithFrame:CGRectMake(0, 45, 0, 20)];
  _labelButton.text = @"LABEL";
  
  [self addSubview:_labelButton];
  [self addSubview:_buttonFav];
  </code></pre>
  
  <p>}</p>
  
  <p>Which is called right before the second animation. My refresh method is:</p>
  
  <pre><code>- (void)refresh {
  if(selected){
  
      [_buttonFav setImage:[UIImage imageNamed:@"fav_sel.png"] forState:UIControlStateNormal];
  }
  else{
      [_buttonFav setImage:[UIImage imageNamed:@"fav.png"] forState:UIControlStateNormal];
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Where I just set the image for the button depending on an attribute that lets me know if the button was tapped.</p>