【问题标题】:How do I have my UIViewController respond to a non-touch event?如何让我的 UIViewController 响应非触摸事件?
【发布时间】:2010-04-28 02:07:27
【问题描述】:

使用 iPhone SDK 3.2 --

我有一个复杂的自定义 UIControl 来处理子控件上的触摸。在某些情况下,我希望父 UIControl 将事件传递给 UIViewController,然后它将在控件之外执行操作。我如何干净地做到这一点?谢谢!

【问题讨论】:

    标签: events iphone-sdk-3.0 uiviewcontroller uicontrol


    【解决方案1】:

    我最终用

    处理了这个问题

    [控制addTarget:self 动作:@选择器(动作:) forControlEvents:UIControlEventValueChanged];

    在 UIViewController 中

    [自己 sendActionsForControlEvents:UIControlEventValueChanged];

    在 UIControl 中

    【讨论】:

    • 那么这个例子中的控制是什么?直接一个 UIControl 的实例?
    【解决方案2】:

    您可以在 UIControl 中覆盖 hitTest:withEvent:,并在您确定触摸应由父级处理时返回 nil。

    【讨论】:

    • 聪明的方法,谢谢。如果这是 Flash/ActionScript,我会让 UIViewController 监听来自父 UIControl 的自定义事件;当满足我的条件时,我会在 UIControl 中调度这个事件。这种方法对我来说也很有意义——它曾经在 Objective C 中使用过吗?
    • 我已经尝试在 VC 中使用 touchesBegan:、touchesMoved: 等,但您只能获得未由任何 UIControl 处理的触摸,因此可能会或可能不会满足您的需求。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-06
    • 2011-01-23
    • 1970-01-01
    相关资源
    最近更新 更多