Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
IOS上的IONIC/AngularJs-更改屏幕方向时innerWidth和innerHeight错误_Ios_Iphone_Angularjs_Cordova_Cordova Plugins - Fatal编程技术网

IOS上的IONIC/AngularJs-更改屏幕方向时innerWidth和innerHeight错误

IOS上的IONIC/AngularJs-更改屏幕方向时innerWidth和innerHeight错误,ios,iphone,angularjs,cordova,cordova-plugins,Ios,Iphone,Angularjs,Cordova,Cordova Plugins,这是我第一次问有关stackoverflow的问题,所以我会尽量具体一些。谢谢你的帮助 目前,我正在为Androïd和IOS开发一个带有角度/离子溶液的应用程序 事实上,我已经开发了一项服务,使用cordova插件屏幕方向1.4.2版本插件来更改我的屏幕方向,以获得一些视图。事实上,这在两个操作系统上都非常有效。但我还需要在完成时捕捉设备的宽度和高度 这就是我的问题。在Android上,一切都正常,但在IOS上,当我改变方向时,似乎总是捕捉到旧的值。(如果我更改为横向,我将捕捉以前的纵向方向值)

这是我第一次问有关stackoverflow的问题,所以我会尽量具体一些。谢谢你的帮助

目前,我正在为Androïd和IOS开发一个带有角度/离子溶液的应用程序

事实上,我已经开发了一项服务,使用cordova插件屏幕方向1.4.2版本插件来更改我的屏幕方向,以获得一些视图。事实上,这在两个操作系统上都非常有效。但我还需要在完成时捕捉设备的宽度和高度

这就是我的问题。在Android上,一切都正常,但在IOS上,当我改变方向时,似乎总是捕捉到旧的值。(如果我更改为横向,我将捕捉以前的纵向方向值)

我尝试了不同的算法,比如更简单的:改变方向,完成后捕捉值

目前,我正在尝试与一个观察者,为同样的结果

这是我的密码:

class WindowService extends Service {
constructor($resource,$config, $window, Watcher) {
    'ngInject';
    super();

    this.orientations = {
        1:"portrait",
        2:"landscape"
    }

    //imported library
    this.md = new MobileDetect($window.navigator.userAgent);
    // if it's a tablet Android, md.tablet() != null && md.os() == 'AndroidOS'
    // if it's an iPad md.tablet() == 'iPad'
    // if it's an iPhone md.mobile() == 'iPhone'
    // if it's an Android phone, md.phone() != null && md.os() == 'AndroidOS'
    console.log("md > ", this.md.mobile());

    this.maxHeight = "100vh";
    this.maxWidth = "100vw";
    if (this.isAndroid()){
        this.maxHeight = $window.innerHeight + "px";
        this.maxWidth = $window.innerWidth + "px";

        this.maxHeightWatcher = Watcher.watch(() => $window.innerHeight, innerHeight => {
            this.maxHeight = $window.innerHeight + "px";
            this.maxWidth = $window.innerWidth + "px";
        });
    }
}

setOrientation(){
    this.invoke(($window) => {
        if ($window.screen.unlockOrientation){
            $window.screen.unlockOrientation();
            if ((this.md.phone() != null && this.md.os() == 'AndroidOS') || this.md.mobile() == 'iPhone'){
                $window.screen.lockOrientation('portrait');
            }else if ((this.md.tablet() != null && this.md.os() == 'AndroidOS') || this.md.tablet() == 'iPad'){
                $window.screen.lockOrientation('landscape');
            }else {
                $window.screen.lockOrientation('landscape');
            }
        }
    });
}

//THIS S THE FUNCTION I CALL
changeOrientation(orientationId){
    this.invoke(($window) => {
        this.lockScreenOrientation($window, orientationId).then(res => {
            console.log("changeOrientation > ", res);
        }).catch(err => {
            console.log("changeOrientation > ", err);
        });
    });
}

lockScreenOrientation($window, orientationId){
    if (this.orientations[orientationId] != undefined){
        if (this.orientations[orientationId] != $window.screen.orientation){
            if ($window.screen.unlockOrientation){
                    $window.screen.unlockOrientation();
                    console.log("lockOrientation > ", $window.screen.lockOrientation(this.orientations[orientationId]));
                    return Promise.resolve(this.orientations[orientationId]);
            }else{
                return Promise.reject("[ERROR] cordova-plugin-screen-orientation hadn't been loaded.")
            }
        }else{
            return Promise.resolve(this.orientations[orientationId]);
        }
    }else{
        return Promise.reject("[ERROR] The orientation specified is Unknown.")
    }
}

getDevice(){
    if ((this.md.phone() != null && this.md.os() == 'AndroidOS')){
        return "Android Smartphone";
    }else if (this.md.mobile() == 'iPhone'){
        return "iPhone";
    }else if ((this.md.tablet() != null && this.md.os() == 'AndroidOS')){
        return "Android Tablet";
    }else if (this.md.tablet() == 'iPad'){
        return "iPad";
    }else
        return "Unknown";
}

isSmartphone(){
    if ((this.md.phone() != null && this.md.os() == 'AndroidOS') || this.md.mobile() == 'iPhone'){
        return true;
    }
    return false;
}

isTablet(){
    if ((this.md.tablet() != null && this.md.os() == 'AndroidOS') || this.md.tablet() == 'iPad')
        return true;
    return false;
}

isIOS() {
    if (this.md.mobile() == 'iPhone' || this.md.tablet() == 'iPad')
        return true;
    return false;
}

isAndroid() {
    if ((this.md.phone() != null && this.md.os() == 'AndroidOS')
        || (this.md.tablet() != null && this.md.os() == 'AndroidOS'))
        return true;
    return false;
}

getMaxHeight(){
    return this.maxHeight;
}

getMaxWidth(){
    return this.maxWidth;
}
} 服务。注册(WindowsService)


....

类观察者只是angular的基本观察者的一个小小扩展。它的工作原理是一样的

[编辑]抱歉,我忘了指定一些内容:正如您在js代码中看到的,在构造函数方法中,如果是IOS,我只需将100vh fr设置为高度,将100vw设置为宽度。我得到了相同的结果:从纵向到横向的变化保持了纵向尺寸值

<ion-side-menu-content drag-content="false" ng-controller="HeaderController" style="height:{{view.maxHeight}};width: {{view.maxWidth}};"> 

    ....

</ion-side-menu-content>