我有一个UIViewController,在里面我有3个UIWebView.我以编程方式向我的webViews添加了向左滑动.现在我可以刷卡,但只需3页然后再重复一次.我想增加我的currentPage并将其添加到我的webView3,但我不知道该怎么做.
你能给我一些提示吗?我真的有这方面的问题!
这是我的代码:
- (void)viewDidLoad { [super viewDidLoad]; NSLog(@"test view"); NSURL *url = [NSURL fileURLWithPath:[ [ NSBundle mainBundle ] pathForResource: @"Name/Name1" ofType:@"html" ]]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; [webView2 loadRequest:request]; [webView2 bringToFront]; NSURL *url = [NSURL fileURLWithPath:[ [ NSBundle mainBundle ] pathForResource: @"Name/Name2" ofType:@"html" ]]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; [webView3 loadRequest:request]; UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeftAction:)]; swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft; swipeLeft.delegate = self; [self.view addGestureRecognizer:swipeLeft]; } - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { return YES; }
currentPage是一个整数,在开头它是0.我的问题是我应该如何将我的currentPage添加到webView3,以便当我滑动它增加我的页面?
- (void)swipeLeftAction:(id)ignored { NSLog(@"Swipe Left"); UIWebView *temp = webView2 ; webView2 = webView3; webView3 = webView; webView = temp; [webView2 bringToFront]; currentPage++; }
提前致谢!
****编辑:**
解决方法
根据这篇文章(
Does UIGestureRecognizer work on a UIWebView?)的信息,看起来手势识别器和网络视图并不总是很好地结合在一起,原因是因为webview自己的手势识别器.也许最好的方法是在webview中添加链接,触摸时使用自己的方案来增加currentPage
-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType { if ( [[[inRequest URL] absoluteString] hasPrefix:@"mySchemeIncrementPage:"] ) { currentPage++; NSLog(@"CURRENT PAGE COUNT: %i",currentPage); return NO; } }