目标C 答案也很好。这是在C#Monotouch中。
目前我正在使用此代码向我的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);
答案 0 :(得分:2)
你可以尝试这个版本,它更短,并利用C#lambdas:
UISwipeGestureRecognizer sgr = new UISwipeGestureRecognizer ();
sgr.Action = delegate {
// Your handler goes here
});
sgr.Direction = UISwipeGestureRecognizerDirection.Left |
UISwipeGestureRecognizerDirection.Right;
this.View.AddGestureRecognizer (sgr);
答案 1 :(得分:0)
在ObjC中,你可以使用按位或运算符和方向来包含它们。但是对于您使用的任何一种语言,您将很幸运得到任何有经验的iOS开发人员的大力支持。