如何在没有uigesturerecognizer的情况下在or窗口或uiview上获得触摸位置,目的是在极低的延迟下获得触摸位置,因为调度器可以延迟触摸触发事件
发布于 2017-08-30 17:44:41
您需要创建UIView的子类并覆盖UIResponder (UIView的超类)方法touchesBegan(_:with:)。有关here方法的信息,请参阅文档。
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if let touch = touches.first {
// Get the touch location in THIS VIEW's coordinate system:
let locationInThisView = touch.location(in: self)
// Get the touch location in the WINDOW's coordinate system
let locationInWindow = touch.location(in: nil)
}
}另外,确保您的视图将属性isUserInteractionEnabled设置为true。
发布于 2017-08-30 18:04:58
在您的UIView子类中覆盖下面的方法。
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let point = touches.first?.location(in: self)
print("location: ", point ?? CGPoint.zero)
}https://stackoverflow.com/questions/45956981
复制相似问题