Cordova Plugin Screen Orientation 1.4.2 (for IOS) 不会改变视口宽度
Posted
技术标签:
【中文标题】Cordova Plugin Screen Orientation 1.4.2 (for IOS) 不会改变视口宽度【英文标题】:Cordova Plugin Screen Orientation 1.4.2 (for IOS) does not change the viewport width 【发布时间】:2016-08-25 19:56:45 【问题描述】:将插件更新到 1.4.2 版本后,屏幕锁定开始在 iPad 上工作。在纵向模式下,我尝试通过执行screen.lockOrientation('landscape-primary')
将屏幕锁定为横向模式。屏幕确实会旋转到横向模式。但它不占据整个屏幕宽度。旋转似乎不会改变视口的宽度和高度。
纵向视图中的屏幕尺寸:
Height: 1004 px
Width: 768px
执行screen.lockOrientation('landscape-primary')
后
横向视图中的屏幕尺寸(仍然相同):
Height: 1004 px
Width: 768px
以下是我的配置:
cordova version: 6.0.0
ios version: 9.3.4
screen plugin version: 1.4.2
更新:
我面临的问题与此处提到的问题相同: https://github.com/gbenvenuti/cordova-plugin-screen-orientation/issues/1
我试过放下面的配置,还是不行。
<platform name="ios">
<preference name="Orientation" value="all" />
</platform>
元视口中没有width=device-width
或height=device-height
。
【问题讨论】:
你找到解决方案了吗:( 【参考方案1】:cordova-plugin-screen-orientation 似乎没有调整 Web 视图的大小。我遇到了同样的问题。
解决此问题的快速技巧是调用另一个插件,该插件可以正确实现 webview 的大小调整。例如:安装 cordova-plugin-statusbar 并在锁定状态栏后快速隐藏/显示状态栏。繁荣!您的方向已锁定,并且您拥有正确的 webview 大小。
screen.lockOrientation('portrait');
StatusBar.hide();
StatusBar.show();
【讨论】:
我找到解决这个问题的最佳答案。但是,这确实是一个很大的“黑客”……如果可以,请在 ipad 设备上添加条件。使用离子:if(ionic.Platform.isIPad() ...【参考方案2】:根据@Rolando 的回答,这就是我所做的,因为它必须在 lockOrientation 和 statsuBar 刷新之间有短暂的延迟:
var interval;
screen.lockOrientation('landscape');
if(ionic.Platform.isIPad())
// Ipad only, check every 10ms if screen size is refresh or do it with statusBar
interval = $interval(testLandscapeWidth, 10);
else
// Other ios and android
doProcess();
function testLandscapeWidth()
if(parseInt($window.innerWidth) < parseInt($window.innerHeight))
StatusBar.hide();
StatusBar.show();
else
$interval.cancel(interval); // When scree size is refresh, cancel interval
doProcess();
function doProcess()
// Your process
我使用间隔而不是计时器来确保它执行多次并成功,仅 1 次并且刷新失败。我尝试了 10ms、100ms、500ms,取决于 ipad 健康是否快,有时状态栏刷新不成功。所以,有了间隔,就是这样。
【讨论】:
以上是关于Cordova Plugin Screen Orientation 1.4.2 (for IOS) 不会改变视口宽度的主要内容,如果未能解决你的问题,请参考以下文章
Cordova 的插件(屏幕方向/应用程序版本)不适用于 Ionic 5 / Angular 11
离子屏幕方向 Cordova 插件在 iOS 环境中未锁定为纵向模式
无法隐藏默认的cordova-splash screen ionic 3
未获得有关 cordova 推送通知的完整信息 (cordova-plugin-firebasex)
cordova cordova-plugin-statusbar StatusBarOverlaysWebView 不工作