gpt4 book ai didi

iphone - subview 阻止父 View TouchesBegan?

转载 作者:可可西里 更新时间:2023-11-01 06:18:49 28 4
gpt4 key购买 nike

我有一个 View ,它有一个 UITableView 作为 subview,它完全覆盖了父 View 。当我尝试为父 View 实现 touchesBegan 时,我注意到根本没有调用该方法。无论如何要覆盖此行为?

最佳答案

实际上有一种方法可以覆盖这种行为。您需要扩展每个阻塞父 View 的子对象并重写 touchesBegan 方法,如下所示:

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

例如,如果您在 UIView 中的 UIScrollView 中有一个 UIButton,那么您需要创建两个自定义类。一个扩展 UIButton,另一个扩展 UIScrollView。在这些自定义类中的每一个中,您都需要添加上述方法定义。完成这些更改后,您将能够在父 UIView 中接收到 touchesBegan 事件。

关于iphone - subview 阻止父 View TouchesBegan?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12811848/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com