Swift 如何使用tochesBegind()方法作为类的扩展?
如何向类中添加touchesbreated()方法 以下是我的方法:Swift 如何使用tochesBegind()方法作为类的扩展?,swift,sprite-kit,extension-methods,Swift,Sprite Kit,Extension Methods,如何向类中添加touchesbreated()方法 以下是我的方法: override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { for touch in touches{ let locationUser = touch.location(in: self) }} override func touchsbegind(touch:Set,带有事
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches{
let locationUser = touch.location(in: self)
}}
override func touchsbegind(touch:Set,带有事件:UIEvent?){
接触{
让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")
}
}
扩展类{
覆盖open func ToucheSBegind(Touchs:Set,带有事件:UIEvent?){
super.touchesbeated(touches,with:event)
接触{
让locationUser=touch.location(in:self)
}
打印(“触摸开始”)
}
}