ImageView moves from one place to another place swift

@IBOutlet var imageV: UIImageView!

var lastLocation = CGPoint()
override func touchesBegan(_ touches: Set, with event: UIEvent?) {

if let touch = touches.first {
self.lastLocation = touch.location(in: self.view)
}

}

override func touchesMoved(_ touches: Set, with event: UIEvent?) {
if let touch = touches.first {
let location = touch.location(in:self.view)
self.imageV.center = CGPoint(x: (location.x - self.lastLocation.x) + self.imageV.center.x, y: (location.y - self.lastLocation.y) + self.imageV.center.y)
lastLocation = touch.location(in: self.view)
}
}
Previous
Next Post »