title: TabBarController with interactive animated transitioning
body: <p>I'm trying to implement interactive animated transition between tabs in a TabBar. I'm using a pan gesture recogniser. I made a custom animation and use UIPercentDrivenInteractiveTransition to make the switching interactive. But it seems that I don't really understand the process that goes behind all the animation.<br>
  I did manage to make a non-interactive animation, but adding interactivity was somehow difficult. I read many tutorials on the internet and I fully understand how the code snippets that everybody posts works but I somehow can't implement it in my case.  I made a TabBar application with 2 tabs both with navigation bar.<br>
  Here is my code: </p>
  
  <p>TabBarController.swift </p>
  
  <pre><code>import UIKit
  
  class TabBarController: UITabBarController, UITabBarControllerDelegate {
  
  var usingGesture = false
  var interactiveTransition:UIPercentDrivenInteractiveTransition?
  
  override func viewDidLoad() {
      super.viewDidLoad()
      let panGesture = UIPanGestureRecognizer(target: self, action: "didPan:")
      self.view.addGestureRecognizer(panGesture)
      self.delegate = self
      // Do any additional setup after loading the view.
  }
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
      // Dispose of any resources that can be recreated.
  }
  
  func tabBarController(tabBarController: UITabBarController, interactionControllerForAnimationController animationController: UIViewControllerAnimatedTransitioning) -&gt; UIViewControllerInteractiveTransitioning? {
      return self.interactiveTransition
  }
  
  func didPan(gesture: UIPanGestureRecognizer){
      let point = gesture.locationInView(gesture.view)
      let percent = fmax(fmin((point.x / 300.0), 0.99), 0.0)
      self.interactiveTransition = UIPercentDrivenInteractiveTransition()
  
      switch (gesture.state){
      case .Began:
          self.usingGesture = true
          self.selectedIndex++
      case .Changed:
          self.interactiveTransition?.updateInteractiveTransition(percent)
      case .Ended, .Cancelled:
          if percent &gt; 0.5 {
              self.interactiveTransition?.finishInteractiveTransition()
          } else {
              self.interactiveTransition?.cancelInteractiveTransition()
          }
          self.usingGesture = false
      default:
          NSLog("Unhandled state")
      }
  }
  }
  </code></pre>
  
  <p>TransitionToLeft.swift</p>
  
  <pre><code>import UIKit
  
  class TransitionToLeft: UIPercentDrivenInteractiveTransition, UIViewControllerAnimatedTransitioning {
  
  func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
  
      let fromView:UIView = transitionContext.viewForKey(UITransitionContextFromViewKey)!
      let toView:UIView = transitionContext.viewForKey(UITransitionContextToViewKey)!
  
      transitionContext.containerView().addSubview(fromView)
      transitionContext.containerView().addSubview(toView)
  
      toView.frame = CGRectMake(toView.frame.width, 0, toView.frame.width, toView.frame.height)
      let fromNewFrame = CGRectMake(-1 * fromView.frame.width, 0, fromView.frame.width, fromView.frame.height)
  
      UIView.animateWithDuration( 0.7, animations:{ () -&gt; Void in
          toView.frame = fromView.frame
          fromView.frame = fromNewFrame
          },{ (Bool) -&gt; Void in
              // update internal view - must always be called
              transitionContext.completeTransition(true)
      })
  
  }
  func transitionDuration(transitionContext: UIViewControllerContextTransitioning) -&gt; NSTimeInterval {
      return 0.7
  }
  
  }
  </code></pre>
  
  <p>Can someone help me figure this out?</p>