【问题标题】:Increase Pages After Each Swipe Objective-C每次滑动后增加页面 Objective-C
【发布时间】:2012-10-28 00:18:54
【问题描述】:

我有一个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 中获得这种增加?**

【问题讨论】:

  • 你还在努力解决这个问题吗?

标签: objective-c ipad uiswipegesturerecognizer


【解决方案1】:

根据这篇文章 (Does UIGestureRecognizer work on a UIWebView?) 的信息,看起来手势识别器和 webviews 并不总是很好地结合在一起,原因是 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;
  }
}

【讨论】: