【发布时间】:2011-07-23 21:55:02
【问题描述】:
我想在用户放大时增加UIWebView 的高度(如 iPhone 中的默认邮件应用程序)。
因此,我尝试使用下面的代码在 webview 中查找滚动视图并添加 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);
}
问题是我无法放大/缩小网页视图
但是NSLog 上的scrollViewDisEndZooming 方法显示
缩放 1.0
当我结束缩放时
而scrollViewDidZoom 方法没有显示任何内容。
我想检测 webview 的缩放比例以计算其在scrollViewDidZoom 上的高度。
我做错了什么? 请帮忙。
提前致谢。
【问题讨论】:
标签: iphone uiwebview uiscrollview zooming