ios - 触摸物体内部的位置

标签 ios swift cocoa-touch location uitouch

当我尝试使用以下代码行时:

 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/

相关文章:

ios - UIScrollView 的 RTL 支持

ios - Facebook 的最低权限-登录 Parse.com

swift - 尝试解包 UIImage 时意外发现 nil

ios - TableViewController 中 SearchBar 中的取消按钮需要双击

ios - 在 Xcode 项目清理构建文件夹后,Images.xcassets 停止工作 - iOS

ios - 如何 subview 相机 View ?

ios - 如何阻止 tabbarcontrol 中的 uitableview 与状态栏重叠?

objective-c - 我应该返回静态 UIImage 还是返回副本?

objective-c - 异步任务完成后加载 PageViewController

iphone - 当我触摸按钮外部并拖动到按钮上时,如何使 UIButton 获得功能?