gpt4 book ai didi

ios - 如何在选择自定义 UITableViewCell 时获取触摸坐标?

转载 作者:可可西里 更新时间:2023-11-01 03:53:06 25 4
gpt4 key购买 nike

当我触摸(Touch Up)一个 UITableViewCell 时,我的 ViewController 的 UITableViewDelegate 方法 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 被调用。此时我还需要获取 Touch-Point 的 x 坐标,以便我可以知道 Cell 的哪一部分被触摸了(非附件项)。我已经尝试使用通常的触摸方法,例如 TouchesDidEnd,但无论我触摸到哪里,坐标总是返回 x=0.000 y=0.000(ViewController 中 UITableView 对象中自定义 UITableViewCell 中的位置)。我还尝试从 Custom Cell 类中实现触摸处理,虽然我可以获得准确的坐标,可惜我找不到将这些坐标传递给我的 ViewController 类(具有 UITableView)的方法。

问:有什么好的方法可以在我触摸自定义 UITableViewCell 时获取设备屏幕的 x 坐标?

最佳答案

将透明的 UIView 放在您的 TableView 之上,覆盖其 -touchesBegan:withEvent: 等方法。在那些重写的方法中,获取 UITouch 对象并调用它们的 -locationInView: 以获取 CGPoint 值。

这会为您提供触摸事件的坐标。

然后您只需将那些 UITouch 事件传递给基础 TableView 。 TableView 处理将触摸传递到行等的常规业务。

关于ios - 如何在选择自定义 UITableViewCell 时获取触摸坐标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1276988/

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