首页 文章

Cordova插件屏幕方向1.4.2(对于IOS)不会更改视口宽度

提问于
浏览
2

将插件更新到版本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

Updates:

我面临的问题与这里提到的问题相同:https://github.com/gbenvenuti/cordova-plugin-screen-orientation/issues/1

我尝试了以下配置,仍然无法正常工作 .

<platform name="ios">
  <preference name="Orientation" value="all" />
</platform>

我在元视口中没有 width=device-widthheight=device-height .

enter image description here

2 回答

  • 0

    cordova-plugin-screen-orientation似乎没有调整Web视图的大小 . 我遇到了同样的问题 .

    一个可以解决这个问题的快速入侵就是调用另一个插件,该插件可以正确实现webview的大小调整 . 例如:安装cordova-plugin-statusbar并在锁定状态栏后快速隐藏/显示状态栏 . 繁荣!您的方向已锁定并且您具有正确的Webview大小 .

    screen.lockOrientation('portrait');     
    StatusBar.hide();
    StatusBar.show();
    
  • 1

    基于@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
    }
    

    我使用一个间隔,而不是一个计时器,以确保它做了很多时间和成功,这只是一次,并没有刷新 . 我尝试了10ms,100ms,500ms,依赖于ipad的 Health 状况是否快速,有时状态栏刷新没有成功 . 所以,有了间隔,它就是 .

相关问题