1

I'm developing an app that saves html files locally on iPhone file system, then load them in UIWebView. I want to be able to zoom or double tap programmatically on the UIWebView, I tried searching for javascript code, but I could only scroll.

I also tried the webview transform, but didn't work out for me. I found this method

sendAction:to:from:forEvent:

http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIApplication_Class/Reference/Reference.html#jumpTo_26

in the UIApplication class, that can send actions to controls.

Does anybody know how to send the double tap action programmatically to a UIWebView on a certain x,y?

Mat
  • 202,337
  • 40
  • 393
  • 406
Mina Mikhael
  • 2,825
  • 6
  • 27
  • 31

3 Answers3

2

get the UIWebview's subview which is a UIScrollview

UIScrollView *sview = [[webview subviews] objectAtIndex:0];

Then use zoom methods on that.

maxpower
  • 1,203
  • 11
  • 20
1

This is the only way I could find to accomplish it: (specify your own sizes if you wish, i was attempting to zoom out after typing into a form field)

UIScrollView *sv = [[webViewView subviews] objectAtIndex:0]; [sv zoomToRect:CGRectMake(0, 0, sv.contentSize.width, sv.contentSize.height) animated:YES];

Captnwalker1
  • 679
  • 7
  • 16
0

To get double tap from UIWebview u need to subclass the UIWindow and use the method,

- (void)sendEvent:(UIEvent *)event {
    NSLog(@"tap detect");
    NSArray *allTouches = [[event allTouches] allObjects];
    UITouch *touch = [[event allTouches] anyObject];
    UIView *touchView = [touch view];

    if (touchView && [touchView isDescendantOfView:urWebview]) {
        //
        // touchesBegan
        //

        if(touch.tapCount==2){
            //
            // doubletap
            //
        }
    }
}

From this subclass of UIWindow use a delegate or Notification to catch the tap on your class.

Naveen Shan
  • 9,192
  • 3
  • 29
  • 43