I want to limit my imageview to specific y-coordinates, but every-time I drag it over or below the 2-coordinates, the view gets stuck and doesn't move again. Also, if I drag fast enough, the imageView goes above or below the coordinates that i limited it to.
@IBAction func handlePan(_ gesture: UIPanGestureRecognizer) {
// 1
let translation = gesture.translation(in: view)
// 2
guard let gestureView = gesture.view else {
return
}
if gestureView.center.y >= 161 && gestureView.center.y <= 561 {
gestureView.center.y = gestureView.center.y + translation.y
gesture.setTranslation(.zero, in: view)
}
// 3
gesture.setTranslation(.zero, in: view)
}