如何将 touchesBegan() 方法添加到我的类中?
这是我的方法:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches{
let locationUser = touch.location(in: self)
}}
最佳答案
您可以使用类扩展在其中添加方法,如果您 类是 UIView 或 UIWindow 的子类:
extension YourClass {
override open func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
for touch in touches{
let locationUser = touch.location(in: self)
}
print("touchesBegan")
}
}
关于swift - 如何使用 tochesBegan() 方法作为类的扩展?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46981652/