iPhone 手势一次添加 2 个
Objective 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);
Objective C answers are fine too. This is in C# Monotouch.
Currently I am using this code to add 2 gestures (left / right) to my WebView. Works fine.
Can I combine this into less code though to indicate that both gestures go to the same action?
//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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试这个版本,它更短并且利用了 C# lambda:
You could try this version, which is shorter and takes advantage of C# lambdas:
在 ObjC 中,您可以使用按位或运算符以及说明来包含它们。但无论您使用哪种语言,您都会很幸运能够获得经验丰富的 iOS 开发人员的大力支持。
In ObjC you'd use the bitwise or operator with the directions to include them both. But as for whichever language you're using, you'll be lucky to get much support from any experienced iOS developer.