title: Xamarin iOS - Interactive Swipe
body: <p>I am trying to implement a Swipe into my Xamarin iOS App like all big Names are having. I found a <a href="https://github.com/codepath/ios_guides/wiki/View-Controller-Transitions" rel="nofollow noreferrer">simple example</a> written in Swift, but I get stuck with the second code area.</p>
  
  <pre><code>class MyViewController: UIViewController, UINavigationControllerDelegate  {
  
      override func awakeFromNib() {
          super.awakeFromNib()
          self.navigationController?.delegate = self
      }
  
      func navigationController(navigationController: UINavigationController, animationControllerForOperation operation: UINavigationControllerOperation, fromViewController fromVC: UIViewController, toViewController toVC: UIViewController) -&gt; UIViewControllerAnimatedTransitioning? {
          return SimpleAnimationController()
      }
  } 
  </code></pre>
  
  <p>The problem is, that in C# a class can only inherit from one class or multiple Interfaces. Also I don't know exactly what the function <strong><em>func navigationController</em></strong> is doing.</p>
  
  <p>So how can I translate the code snippet?</p>
  
  <p>Thanks for your help!</p>
  
  <p><strong>[Edit 1]</strong></p>
  
  <p>So I implemented the class now like this:</p>
  
  <pre><code>public class MyFadeTransition : UIPercentDrivenInteractiveTransition, IUIViewControllerAnimatedTransitioning
  {
      private UIViewController TransitioningController;
  
      public MyFadeTransition(UIViewController transitioningController)
      {
          TransitioningController = transitioningController;
          TransitioningController.View.AddGestureRecognizer(new UIPanGestureRecognizer(DidPan));
      }
  
      void IUIViewControllerAnimatedTransitioning.AnimateTransition(IUIViewControllerContextTransitioning transitionContext)
      {
          var fromViewController = transitionContext.GetViewControllerForKey(UITransitionContext.FromViewControllerKey);
  
          var toViewController = transitionContext.GetViewControllerForKey(UITransitionContext.ToViewControllerKey);
          transitionContext.ContainerView.AddSubview(toViewController.View);
  
          toViewController.View.Alpha = 0.0f;
  
          UIView.Animate(0.35, () =&gt;
          {
              toViewController.View.Alpha = 1.0f;
              Debug.WriteLine("Custom Transitioning");
  
          }, () =&gt;
          {
              transitionContext.CompleteTransition(!transitionContext.TransitionWasCancelled);
              Debug.WriteLine("Custom Transitioning Done");
  
          });
      }
  
      double IUIViewControllerAnimatedTransitioning.TransitionDuration(IUIViewControllerContextTransitioning transitionContext)
      {
          return 0.35;
      }
  
      public void DidPan(UIPanGestureRecognizer gesture)
      {
          var point = gesture.LocationInView(TransitioningController.View);
          double percent = Math.Max(Math.Min((point.X / 300), 0.99), 0.0f);
  
          Debug.WriteLine(string.Format("Point: {0} | Percent: {1}", point, percent));
  
          switch (gesture.State)
          {
              case UIGestureRecognizerState.Began:
                  // this.UsingGesture = true
                  this.TransitioningController.NavigationController?.PopViewController(true);
                  break;
              case UIGestureRecognizerState.Changed:
                  UpdateInteractiveTransition((System.nfloat)percent);
                  break;
              case UIGestureRecognizerState.Ended:
              case UIGestureRecognizerState.Cancelled:
                  if (percent &gt; 0.5)
                  {
                      Debug.WriteLine("Finishing Transition");
                      this.FinishInteractiveTransition();
                  }
                  else
                  {
                      Debug.WriteLine("Cancelling Transition");
                      this.CancelInteractiveTransition();
                  }
                  break;
              default:
                  Debug.WriteLine("Unhandled Transition state");
                  break;
          }
      }
  }
  </code></pre>
  
  <p>Now the ViewControllers are transitioning, but they do also if the user only swipes some pixels. Any idea what is happening here?</p>