ios - UITableView with UIPanGestureRecognizer causes "jumping" touch -
the case: https://github.com/artworkad/ios_jumping_y.git

the container
class containercontroller: uiviewcontroller { @iboutlet weak var container: uiview! @iboutlet weak var foregroundtopspace: nslayoutconstraint! @iboutlet weak var foregroundbottomspace: nslayoutconstraint! } the container connected uitableviewcontroller right.
what want do
the user scrolls table , when reaches top want move table down same movement. change top/bottom space of container view. causes table jump.
class maincontroller: uitableviewcontroller, uigesturerecognizerdelegate { var panrecognizer: uipangesturerecognizer! var gotstart: bool = true var starttouch: cgpoint! override func viewdidload() { super.viewdidload() self.tableview.bounces = false self.panrecognizer = self.tableview.pangesturerecognizer self.panrecognizer.addtarget(self, action: "pan:") self.tableview.addgesturerecognizer(self.panrecognizer) } func gesturerecognizer(gesturerecognizer: uigesturerecognizer, shouldrecognizesimultaneouslywithgesturerecognizer othergesturerecognizer: uigesturerecognizer) -> bool { return true } func pan(rec:uipangesturerecognizer){ if let parent = self.parentviewcontroller as? containercontroller { var y = self.tableview.contentoffset.y var touch = rec.locationinview(self.view) // jumping y println(touch.y) if y == -64 { if self.gotstart || y < -64 || y > -64 { self.starttouch = touch self.gotstart = false } else { if rec.state == .changed { var changedverticalheight = (self.starttouch.y - touch.y)*(-1) if changedverticalheight <= parent.view.frame.size.height && touch.y >= changedverticalheight { parent.foregroundtopspace.constant = changedverticalheight parent.foregroundbottomspace.constant = -changedverticalheight } } else if rec.state == .ended { parent.foregroundtopspace.constant = 0 parent.foregroundbottomspace.constant = 0 self.gotstart = true } } } } } } result:

any ideas whats wrong? there has problem container view because when move table view directly there no jumping.
i going clarify things in answer before put complete code
you can use function
scrollviewwillenddraggingknowcontentoffsetgoing to, see below code :override func scrollviewwillenddragging(scrollview: uiscrollview, withvelocity velocity: cgpoint, targetcontentoffset: unsafemutablepointer<cgpoint>) { println(targetcontentoffset.memory.y) }you can use function
scrollviewdidenddeceleratingknow when scroll has finished it.
then can merge 2 above tips accomplish goal in following way:
class maincontroller: uitableviewcontroller { var position : cgfloat! override func viewdidload() { super.viewdidload() } override func scrollviewwillenddragging(scrollview: uiscrollview, withvelocity velocity: cgpoint, targetcontentoffset: unsafemutablepointer<cgpoint>) { // save contentoffset go position = targetcontentoffset.memory.y } override func scrollviewdidenddecelerating(scrollview: uiscrollview) { // if reach top or more top when user move scroll if (position < 0) { var = scrollview.contentoffset.y + 213 scrollview.setcontentoffset(cgpoint(x: 0, y: to), animated: true) } } // default table stuff, not related problem /* here comes rest of code of tableview */ } i remove code project relative pangesturerecognizer , bounces test.
in line var = scrollview.contentoffset.y + 213 can add position variable or value want, put 213 test down movement.
i hope you.
Comments
Post a Comment