iOs 方向宽度和高度小于应有的值
iOs orientation widht and height are smaller than it sould be
我有一个问题 运行 我在 iOs real 设备上的离子应用程序(在 iPhone 4 和 iPad 上测试第 4 代)。在 android 手机、平板电脑和 iOs 模拟器上一切正常。
(这是我正在使用的方向插件:cordova-plugin-screen-orientation)
我的应用程序被锁定在纵向模式,通过单击一个按钮,我转到另一个锁定横向模式的页面。 (目前一切顺利)
当我点击后退按钮 return 到纵向页面时,它旋转并处于纵向模式,但 window 宽度和高度完全混乱。
我尝试了其他主题中的许多配置,但其中 none 对我有用:
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, target-densityDpi=device-dpi" /> <!-- Works on android -->
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, target-densityDpi=device-dpi, user-scalable=no" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
我也注意到纵向页面的初始宽度和高度是:
[Log] Window height = 480 width = 320
比在横向页面上:
[Log 2] Window height = 320 width = 480
最后,当我返回肖像页面时,我看到了这个:
[Log 3] Window height = 640 width = 160
对于这两种方法,这些日志是相同的:
window.innerHeight / document.documentElement.clientHeight
window.innerWidth / document.documentElement.clientWidth
这里的这个主题是相关但未回答的:Whosebug。com/questions/18835784/iphones-orientation-change-back-to-portrait-breaks-sites-zoom
页面截图:
Page 1 in portrait mode but with width problems
非常感谢,提前!
我终于设法解决了这个问题。这是我的解决方法:
打开 XCode 中的 iOs 项目。
然后在 MainViewController.m
中编辑以下函数
- (void)webViewDidFinishLoad:(UIWebView*)theWebView
{
// Black base color for background matches the native apps
theWebView.backgroundColor = [UIColor blackColor];
theWebView.scalesPageToFit = true;
theWebView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
return [super webViewDidFinishLoad:theWebView];
}
构建并享受!
我有一个问题 运行 我在 iOs real 设备上的离子应用程序(在 iPhone 4 和 iPad 上测试第 4 代)。在 android 手机、平板电脑和 iOs 模拟器上一切正常。
(这是我正在使用的方向插件:cordova-plugin-screen-orientation)
我的应用程序被锁定在纵向模式,通过单击一个按钮,我转到另一个锁定横向模式的页面。 (目前一切顺利) 当我点击后退按钮 return 到纵向页面时,它旋转并处于纵向模式,但 window 宽度和高度完全混乱。
我尝试了其他主题中的许多配置,但其中 none 对我有用:
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, target-densityDpi=device-dpi" /> <!-- Works on android -->
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, target-densityDpi=device-dpi, user-scalable=no" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
我也注意到纵向页面的初始宽度和高度是:
[Log] Window height = 480 width = 320
比在横向页面上:
[Log 2] Window height = 320 width = 480
最后,当我返回肖像页面时,我看到了这个:
[Log 3] Window height = 640 width = 160
对于这两种方法,这些日志是相同的:
window.innerHeight / document.documentElement.clientHeight
window.innerWidth / document.documentElement.clientWidth
这里的这个主题是相关但未回答的:Whosebug。com/questions/18835784/iphones-orientation-change-back-to-portrait-breaks-sites-zoom
页面截图:
Page 1 in portrait mode but with width problems
非常感谢,提前!
我终于设法解决了这个问题。这是我的解决方法:
打开 XCode 中的 iOs 项目。
然后在 MainViewController.m
- (void)webViewDidFinishLoad:(UIWebView*)theWebView
{
// Black base color for background matches the native apps
theWebView.backgroundColor = [UIColor blackColor];
theWebView.scalesPageToFit = true;
theWebView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
return [super webViewDidFinishLoad:theWebView];
}
构建并享受!