Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.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 如何使用tochesBegind()方法作为类的扩展?_Swift_Sprite Kit_Extension Methods - Fatal编程技术网

Swift 如何使用tochesBegind()方法作为类的扩展?

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,带有事

如何向类中添加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,带有事件: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)
}
打印(“触摸开始”)
}
}