[英]iphone uiwebview programmatic zoom
我正在开发一个将html文件本地保存在iPhone文件系统上的应用程序,然后将其加载到UIWebView中。 我希望能够以编程方式在UIWebView上进行缩放或双击,我尝试搜索javascript代码,但只能滚动。
我也尝试了webview转换,但对我来说没有用。 我发现这种方法
sendAction:to:from:forEvent:
在UIApplication类中,可以将操作发送到控件。
有人知道如何以编程方式将双击动作发送到某个x,y上的UIWebView吗?
获取UIWebview的子视图,即UIScrollview
UIScrollView *sview = [[webview subviews] objectAtIndex:0];
然后在其上使用缩放方法。
这是我能找到的唯一方法:(如果您愿意,请指定您自己的尺寸,我在输入表单字段后尝试缩小)
UIScrollView *sv = [[webViewView subviews] objectAtIndex:0]; [sv zoomToRect:CGRectMake(0, 0, sv.contentSize.width, sv.contentSize.height) animated:YES];
要从UIWebview双击,您需要继承UIWindow并使用方法,
- (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
//
}
}
}
在UIWindow的此子类中,使用委托或通知来捕获类上的点击。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.