Handling swipe gesture on UIWebview

我是研究僧i 提交于 2019-12-13 04:29:28

问题


I want to load gmail and yahoo on two individual UIwebview's and pan/swipe between those two views. But the scroll/pan does not work since Gmail and Yahoo handle swipe gestures inside the browser for performing their own functionality. Like on Gmail swipe "Archive" is the action. For yahoo, on the swipe "Delete", "Mark favorite" etc are the features shown. I am able to successfully

Please let me know if my main controller can receive swipe events so that i can swipe/pan/scroll between those two web views. Also my app should support App store guide lines.

Regards, Prasad


回答1:


Following solution will work in this situation.
1. Take a UIView
2. Add smaller Webview as a subview to the UIview
3. Add swipe gesture Recognizer to UIView.
Now Panning on the View area will solve the problem and It will also support AppStore Guide Lines.

You can put an image showing the Arrow to swipe/pan.




回答2:


You can receive the swipe gestures within the main controller, then pass them as needed into the uiwebviews via javasacript. Here is an example:

    UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self  action:@selector(swipeRightAction:)];
    swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
    swipeRight.delegate = self;

    swipeRight.numberOfTouchesRequired = 1;
    swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
    swipeRight.delaysTouchesBegan = YES;
    [webView addGestureRecognizer:swipeRight];

Then...

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
     return YES;
}

- (void)swipeRightAction:(id)ignored
{

    // Send javascript into web view
[self.webView stringByEvaluatingJavaScriptFromString:@"alert('Swipe right');"];


    //[webView goBack]; // or just navigate back in web view
}


来源:https://stackoverflow.com/questions/18711208/handling-swipe-gesture-on-uiwebview

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!