Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在swift视图中获得触摸的X和Y位置_Swift_Events_Touch_Screen - Fatal编程技术网

如何在swift视图中获得触摸的X和Y位置

如何在swift视图中获得触摸的X和Y位置,swift,events,touch,screen,Swift,Events,Touch,Screen,如何在Swift中获取UIView上触摸的X和Y位置? 我有一个UIViewController和一个UIView 这是否可能进入UIView或我必须在控制器中处理触摸 我在谷歌和其他网站上搜索过,但没有找到任何好的信息来源。我简直不敢相信 我没有起点,所以我不能显示任何代码 在哪里找到解决方案有任何提示吗?对于UITouch,您有locationInView,它返回触摸在特定视图上的位置。例如: import UIKit override func touchesBegan(touches:

如何在Swift中获取UIView上触摸的X和Y位置? 我有一个UIViewController和一个UIView

这是否可能进入UIView或我必须在控制器中处理触摸

我在谷歌和其他网站上搜索过,但没有找到任何好的信息来源。我简直不敢相信 我没有起点,所以我不能显示任何代码

在哪里找到解决方案有任何提示吗?

对于UITouch,您有locationInView,它返回触摸在特定视图上的位置。例如:

import UIKit

override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
        let touch = touches.anyObject() as UITouch

        let point = touch.locationInView(self.view)
    }

谢谢你的帮助。我不明白。我应该在哪里通过你的密码?我尝试将其粘贴到UIViewController和UIView中。但在这两种情况下,它都无法识别。您必须导入UIKit。您只需将其粘贴到ViewControllerI中,我就可以看到主要问题。我显然使用了不同的swift版本。它将通过touchBeganTouches:Set、withEvent:UIEvent进行识别。谢谢你的帮助。