检测 Monotouch 中 UIPageViewController 内控件的触摸事件

发布于 2024-12-27 17:36:01 字数 566 浏览 1 评论 0原文

我的 ViewController 上有几个按钮,位于 UIPageViewControllerGestureRecognizers 覆盖的区域内。此区域中的点击由 UIPageViewController 使用,并且永远不会到达下面的按钮。

我已阅读 iPad - PageViewController - 在按钮上显示下一个视图控制器单击UIPageViewController 手势识别器并了解其原理,但之前没有 Obj-C 经验,并且正在努力用 C# 重新创建这些解决方案。

有人可以提供一个如何在 MonoTouch 中完成此操作的示例吗?

I have several buttons positioned on my ViewController within the area covered by the UIPageViewController's GestureRecognizers. Taps in this area are consumed by the UIPageViewController and never reach the buttons below.

I've read iPad - PageViewController - Show next view controller on button click and UIPageViewController Gesture recognizers and understand the principle but have no prior Obj-C experience and am struggling to recreate these solutions in C#.

Could somebody please provide an example of how this is done in MonoTouch?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

世界和平 2025-01-03 17:36:01

以下是如何使用 MonoTouch 将第一个链接转换为 C#(注意:未经尝试)。

首先,您将为 UIGestureRecognizer 创建自己的(非 .NET)委托,如下所示:

class MyUIGestureRecognizerDelegate : UIGestureRecognizerDelegate {

    public override bool ShouldReceiveTouch (UIGestureRecognizer recognizer, UITouch touch)
    {
        return (!(touch.View is UIControl));
    }
}

如果触摸手势不适用,它将返回 trueUIControl(包括按钮)。

然后,您需要将此委托分配给分配给UIPageViewControllerGestureRecognizers

MyUIGestureRecognizerDelegate del = new MyUIGestureRecognizerDelegate ();

UIPageViewController pvc = new UIPageViewController ();

foreach (var gr in pvc.GestureRecognizers)
    gr.Delegate = del;

这使您可以调整手势的解释方式。如果手势本身不处理,则应将其路由到您自己的控件/按钮。

Here's how your first link would translate into C# using MonoTouch (note: untried).

First you would create your own (non .NET) delegate for UIGestureRecognizer like this:

class MyUIGestureRecognizerDelegate : UIGestureRecognizerDelegate {

    public override bool ShouldReceiveTouch (UIGestureRecognizer recognizer, UITouch touch)
    {
        return (!(touch.View is UIControl));
    }
}

It will return true to if the touch gesture does not apply to a UIControl (including buttons).

Then you need to assign this delegate to the GestureRecognizers that are assigned to your UIPageViewController.

MyUIGestureRecognizerDelegate del = new MyUIGestureRecognizerDelegate ();

UIPageViewController pvc = new UIPageViewController ();

foreach (var gr in pvc.GestureRecognizers)
    gr.Delegate = del;

This lets you adapt how the gesture will be interpreted. If not handled by the gesture itself then it should be routed to your own controls/buttons.

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