gpt4 book ai didi

ios - 获取触摸标识符

转载 作者:行者123 更新时间:2023-11-28 06:18:45 26 4
gpt4 key购买 nike

我试图在整个 touchesBegantouchesMovedtouchesEnded 中识别触摸。

在将 UITouch(整套)打印到控制台时,我注意到开头有一个字符串,它似乎对屏幕上的每个手指都保持不变。

[<UITouch: 0x100d362e0> phase: ...

如何检索此属性?

最佳答案

我不是 100% 确定你在问什么,但我认为你可以以此为起点来跟踪独特的触摸实例,尽管我不确定如果我们不创建触摸事件,它会有多可靠.

import UIKit

class ViewController: UIViewController {

var touches: [UITouch] = []

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
self.touches.append(contentsOf: touches)
}

override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
touches.forEach {
let index = self.touches.index(of: $0)
print(String.init(describing: index))
}
}

override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
touches.forEach {
let index = self.touches.index(of: $0)
print(String.init(describing: index))
}
}
}

关于ios - 获取触摸标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44328286/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com