在我的 UITableView
子类中,我有一个在识别长按手势时调用的方法:
func longPressed(recognizer: UILongPressGestureRecognizer) {
let location = recognizer.locationInView(self)
print("location: \(location), \(frame.origin), \(bounds.origin)")
}
在这种情况下(红色圆圈是我点击的地方):
控制台打印:
location: (32.0, 277.5), (0.0, 50.0), (0.0, 261.5)
所以我的位置在边界坐标内?我需要 UITableView 中的绝对触摸位置,但不包括滚动。可能吗?
很快,这就是我对这里或多或少的期望:
location: \(32.0, 22.0) ...
最佳答案
View 的框架在父 View 坐标系中指定。所以你可以使用:
let locationInSuperView = recognizer.locationInView(self.superview)
或者你可以自己移除滚动偏移:
let contentOffset = self.contentOffset
let location = recognizer.locationInView(self)
let locationWithoutScroll = CGPoint( x: location.x - contentOffset.x,
y: location.y - contentOffset.y)
关于ios - 如何在 UITableView 框架中获取手势识别器的位置,而不是边界,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32646331/