title: Synchronise animation with top of a keyboard with accessory view
body: <p>I have a <code>UITextField</code> which has an accessory view. I also have another view which resides at the bottom of the screen. I want this view to animate up as the keyboard shows, which I have done plenty of times by utilizing the <code>UIKeyboardWillShowNotification</code>. However, this time it is a little special since I want the bottom view to follow the top of the keyboard and not the top of the accessory view.</p>
  
  <p>Obviously I have tried this solution:</p>
  
  <pre><code>[UIView animateWithDuration:keyboardAnimationDuration delay:0 options:keyboardAnimationCurve animations:^{
          viewBottomConstraint.constant = keyboardHeight - accessoryViewHeight;
          [self.overviewViewController.view layoutIfNeeded];
  } completion:nil];
  </code></pre>
  
  <p>(<code>keyboardAnimationDuration</code>, <code>keyboardAnimationCurve</code> and <code>keyboardHeight</code> all come from the <code>userInfo</code> dictionary of the keyboard notification)</p>
  
  <p>This solution gives me the correct end position of the bottom view, but the animation is slightly off since the keyboard (including the accessory view) has to traverse a longer distance in the same duration (to the top of the accessory view instead of to the top of the keyboard).</p>
  
  <p>I have considered calculating a relative animation duration for my bottom view like this:</p>
  
  <pre><code>keyboardToAccessoryRatio = (keyboardHeight - accessoryViewHeight) / keyboardHeight
  relativeDuration = keyboardAnimationDuration * keyboardToAccessoryRatio
  </code></pre>
  
  <p>And then have the animation start with a delay of <code>keyboardAnimationDuration - relativeDuration</code>. However, this would only work nicely if the keyboard was using the <code>UIViewAnimationOptionCurveLinear</code> curve, but it is, in fact, using <code>UIViewAnimationCurveEaseInOut</code>.</p>
  
  <p>So any other suggestions?</p>
  
  <p>PS. I cannot simply add my button view to the accessory view as they are actually in separate view controllers. The animation is done as a part of a custom transition within a <code>UIViewControllerAnimatedTransitioning</code> class.</p>