开发者

UISwipeGestureRecognizer perpendicular to UIWebView Scrolling: How to avoid diagonal swipes?

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 beh开发者_JAVA百科avior? Maybe to detect the start of the horizontal swipe and lock the UIWebView vertical position?

Thanks!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜