2017-07-28 14 views
0

私はXamarin iOSアプリケーションにスワイプを実装しようとしています。私はSwiftで書かれたsimple exampleを見つけましたが、私は第2のコード領域で立ち往生しています。Xamarin iOS - Interactive Swipe

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) -> UIViewControllerAnimatedTransitioning? { 
     return SimpleAnimationController() 
    } 
} 

問題は、C#ではクラスが1つのクラスまたは複数のインターフェイスから継承できるということです。また、私は機能が何であるか分かりませんfunc navigationControllerをやっています。

コードスニペットをどのように翻訳できますか?

ありがとうございました!

[編集1]

だから私はこのようになりましたクラスを実装:

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,() => 
     { 
      toViewController.View.Alpha = 1.0f; 
      Debug.WriteLine("Custom Transitioning"); 

     },() => 
     { 
      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 > 0.5) 
       { 
        Debug.WriteLine("Finishing Transition"); 
        this.FinishInteractiveTransition(); 
       } 
       else 
       { 
        Debug.WriteLine("Cancelling Transition"); 
        this.CancelInteractiveTransition(); 
       } 
       break; 
      default: 
       Debug.WriteLine("Unhandled Transition state"); 
       break; 
     } 
    } 
} 

は今ViewControllersが移行されますが、ユーザーは一部の画素のみを通す場合、彼らも行います。どのようなアイデアがここで起こっている? Xamarin.iOSで

答えて

0

は、インターフェイスの同等を持っている:

IUINavigationControllerDelegate 

あなたは必要な数のインターフェイスを実装することができます。

あなたはそれが正しいhere

Xamarinの翻訳は、私が見

public class MyViewController : UIViewController, IUINavigationControllerDelegate 
{ 

    public override void AwakeFromNib() 
    { 
     base.AwakeFromNib(); 
     NavigationController.Delegate = this; 
    } 

    [Export("navigationController:animationControllerForOperation:fromViewController:toViewController:")] 
    public IUIViewControllerAnimatedTransitioning GetAnimationControllerForOperation(UINavigationController navigationController, UINavigationControllerOperation operation, UIViewController fromViewController, UIViewController toViewController) 
    { 
     return new SimpleAnimationController(); 
    } 
} 
+0

だろう見つけることができますが、行は** NavigationController.Delegate =これは、** AwakeFromNibかのviewDidLoadで呼び出されるかどうかの例外がスローされます。 ** System.Reflection.TargetInvocationException:呼び出しのターゲットによって例外がスローされました。 ---> System.NullReferenceException:オブジェクト参照オブジェクトのインスタンスに設定されていません** ** EDIT:**おかしい事:**(!this.NavigationController = null)の場合は{ \t \t \t \t NavigationController。デリゲート= this; \t \t \t **仕事をしているようです –

+0

あなたのViewControllerにNavigationControllerがないためです。 MyViewControllerをどのように起動しますか? PushViewControllerメソッドを使用していますか? NavigationControllerのナビゲーションスタック内にある必要があります。これは、ViewControllerを表示するときにPushViewControllerを使用する場合、または新しいViewControllerをルートViewControllerとして新しいNavigationControllerを作成する場合にのみ発生します。 – stonecompass

+0

https://stackoverflow.com/a/7767160/2710750 – stonecompass