当我尝试使用以下代码行时:
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch in touches {
let tap = touch as UITouch
let location = tap.locationInView(self.view)
print(location(
}
我无法获取选择器 View 内触摸的位置。有办法做到吗?
最佳答案
这就是我的做法..首先你需要为你的对象分配一个名称,然后在touchesBegan中你需要指定触摸的位置与对象相同
let location = (touch as! UITouch).locationInNode(self)
if let name = self.nodeAtPoint(location).name {
if name == "objectName" {
// do your code here
}
关于ios - 触摸物体内部的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32207350/