tags:

views:

356

answers:

1

Hello i have search everything and i didn't figure this out!

I have a tab bar controller with 5 navigation controlls, in one of the navigation control, i have a view, with a table view inside, and when i click that item i push a new view, that view have

  view
     -webview
     -view

i create that second view(is transperant) because i need to handle a single tap to hide my toolbar and navigation bar, and the webview was eating all the touches! I put that view and implement on the view controller

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
 UITouch* touch = [touches anyObject];
 if(touch.tapCount == 2){
  [NSObject cancelPreviousPerformRequestsWithTarget:self];
 } 
 [[wv.subviews objectAtIndex:0] touchesBegan:touches withEvent:event];
 [super touchesBegan:touches withEvent:event];
}

-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
 [[wv.subviews objectAtIndex:0] touchesMoved:touches withEvent:event];
 [super touchesMoved:touches withEvent:event];
}

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
 UITouch* touch = [touches anyObject];
 if(touch.tapCount == 1){
  [self performSelector:@selector(hideBars) withObject:nil afterDelay:0.3];
 }
 [[wv.subviews objectAtIndex:0] touchesEnded:touches withEvent:event];
 [super touchesEnded:touches withEvent:event];
}

-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
 [[wv.subviews objectAtIndex:0] touchesCancelled:touches withEvent:event];
 [super touchesCancelled:touches withEvent:event];
}

wv is my UIWebView IBOutlet now i can get the the touches in my controller and send them to my webview. So i thought everything was working, i'm able to scroll, but now when i have links i'm not able to click them. And the webview is detecting the links i have made that test. So any other way to implements this to get the touches in the links, or i should change this workaround to hide the toolbars so i can have the full functionability of the webview? Thks for the help in advance.

A: 

Ok, i didn't solve my problem but i get a workaround for this situation.

UIWebView get all touches and don't pass them to other views, only if you disable the user interaction, and we don?t want that. And you can't override touchesBegan and that stuff in a implementation of a UIWebView. So what's the solution?

As i mention, if you put a UIView on top of the UIWebView you can get the touches, and pass them to the webview, but that is not perfect also because you cant click on links, and zoom and all that stuff, you are only able to scroll! and that suck's!

Soooo, my workaround is:

Get ride of the UIView that is on top of the UIWebView, and now the magic with some help of javascript!

In your html you need to do some tricks, first: Create a div envolving all the page, just after the body, and set padding and margin to 0! and put this on div:

What this does is, create and event when you tap on the div, if the div is fill the entire webview, whenever you click you call that event, and that event change the address and if you set your view controller as delegate of the webview, the delegate will call this metod:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    NSString* scheme = request.URL.scheme;
    NSString* query = request.URL.query;
    NSLog(@"%@, %@", scheme, query);
    if ([scheme compare:@"file"]==0){
     if ([query isEqualToString:@"hideBars"]){
      [self hideBars];
      return NO;
     }
    }

    return YES;
}

that's where the magic happens, the query string will come with the hideBars string if you click anywhere! So it will call my hideBars function! if you click on a link the query will come with the link adress so it works too! zoom doesn't call this metod so its all great!

If you have any question just mail me to goncalo.falcao @ waveweb2 . com

Gonçalo Falcão