简体   繁体   中英

iphone uiwebview programmatic zoom

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?

get the UIWebview's subview which is a UIScrollview

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

Then use zoom methods on that.

这是我能找到的唯一方法:(如果您愿意,请指定您自己的尺寸,我在输入表单字段后尝试缩小)

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM