如何在 swift 的视图中获取触摸的 X 和 Y 位置
Howto get X and Y Postion of touch in a view in swift
如何在 Swift 中获取 UIView 上触摸的 X 和 Y 位置?
我有一个 UIViewController 和一个 UIView。
是否可以进入 UIView 或我是否必须在 Controller 中处理触摸。
我在 Google 和其他网站上进行了搜索,但没有找到任何好的资源。 (我简直不敢相信)
我没有起点,所以我无法展示任何代码。
任何提示在哪里可以找到解决方案?
对于 UITouch,您有 locationInView
其中 return 触摸在特定视图上的位置。示例:
import UIKit
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
let touch = touches.anyObject() as UITouch
let point = touch.locationInView(self.view)
}
如何在 Swift 中获取 UIView 上触摸的 X 和 Y 位置? 我有一个 UIViewController 和一个 UIView。
是否可以进入 UIView 或我是否必须在 Controller 中处理触摸。
我在 Google 和其他网站上进行了搜索,但没有找到任何好的资源。 (我简直不敢相信) 我没有起点,所以我无法展示任何代码。
任何提示在哪里可以找到解决方案?
对于 UITouch,您有 locationInView
其中 return 触摸在特定视图上的位置。示例:
import UIKit
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
let touch = touches.anyObject() as UITouch
let point = touch.locationInView(self.view)
}