我寫一個自定義視圖控制器具有的WebView象下面這樣:UIWebView pich縮放工作在iPhone 5.0模擬器上,但不能在iPhone 4.3和iPad 4.3,5.0模擬器中工作?
@interface WebpageController : UIViewController<UIWebViewDelegate> {
UIWebView* webView;
//....
}
,它的構造函數:
-(id)init {
if (self = [super init]) {
webView=[[UIWebView alloc]init];
webView.delegate=self;
webView.scalesPageToFit = YES;
webView.multipleTouchEnabled = YES;
//.....
}
和我有3個功能zoomin,縮小和loadHTMLString到webView的下面:
//this is load HTML String function
// param: content --> HTML conten by inside <body> </body>
-(void) loadWebViewWithContent:(NSString*) content{
NSString * header = @"<meta name='viewport' content='width=device-width;initial-scale=1.0; user-scalable= yes;'/>";
NSString * html = [NSString stringWithFormat:@"<html>
<head>%@ </head>
<body> %@ </body>
</html>",header,content];
[webView loadHTMLString:html baseURL:nil];
}
//這些是放大和縮小功能
-(void) zoomIn {
for (UIScrollView *scroll in [self.webView subviews]) {
//Set the zoom level.
if ([scroll respondsToSelector:@selector(setZoomScale:animated:)]) {
NSLog(@"set ZoomScale work");
[scroll setZoomScale:2.0f animated:YES];
NSLog(@"zoomScale of SCROLLVIEW= %f",(scroll.zoomScale));
}
}
}
-(void) zoomOut {
for (UIScrollView *scroll in [self.webView subviews]) {
//Set the zoom level.
if ([scroll respondsToSelector:@selector(setZoomScale:animated:)]) {
NSLog(@"set ZoomScale work");
[scroll setZoomScale:0.5f animated:YES];
NSLog(@"zoomScale of SCROLLVIEW= %f",(scroll.zoomScale));
}
}
}
在主UI,我設置,當上ZoomIn按鈕用戶抽頭 - > webView的zoomIn由呼叫zoomIn函數(同樣爲縮小(ZoomOut))
一切正常,當我在iPhone 5.0模擬器測試(I xcode中使用4.2)。你可以捏縮放,zoomOut(也可以使用zoomIn,zoomOut按鈕)。 但是,當在iPhone 4.3和iPad測試(包括4.3和5.0)--->無事發生 - >的LOG表明:
* *設置ZoomScale工作
滾動型zoomScale = 1.00; --->我還設置其他值,但始終zoomScale = 1.00 - >無變化 **
什麼是錯我的代碼?我很困惑,請幫助我。 提前致謝。