ios - UIPanGestureRecognizer - Best way to stop an object moving past a boundary -


i've got view within navigation controller.

i adding subview view , offsetting origin height covers half screen (with other half overflowing off out bottom of screen). want able drag view upwards stopped when hits bottom of navigation bar , stopped when dragged down when hits origin offset point.

i'm using uipangesturerecognizer handle dragging of view , able achieve desired effect using 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 view moving side side , stop moving past either top , bottom 'boundary', however, there still slight movement when trying drag past one.

is there better way can completely prevent @ moving past boundaries?


Comments