事件touchesForView:在超级视图中返回null

发布于 2025-01-06 17:04:06 字数 589 浏览 6 评论 0原文

我有一个名为 BigView 的 UIView 子类,它重写了 TouchesMoved(除其他外),如下所示:

@implementation BigView
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    NSSet * viewTouches = [event touchesForView:self];
    NSLog(@"set of touches: %@", viewTouches);
}
@end

我的 BigView 实例也有一个子视图(常规 UIView 实例) - 当我触摸该子视图内部时,上面的 touchesMoved 方法被调用,但 viewTouches 出现 null。子视图不会重写任何事件处理方法(touchesBegantouchesMoved 等)。我希望视图的触摸计数包含其子视图内的所有触摸,但它似乎并不是这样工作的。我在代码中做错了什么吗,或者这是它应该工作的方式,但我不明白为什么? (如果是后者,为什么这样更好?)

谢谢!

I have a subclass of UIView called BigView that overrides touchesMoved (among other things) like so:

@implementation BigView
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    NSSet * viewTouches = [event touchesForView:self];
    NSLog(@"set of touches: %@", viewTouches);
}
@end

My BigView instance also has a subview (regular UIView instance) - when I touch inside that subview, the above touchesMoved method gets called, but viewTouches comes up null. The subView doesn't override any of the event handling methods (touchesBegan, touchesMoved, etc). I would expect the touch count for a view to include all of the touches inside its subviews, but it doesn't seem to be working that way. Am I doing something wrong in the code, or is this the way it should work and I don't understand why? (If the latter, why is this better?)

Thank you!

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文