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://develope开发者_开发百科r.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.
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];
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.
精彩评论