【问题标题】:Put Swipe Gesture over UIWebView to Get Scroll Direction in IOS将滑动手势放在 UIWebView 上以获取 IOS 中的滚动方向
【发布时间】:2015-06-16 04:13:08
【问题描述】:

我想在 webView 中获取滚动方向。我阅读了有关获取滚动方向的代码here。

-(void)userDidScrollWebView:(id)scrollPoint{
    // NSLog(@"scrolled:::");

    NSString *x1 = [webView stringByEvaluatingJavaScriptFromString: @"scrollX"];


    NSString *y1 = [webView stringByEvaluatingJavaScriptFromString: @"scrollY"];


    NSLog(@"scroll x=%@ y=%@", x1,y1);      

    if ([y1 isEqualToString: @"0"]) {
        NSLog(@"RELAOD ME");
    }   
}

我有 2 个问题:-

  1. 关于这段代码,我不知道在我的代码中哪里调用userDidScrollWebView 方法,以便定期更新滚动。

  2. 另一种方法,我想可能是我可以将滑动手势放在 Web 视图上,但这不起作用。

【问题讨论】:

    标签: ios xcode scroll uiwebview swipe


    【解决方案1】:

    这就是我在 UIWebView 中实现滑动手势的方式。

    1. 将<UIGestureRecognizerDelegate> 协议添加到ViewController.h
    2. 在ViewDidLoad方法中添加如下代码:

      UISwipeGestureRecognizer * swipeGestureDown = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeDown)]; swipeGestureDown.numberOfTouchesRequired = 1; swipeGestureDown.direction = UISwipeGestureRecognizerDirectionDown; swipeGestureDown.delegate = self; [self.webView addGestureRecognizer:swipeGestureDown];

    3. 在ViewController.m中添加Delegate方法:

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

    4. -(void)swipeDown { NSLog(@"swipe down in webView"); }

    同样,您可以添加另一个向上滑动的手势。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-18
      相关资源
      最近更新 更多