Friday 15 August 2014

ios - Pan Gesture - Swipe Gesture Conflict -



ios - Pan Gesture - Swipe Gesture Conflict -

i’m trying create application duplicates ability of apple’s photos app (iphone) zoom, pan , scroll through photographic images. (i want utilize same controls when viewing pdfs , other documents.) got tap gesture show/hide navigation bar , swipe gesture scroll through images left right & vice versa. got pinch gesture zoom in , out, when added pan gesture move around within zoomed image, swipe gesture quit working.

i found potential solutions elsewhere on stackoverflow including utilize of shouldrecognizesimultaneouslywithgesturerecognizer, far have not been able resolve conflict. suggestions?

here's code:

func gesturerecognizer(uipangesturerecognizer: uigesturerecognizer, shouldrecognizesimultaneouslywithgesturerecognizer uiswipegesturerecognizer: uigesturerecognizer) -> bool { homecoming true } @ibaction func handlepinch(sender: uipinchgesturerecognizer) { sender.view!.transform = cgaffinetransformscale(sender.view!.transform, sender.scale, sender.scale) sender.scale = 1 } @ibaction func handlepan(sender: uipangesturerecognizer) { self.view.bringsubviewtofront(sender.view!) var translation = sender.translationinview(self.view) sender.view!.center = cgpointmake(sender.view!.center.x + translation.x, sender.view!.center.y + translation.y) sender.settranslation(cgpointzero, inview: self.view) } @ibaction func handleswiperight(sender: uiswipegesturerecognizer) { if (self.index == 0) { self.index = ((photos.count) - 1); } else { self.index--; } // requiregesturerecognizertofail(pangesture) setimage() }

you not want shouldrecognizesimultaneouslywithgesturerecognizer: (which allows 2 gestures happen simultaneously). that's useful if want to, example, simultaneously pinch , pan. simultaneous gestures not help in scenario panning , swiping @ same time. (if anything, recognizing simultaneously confuses situation.)

instead, might want found precedence of swipe , pan gestures (e.g. pan if swipe fails) requiregesturerecognizertofail:.

or better, retire swipe gesture exclusively , utilize solely pan gesture, which, if you're zoomed out interactive gesture navigate 1 image next, , if zoomed in, pans image. interactive pan gestures more satisfying ux, anyway; e.g., if swiping 1 photo next, able stop mid pan gesture , go back. if @ photos.app, it's using pan gesture swipe 1 image another, not swipe gesture.

ios swift uigesturerecognizer gesture

No comments:

Post a Comment