我希望在用户缩放时(如iPhone上的默认邮件应用程序),增加
问题是我无法在webview上缩放, 但是
UIWebView
的高度。
因此,我尝试了下面的代码来查找webview中的scrollview,并添加UIScrollViewDelegate
以使用scrollViewDidZoom
来检测缩放比例,在此方法中增加webview的高度。// MessageAppDelegate.h
@interface MessageAppDelegate : NSObject <UIApplicationDelegate,UIWebViewDelegate,UIScrollViewDelegate> {
UIWebView *webview;
UIScrollView *scrollview;
}
//MessageAppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
[self.window makeKeyAndVisible];
webview = [[UIWebView alloc] initWithFrame:CGRectMake(0, 150, 320, 100)];
webview.delegate = self;
webview.scalesPageToFit = YES;
webview.userInteractionEnabled = YES;
[webview loadHTMLString:@"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=6.0 user-scalable=yes\">test test" baseURL:nil];
[self.window addSubview:webview];
// Find scrollview in webview
for (UIView *view in webview.subviews) {
if ([view isKindOfClass:[UIScrollView class]]) {
// Get UIScrollView object
scrollview = (UIScrollView *) view;
scrollview.delegate = self;
}
}
return YES;
}
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale{
NSLog(@"scale %f",scale);
}
- (void)scrollViewDidZoom:(UIScrollView *)scrollView{
NSLog(@"scrollViewDidZoom %f",scrollview.zoomScale);
}
问题是我无法在webview上缩放, 但是
scrollViewDisEndZooming
方法的 NSLog
显示了
比例为1.0
当我结束缩放时
并且 scrollViewDidZoom
方法没有显示任何内容。
我想检测webview的缩放比例,以计算其在 scrollViewDidZoom
上的高度。
我做错了什么? 请帮忙。
提前感谢。