ios - Recognize two fingers swipe down gesture in UITableView -
i want add 2 fingers swipe , down gestures in uitableview. idea scroll through cells using 1 finger pan gesture , other action using 2 fingers swipe up/down gestures. i'd achieve similar experience tweetbot's night mode toggle: https://vine.co/v/hf5j1y7hubt
this code:
func setupgesturerecognizer() { swipeup = uiswipegesturerecognizer(target: self, action: "handleswipe") swipedown = uiswipegesturerecognizer(target: self, action: "handleswipe") swipeup.direction = uiswipegesturerecognizerdirection.up swipedown.direction = uiswipegesturerecognizerdirection.down swipeup.numberoftouchesrequired = 2 swipedown.numberoftouchesrequired = 2 self.tableview.pangesturerecognizer.maximumnumberoftouches = 1 self.tableview.pangesturerecognizer.requiregesturerecognizertofail(swipeup) self.tableview.pangesturerecognizer.requiregesturerecognizertofail(swipedown) self.tableview.addgesturerecognizer(swipeup) self.tableview.addgesturerecognizer(swipedown) } func handleswipe() { print("swiped!") let alert = uialertcontroller(title: "gesture recognizer", message: "swipe detected", preferredstyle: uialertcontrollerstyle.alert) let action = uialertaction(title: "ok", style: uialertactionstyle.default, handler: nil) alert.addaction(action) self.presentviewcontroller(alert, animated: true, completion: nil) } setupgesturerecognizer() called in viewdidload()
i alert when swipe or down 2 fingers when use pan gesture there's significant lag before table moves. it's time pan gesture needs wait make sure swipe gesture fails:
it makes more sense me set requiregesturerecognizertofail this: swipedown.requiregesturerecognizertofail(self.tableview.pangesturerecognizer) when tried swipe gesture didn't work @ all. think there's problem pangesturerecognizer failing. why doesn't fail when use 2 fingers if explicitly stated should accept maximumnumberoftouches = 1 ?
do know how make these gestures interact each other?
remove these lines
self.tableview.pangesturerecognizer.requiregesturerecognizertofail(swipeup) self.tableview.pangesturerecognizer.requiregesturerecognizertofail(swipedown) set gesture delegate swipeup , swipedown
swipedown.delegate = self swipeup.delegate = self and handle gesture delegate failure dynamically.
func gesturerecognizer(gesturerecognizer: uigesturerecognizer, shouldrecognizesimultaneouslywithgesturerecognizer othergesturerecognizer: uigesturerecognizer) -> bool { return true } return true always. take care whether swipe being handled or pan.
Comments
Post a Comment