Increase Pages After Each Swipe Objective-C
Asked Answered
O

1

7

I have one UIViewController and inside it I have 3 UIWebView. I added swipe left to my webViews programatically. Right now I can swipe, but just 3 pages and then repeat again. I want to increase my currentPage and add this to my webView3, but I don't know how should I do that.

Would you please give me some hints? I really have problem in this part!

Here is my code:

- (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 is an integer and at the beginning it is 0. My question is how should I add my currentPage to webView3 so that when I Swipe it increase my pages?

 - (void)swipeLeftAction:(id)ignored
 {
NSLog(@"Swipe Left");
UIWebView *temp = webView2 ;
webView2 = webView3;
webView3 = webView;
webView = temp;

[webView2 bringToFront];
currentPage++;
 }

Thanks in advance!

****Edit:**

This current page is not connected to any webView, How Can I get this increase in my webView?**

Ossieossietzky answered 7/11, 2012 at 21:8 Comment(1)
Are you still working to resolve this issue?Marlee
M
0

Based on information from this post (Does UIGestureRecognizer work on a UIWebView?) it looks like gesture recognizers and webviews do not always play nice together, the reason being because of a webview's own gesture recognizers. Perhaps the best way would be to add links inside of your webview that when touched use your own scheme to increment 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;
  }
}
Marlee answered 8/11, 2012 at 19:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.