开发者

iOS: Can I intercept swipes on top of a UIWebView?

I want the user to be able to swipe left, right, upward and downward on a UIWebview, but I don't want the HTML/Javascript to process those swipes-- I want to do that myself.

Is that possible: To intercept just the swipes? I want 开发者_JAVA技巧the taps still to go through to the UIWebview.

Thanks.


Sure thing.
Just attach UIGestureRecognizer subclass to that view and hold on for calls...

    UISwipeGestureRecognizer* leftSwipeRecognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(someAction)];
    leftSwipeRecognizer.numberOfTouchesRequired = 1;
    leftSwipeRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
    leftSwipeRecognizer.cancelsTouchesInView = YES;
    [self.webView addGestureRecognizer:leftSwipeRecognizer];

there is some sample for left swipe gesture. You can set more with very similar approach...
Hope that helps.


If you add a UISwipeGestureRecognizer onto the UIWebview with

addGestureRecognizer: 

it will allow you to get those events. I believe the default is to only allow one recognizer at a time, but I'm not sure if that applies to individual gesture types or across all gesture types, so this may only be the first step in solving your problem.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜