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

时间:2012-11-07 21:08:51

标签: objective-c ipad uiswipegesturerecognizer

我有一个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++;
 }

提前致谢!

****编辑:**

此当前页面未连接到任何webView,如何在webView中获得此增加?**

1 个答案:

答案 0 :(得分:0)

根据这篇文章的信息(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;
  }
}