Xcode 在最新的swift中移动对象

Xcode 在最新的swift中移动对象,xcode,swift,Xcode,Swift,在最新版本的swift中,我将如何移动对象以跟随触摸。因此,如果你触摸物体,它将跟随你的手指直到你移开手指。你应该使用触摸开始和触摸移动方法 override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { for touch in touches { thing.center = (touch.locationInView(self.view)) }

在最新版本的swift中,我将如何移动对象以跟随触摸。因此,如果你触摸物体,它将跟随你的手指直到你移开手指。

你应该使用
触摸开始
触摸移动
方法

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {

    for touch in touches {

        thing.center = (touch.locationInView(self.view))

    }

}

override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {

    for touch in touches {

        thing.center = touch.locationInView(self.view)

    }
}
覆盖函数触摸开始(触摸:设置,withEvent事件:UIEvent?){
接触{
thing.center=(touch.locationInView(self.view))
}
}
覆盖功能触摸移动(触摸:设置,带事件:UIEvent?){
接触{
thing.center=touch.locationInView(self.view)
}
}

有关更多信息,请观看此。希望这能有所帮助。

现在这应该更有帮助了。