iPhone手势一次添加2个

iPhone手势一次添加2个,iphone,ipad,xamarin.ios,gesture-recognition,Iphone,Ipad,Xamarin.ios,Gesture Recognition,目标C答案也不错。这是C#monotuch 目前,我正在使用此代码向我的WebView添加2个手势(左/右)。很好 我能不能把这两个手势组合成更少的代码来表示两个动作是相同的 //LEFT UISwipeGestureRecognizer sgr = new UISwipeGestureRecognizer (); sgr.AddTarget (this, MainViewController.MySelector); sgr.Direction = UISwipeGestureRecogniz

目标C答案也不错。这是C#monotuch

目前,我正在使用此代码向我的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);

在ObjC中,您将使用按位or运算符和方向来同时包含它们。但是,无论您使用哪种语言,您都会幸运地从任何有经验的iOS开发人员那里获得大量支持。

您可以尝试此版本,该版本较短,并利用了C#lambdas:


这是什么语言?请在问题上加上任何标记。我发现如果我或他们在一起,我必须在选择器中列出答案。现在可以了呃,对我来说UISweepGestureRecognitor没有“Action”属性。。。?这怎么可能?我有最新的MT。
UISwipeGestureRecognizer sgr = new UISwipeGestureRecognizer ();
sgr.Action = delegate {
   // Your handler goes here
});
sgr.Direction = UISwipeGestureRecognizerDirection.Left | 
                UISwipeGestureRecognizerDirection.Right;
this.View.AddGestureRecognizer (sgr);