swift - 快速获取触摸的各种坐标
问题描述
我试图在 swift 4 的 UIView 中触摸时获取各个点的坐标。我已经看过关于类似问题的另一篇文章,但该代码只允许注册第一次触摸。我会很感激一些帮助。谢谢。
解决方案
所以,我也能够找到我的问题的答案:我在 UIViewController 中使用下面的代码在不同位置触摸时获取一个二维整数数组。感谢所有的帮助。
var positionArray = Array(repeating: Array(repeating: 0, count: 2), count: 10)
var counter = 0
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if let touch = touches.first {
let position = touch.location(in: self.view)
let locx = Int(position.x)
let locy = Int(position.y)
positionArray[counter] = [locx, locy]
print(positionArray[counter])
counter = counter + 1
}
}
推荐阅读
- java - 在 Docker 中找不到合适的驱动程序
- elixir - 运行 Elixir exq 工作人员时模块不可用
- node.js - Datadog Real User Monitoring 中断 IE11 上的节点服务器
- kivy - ScatterLayout 是重叠的按钮
- android - 在单个 Activity 应用程序中使用 Dagger 范围跨 Fragment 共享 ViewModel
- flutter - Flutter Build APK:失败 - 无法初始化类“org.codehaus.groovy.reflection.ReflectionCache”
- python-3.x - 带有不同输入到 url 输出的破折号按钮
- python - 我的不和谐机器人代码有问题,它一直显示相同的错误
- linux - 从 LinuxVM 返回值到 Azure Pipeline
- svelte - 在 svelte 中,如何将异步函数绑定到属性?