iPhone 手势一次添加 2 个

发布于 2024-10-10 03:46:07 字数 733 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

素年丶 2024-10-17 03:46:07

您可以尝试这个版本,它更短并且利用了 C# lambda:

UISwipeGestureRecognizer sgr = new UISwipeGestureRecognizer ();
sgr.Action = delegate {
   // Your handler goes here
});
sgr.Direction = UISwipeGestureRecognizerDirection.Left | 
                UISwipeGestureRecognizerDirection.Right;
this.View.AddGestureRecognizer (sgr);

You could try this version, which is shorter and takes advantage of C# lambdas:

UISwipeGestureRecognizer sgr = new UISwipeGestureRecognizer ();
sgr.Action = delegate {
   // Your handler goes here
});
sgr.Direction = UISwipeGestureRecognizerDirection.Left | 
                UISwipeGestureRecognizerDirection.Right;
this.View.AddGestureRecognizer (sgr);
醉城メ夜风 2024-10-17 03:46:07

在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文