0

I'm writing an iPad app in which I make intense use of a UIWebView inside a UIViewController.

I'm tying a few actions to swipe gesture recognizers. They detect both left and right swipes. Since my web view scrolls up and down, it is very easy to try a horizontal swipe and get the webview to scroll up or down a bit, what ends up failing the gesture recognizer.

So is there any way to avoid this behavior? Maybe to detect the start of the horizontal swipe and lock the UIWebView vertical position?

Thanks!

Aloha Silver
  • 1,394
  • 17
  • 35

1 Answers1

0

You could intercept the continueTrackingWithTouch:withEvent call and selectively return NO - or perhaps even cancel the swipe.

E.g. something like

(BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
{
    if (... too diagonal to my taste) .. 
          return (NO);
    return [super continueTrackingWithTouch:touch withEvent:event];
}

where 'too diagonal' could be as simple as checking if the begin spot & current spot are too non-ortogonal (e.g. dx = firstX - lastX, dy = firstY - lastY; len2 = dx * dx + dy * dy - which is only allowed some ratio relative to area = dx * dy.

Thanks,

Dw.

Dirk-Willem van Gulik
  • 7,566
  • 2
  • 35
  • 40
  • Trouble is, the UISwipeGestureRecognizer itself cancels the tracking when it finds the gesture too diagonal. I want exactly the opposite. Will this method override the automatic canceling? – Aloha Silver Nov 15 '10 at 00:21
  • No - as the [super ..] will in above still return 'NO'. However you could be naughty - and simply change above to always return a YES and see what happens ? – Dirk-Willem van Gulik Nov 15 '10 at 00:25
  • Still no good. I'm experimenting with some alternatives, like using a UIScrollView instead of gesture recognition. This has brought me a few new issues, reported here: http://stackoverflow.com/questions/4200563/loadhtmlstring-wont-fire-while-uiscrollview-is-scrolling. The behavior is not exactly the same, but both represent a few challenges that I have not been able to overcome so far. So I'll have to keep trying. Anyway, thanks for the help, Dirk. – Aloha Silver Nov 17 '10 at 01:09