检测UIWebview中的滑动手势 [英] detect Swipe gesture in UIWebview
本文介绍了检测UIWebview中的滑动手势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 iPhone的新手
开发人员,
我制作了epub阅读器,并在我的每一页中加载了epub webview
I made epub reader and loaded each page of epub in my webview
我想要的是,当用户执行右滑动手势
第二次然后我要导航到新页面,当用户第一次执行右滑动手势
时,我不想做任何事情。
What i want to is, when user does right swipe gesture
2nd time then i want to navigate to new page, i do not want to do anything when user does right swipe gesture
for first time.
UISwipeGestureRecognizer * swipeRight
有什么方法,比如,
if(swipeRight.touch.count > 2)
{
// do this
}
任何帮助都会被评估。
Any help will be appriciated.
提前致谢!
编辑
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
float scrollViewHeight = scrollView.frame.size.height;
float scrollContentSizeHeight = scrollView.contentSize.height;
float scrollOffset = scrollView.contentOffset.y;
if (scrollOffset == 0)
{
swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeftAction:)];
swipeUp.direction = UISwipeGestureRecognizerDirectionUp;
swipeUp.numberOfTouchesRequired=2;
swipeUp.delegate = (id<UIGestureRecognizerDelegate>)self;
swipeUp.cancelsTouchesInView=YES;
[_webview addGestureRecognizer:swipeUp];
}
else if (scrollOffset + scrollViewHeight == scrollContentSizeHeight)
{
swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRightAction:)];
swipeDown.direction = UISwipeGestureRecognizerDirectionDown;
swipeDown.numberOfTouchesRequired=2;
swipeDown.delegate = (id<UIGestureRecognizerDelegate>)self;
swipeDown.cancelsTouchesInView=YES;
[_webview addGestureRecognizer:swipeDown];
}
推荐答案
只需附上UIGestureRecognizer子类到该视图并保持调用...
Just attach UIGestureRecognizer subclass to that view and hold on for calls...
UISwipeGestureRecognizer* rightSwipeRecognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(someAction)];
rightSwipeRecognizer.numberOfTouchesRequired = 2;
rightSwipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
rightSwipeRecognizer.cancelsTouchesInView = YES;
[self.webView addGestureRecognizer:rightSwipeRecognizer]; // add in your webviewrightSwipeRecognizer
这篇关于检测UIWebview中的滑动手势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文