1

Objective Cの回答も問題ありません。これは C# モノタッチです。

現在、このコードを使用して、WebView に 2 つのジェスチャ (左/右) を追加しています。正常に動作します。

両方のジェスチャが同じアクションになることを示すために、これを組み合わせてより少ないコードにすることはできますか?

//LEFT
UISwipeGestureRecognizer sgr = new UISwipeGestureRecognizer ();
sgr.AddTarget (this, MainViewController.MySelector);
sgr.Direction = UISwipeGestureRecognizerDirection.Left;
sgr.Delegate = new SwipeRecognizerDelegate ();
this.View.AddGestureRecognizer (sgr);

//RIGHT
UISwipeGestureRecognizer sgrRight = new UISwipeGestureRecognizer ();
sgrRight.AddTarget (this, MainViewController.MySelector);
sgrRight.Direction = UISwipeGestureRecognizerDirection.Right;
sgrRight.Delegate = new SwipeRecognizerDelegate ();
this.View.AddGestureRecognizer (sgrRight);
4

2 に答える 2

2

より短く、C# ラムダを利用するこのバージョンを試すことができます。

UISwipeGestureRecognizer sgr = new UISwipeGestureRecognizer ();
sgr.Action = delegate {
   // Your handler goes here
});
sgr.Direction = UISwipeGestureRecognizerDirection.Left | 
                UISwipeGestureRecognizerDirection.Right;
this.View.AddGestureRecognizer (sgr);
于 2011-01-02T14:03:17.013 に答える
0

ObjC では、ビットごとの or 演算子を指示とともに使用して、両方を含めます。ただし、使用している言語に関係なく、経験豊富な iOS 開発者から多くのサポートを受けることができて幸運です。

于 2011-01-02T03:45:58.737 に答える