I've got a view within a navigation controller.
I am then adding a subview to this view and offsetting its origin height so that it covers only half the screen (with the other half overflowing off out the bottom of the screen). I want to be able to then drag this view upwards but it get stopped when it hits the bottom of the navigation bar and similarly get stopped when dragged back down when it hits the origin offset point.
I'm using a UIPanGestureRecognizer
to handle the dragging of the view and am currently able to somewhat achieve my desired effect using the following code:
func handlePanGesture(recognizer: UIPanGestureRecognizer) {
let minX: CGFloat = recognizer.view!.frame.size.width/2
let maxX: CGFloat = minX
let minY: CGFloat = bottomNavbarY+recognizer.view!.frame.size.height/2
let maxY: CGFloat = pulloverOffset+recognizer.view!.frame.size.height/2
recognizer.view!.center = CGPointMake(min(max(minX,recognizer.view!.center.x),maxX), min(max(minY,recognizer.view!.center.y),maxY))
...
This prevents the view from moving side to side and does stop it from moving past either top and bottom 'boundary', however, there is still some slight movement when trying to drag it past one.
Is there a better way I can do this to completely prevent it at all from moving past the boundaries?