title: Animations inside of layoutSubviews?
body: <p>I have a view (LSTabBarView) which supports insertion/deletion of new elements with the following methods:</p>
  
  <pre><code>- (void)insertItem:(LSTabItem *)item atIndex:(NSUInteger)index animated:(BOOL)animated; 
  - (void)removeItemAtIndex:(NSUInteger)index animated:(BOOL)animated;
  </code></pre>
  
  <p>LSTabItem is the object that represents my model class. Every time that a new element is added with insertItem:atIndex:animated: a new subview is created (LSTabControl) using the informations inside of this model object, then added to the main view, and finally layoutSubviews is called to recalculate the frame of each subviews.</p>
  
  <p>I have just implemented these operations but the "animated" parameter is not used for now and <strong>I was wondering where should I put the code to handle the animation when animated is YES.</strong> </p>
  
  <p>These are the relevant methods:</p>
  
  <pre><code>- (void)insertItem:(LSTabItem *)item 
             atIndex:(NSUInteger)index 
            animated:(BOOL)animated 
  {
      ...
      LSTabControl *tab = [self _configureNewTabControlForItem:item atIndex:index];
      [tabItems insertObject:item atIndex:index]; 
      [tabViews insertObject:tab atIndex:index]; // array which contains all the subviews
  
      [self setNeedsLayout];
  }
  
  - (void)removeItemAtIndex:(NSUInteger)index 
                   animated:(BOOL)animated 
  {
      ...
      LSTabControl *tab = [tabViews objectAtIndex:index];
      ...
      [tab removeFromSuperview];
  
      [tabViews removeObjectAtIndex:index];
      [tabItems removeObjectAtIndex:index];
  
      [self setNeedsLayout];
  }
  </code></pre>
  
  <p>What layoutSubviews do is basically to put every subviews in a linear horizontal sequence one after another applying a padding between each subview. Each subview could have a different width or height (they are not fixed size).
  When a new element is added with animation set to YES (lets say at index=2) I want that each subviews from index+1 to numberOfElements are shifted to right and then the new subview appear in the available hole.</p>
  
  <p>I want obviously LSTabBarView to be extensible, so in my base implementation of these methods I cannot make assumptions about how the subviews will be arranged by subclasses (for example a subclass might override layoutSubviews and decide to layout the elements in a vertical layout instead of horizontal and as consequence decides to shift each subviews down instead of to right when adding new elements...)</p>
  
  <p>I don't want to know how to perform the animation (I already know how to do it) but what is the correct approach how to animate the appearance of a new subview, considering my requirements described above.</p>
  
  <p><strong>Should I consider to perform all the animations inside of layoutSubviews or puts the animation code inside of insertItem/removeItem letting layoutSubviews just to calculate the subviews layout?</strong></p>
  
  <p>Thanks</p>