我想在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");
}
}
我有两个问题: -
关于此代码,我不知道在我的代码中调用userDidScrollWebView
方法的位置,以便定期获得有关滚动的更新。
另一种方法,我想可能是我可以将Swipe Gesture放在Web View上,但这不起作用。
答案 0 :(得分:1)
这是我在UIWebView中实现滑动手势的方式。
ViewController.h
协议添加到ViewDidLoad
在UISwipeGestureRecognizer * swipeGestureDown = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeDown)];
swipeGestureDown.numberOfTouchesRequired = 1;
swipeGestureDown.direction = UISwipeGestureRecognizerDirectionDown;
swipeGestureDown.delegate = self;
[self.webView addGestureRecognizer:swipeGestureDown];
方法中添加以下代码:
ViewController.m
在-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
中添加委托方法:
-(void)swipeDown
{
NSLog(@"swipe down in webView");
}
<preference name="orientation" value="landscape"></preference>
同样,您可以添加另一个手势以向上滑动。