Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个快速的问题,
我有一个包含多个子视图的视图。
在我看来,我已经开始接触等等。
有没有办法从触摸开始检索子视图,而不必从触摸中检测位置,然后对 c 哪个子视图在该特定区域有一个很大的 if else 。
谢谢。
您想要的方法是 UIView 实例方法-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event。这将为您返回包含point.
-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
point
所以你得到了你的触摸点,将它传递给你最大的容器 UIView 的那个方法,然后取回最前面的被触摸的子视图的句柄。十分简单。
我的解决方案不是从超级视图计算触摸位置。子类子视图并仅在那里获取触摸位置表格并相对于超级视图转换点。