【问题标题】:Another problem with UIResponder and event deliveryUIResponder 和事件传递的另一个问题
【发布时间】:2011-05-31 22:32:33
【问题描述】:

我正在尝试实现一个 UIResponder 对象,该对象将允许我记录屏幕活动,然后将事件传递给下一个响应者以允许应用程序正常进行。我已经对此进行了一段时间的研究,并看到了两种应该起作用的方法:要么创建根视图并忽略放置在其顶部的子视图中的触摸,从而允许根视图处理它们;或者创建一个添加到所有子视图的 GestureRecognizer。我的应用程序有多个视图在主窗口中交换进出。

我已经尝试了这两种方法,但最终陷入了同样的僵局:我在我的视图(或识别器)中收到了 touchesBegan/touchesMoved/touchesEnded 事件,但是当我将它们发送到响应者链时没有任何反应。我已经尝试了以下所有方法。请注意,“view”是从 touch.view 派生的,view.superview 是我的“loginView”对象,其中包含被点击以将我带到此处的按钮:

 [view hitTest:frame.origin withEvent:event];
 [view touchesBegan:touches withEvent:event];
 [view.superview hitTest:frame.origin withEvent:event];
 [view.superview touchesBegan:touches withEvent:event];
 [[view nextResponder] touchesBegan:touches withEvent:event];
 [[view nextResponder] hitTest:frame.origin withEvent:event];
 [[[view superview] nextResponder] touchesBegan:touches withEvent:event];
 [[view superview] hitTest:frame.origin withEvent:event];

这些都不起作用,事实上 '[[view nextResponder] hitTest...' 会产生警告。

我已经尝试过 resignFirstResponder,甚至打算尝试 sendAction,但我现在只是抓住了救命稻草。我尝试将我的观点放在链的底部和顶部并获得相同的结果。显然我遗漏了一些东西,但我看不到什么。

谁能告诉我下一步该尝试什么?

--山姆

【问题讨论】:

    标签: iphone xcode ios ipad uiresponder


    【解决方案1】:

    我不太确定您到底想做什么,但也许 http://iphonedevelopment.blogspot.com/2008/10/bit-about-responder-chain.html 可以帮助您。

    就个人而言,我在 UIView 子类中传递触摸的方法是:

    - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event {
        [super touchesBegan:touches withEvent:event];
        [[self nextResponder] touchesBegan:touches withEvent:event];
    }
    
    - (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent *)event {
        [super touchesMoved:touches withEvent:event];
        [[self nextResponder] touchesMoved:touches withEvent:event];
    }
    
    - (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent *)event {
        [super touchesEnded:touches withEvent:event];
        [[self nextResponder] touchesEnded:touches withEvent:event];
    }
    

    【讨论】:

    • 谢谢,但这就是我尝试过的方法,但它仍然对我不起作用。该事件永远不会传递给 nextResponder。所有的例子都让它看起来像我的应该工作,但事实并非如此。我的基本观点与 IBActions 和 Outlets 有关联吗?我正在拦截按钮按下并试图使底层视图的按钮做出反应;它不是。我“消费”了 touchesBegan 事件(即使我不想这样做),但它没有更进一步。
    • 好的,我离得更近了一点:我已经确定向 UIButton 对象发送 touchesBegan 似乎不会导致它触发 UIControlEventTouchUpInside 事件。如果该事件未触发,则与按钮关联的回调不会触发。因此,对于我想要监控的应用程序中的每个对象,我需要调用适当的“火灾”事件吗?这似乎很笨拙。
    猜你喜欢
    • 1970-01-01
    • 2018-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-04
    • 1970-01-01
    • 2015-10-26
    相关资源
    最近更新 更多