检测手机横竖屏

1. cc.EGLView._getInstance().setResizeCallback(function() {
    var windowInnerHeight = window.innerHeight;
    var windowInnerWidth = window.innerWidth;
    if(windowInnerHeight>windowInnerWidth){
        alert("竖屏");
        //cc.view.setDesignResolutionSize(720, 1280, cc.ResolutionPolicy.SHOW_ALL);
    }else{
        alert("横屏");
        //cc.view.setDesignResolutionSize(1280, 720, cc.ResolutionPolicy.SHOW_ALL);
    }
});
2.window.addEventListener("orientationchange", function(event){
    if ( window.orientation == 180 || window.orientation == 0 )
    {
        alert("竖屏");
        
    }
    if( window.orientation == 90 || window.orientation == -90 )
    {
        alert("横屏");
        
    }
});

猜你喜欢

转载自blog.csdn.net/cleve_baby/article/details/76546643