【问题标题】:How to limit touch events to a specific region or UIView?如何将触摸事件限制在特定区域或 UIView?
【发布时间】:2011-07-30 17:44:19
【问题描述】:

如何将触摸限制在特定区域或UIView

换句话说,我在视图上有一个UIButton,但它似乎被触摸禁用了。

我还应该写,触摸可以做我想做的事,但是,就像我说的,我失去了对UIButtons 的控制。

@Implementation
...


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    ...
}


- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    ...
}


- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    ...  
}

我解决了我的问题...

(我的错误)我制作了一个较小的 UIView,UIButtons 位于其外部。子视图附加到该 UIView。 (我可以看到按钮,但我什至无法按下它们)

解决方案(其中 2 个有效):

  • 将 UIButtons 的子视图添加到 self.view
  • 或...将较小的 UIView 放大到 340 x 480。

【问题讨论】:

  • 您能否提供更多详细信息?你如何处理触摸,你的视图层次结构是什么?..

标签: objective-c cocoa-touch


【解决方案1】:

如果您的视图(您在其中定义 touchesBegan 等)没有将触摸转发给响应者链中的下一个响应者(其中有您的按钮),您可以尝试调用 [super]那些方法,即:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    ...
    [super touchesBegan:touches withEvent:event];
}

其他方法也一样。另见讨论here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多