我在 phonegap 上遇到了同样的问题,删除 device-width 并没有解决我的问题。
我不得不修改 Classes/MainViewController.m
我修改了:
- (void)webViewDidFinishLoad:(UIWebView*)theWebView
{
// Black base color for background matches the native apps
theWebView.backgroundColor = [UIColor blackColor];
return [super webViewDidFinishLoad:theWebView];
}
成为:
- (void)webViewDidFinishLoad:(UIWebView*)theWebView {
theWebView.backgroundColor = [UIColor blackColor];
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
if (version >= 7.0)
{
[self.webView stringByEvaluatingJavaScriptFromString:@"$('meta[name=viewport]').attr('content','width=device-width, initial-scale=.42 user-scalable=no');$('body').animate({'opacity':1},300)"];
}
return [super webViewDidFinishLoad:theWebView];
}
* 更新 *
- (void)webViewDidFinishLoad:(UIWebView*)theWebView
{
// Black base color for background matches the native apps
theWebView.backgroundColor = [UIColor blackColor];
// iPhone app zoom on iPad with iOS 7 fix
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
if (version >= 7.0)
{
[self.webView stringByEvaluatingJavaScriptFromString:@"if(!(navigator.userAgent.match(/iPhone/i)) && !(navigator.userAgent.match(/iPod/i))) {$('meta[name=viewport]').attr('content','width=device-width, initial-scale=.42 user-scalable=no');}"];
}
[self.webView stringByEvaluatingJavaScriptFromString:@"$('body').animate({'opacity':1},300)"];
return [super webViewDidFinishLoad:theWebView];
}
我将淡入代码移到 if 语句之外,否则 < iOS7 将保持不透明度 0
* 结束更新 *
我使用“版本”变量和 if 语句来定位 iOS 7。谢谢@leetvin
然后从放大缩小比例
最初在放大视图和缩小视图之间有一个跳跃,所以我在 css 中将 body 的不透明度设置为 0,并在调整大小后动画/淡入