每次滑动后增加页面 Objective-C

7
我有一个UIViewController,里面有三个UIWebView。我已经通过编程的方式为我的webViews添加了左滑功能。现在我可以左滑浏览3页,然后重复。我想增加当前页数并将其添加到我的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++;
 }

提前感谢你!

****编辑:**

这个页面当前没有连接到任何webView,我该如何在我的webView中实现此增加?**


你还在努力解决这个问题吗? - propstm
1个回答

0
根据这篇文章(UIGestureRecognizer在UIWebView上工作吗?)提供的信息,手势识别器和Web视图并不总是能很好地协同工作,原因是由于Web视图自身的手势识别器。也许最好的方法是在您的Web视图中添加链接,当触摸时使用您自己的方案来增加当前页。
-(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;
  }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接