title: How to bounce child view controller's UICollectionView when the child view controller is presented?
body: <p>I want to present a child view controller by dropping it from top to the bottom. The child view controller is a UICollectionViewController with several cells in it. I can use the iOS7 UIViewControllerContextTransitioning for the dropping down view controller transition. But if I want only the collection view to bounce (like a ball hit on the ground) when the child view controller is presented, how should I do?</p>
  
  <p>I have try to use UIKit Dynamics and create some UIAnimatorBehavior on the UICollectionView after the transition, like UIGravityBehavior and UIPushBehavior. But they don't seem to work. Maybe I am using them in the wrong way. Is there anyone can give me some hints?</p>
  
  <p><img src="https://i.stack.imgur.com/PsQ0Z.png" alt="illustration of view controllers"></p>
  
  <h2>Update</h2>
  
  <p>After tried several solutions, I finally came out a solution which is pretty close to what I want. This video shows the result: <a href="http://youtu.be/tueXDBMsdt0" rel="nofollow noreferrer">http://youtu.be/tueXDBMsdt0</a> </p>
  
  <p>But I think there should be a better solution for that. And here is my solution's steps:</p>
  
  <ol>
  <li><p>Create a <code>UIViewControllerAnimatedTransitioning</code> object, which animate the view controller transition from top to bottom.</p></li>
  <li><p>The child view controller is a <code>UICollectionViewController</code>. At the end of transition animation, I set child view controller's scrollview content offset to (0, -30), and then complete the transition. </p></li>
  <li><p>In child view controller's <code>viewDidAppear</code>, animate the content offset back to (0, 0). </p></li>
  <li><p>Besides, I also follow the instructions in the article: <a href="http://www.teehanlax.com/blog/implementing-a-bouncy-uicollectionviewlayout-with-uikit-dynamics/" rel="nofollow noreferrer">http://www.teehanlax.com/blog/implementing-a-bouncy-uicollectionviewlayout-with-uikit-dynamics/</a> to set UIKit dynamics animator in cells. When the content offset is changed, then the cells will look like bouncing.</p></li>
  </ol>
  
  <p>The transition animation code looks like this:</p>
  
  <pre><code>- (void) animateTransition:(id&lt;UIViewControllerContextTransitioning&gt;)transitionContext {
    UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
  
    CGRect frame = [[transitionContext containerView] frame];
    CGRect startFrame = frame;
    startFrame.origin.y -= CGRectGetHeight(transitionContext.containerView.frame);
  
    [transitionContext.containerView addSubview:fromViewController.view];
    [transitionContext.containerView addSubview:toViewController.view];
    toViewController.view.frame = startFrame;
  
    [UIView animateWithDuration:0.4 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
  
                   toViewController.view.frame = frame;
                 }
                 completion:^(BOOL finished) {
                   ((UICollectionViewController*)toViewController).contentOffset = CGPointMake(0, -30);
                   [transitionContext completeTransition:YES];
                 }];
  }
  </code></pre>
  
  <p>And in child view controller viewDidAppear:</p>
  
  <pre><code>- (void) viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
  
    [self.collectionView setContentOffset:CGPointMake(0, 0) animated:YES];
  }
  </code></pre>
  
  <p>But I would still want the cell to bounce more naturally. Any other better solutions?</p>