【问题标题】:Closing/Opening Ionic menu during screen orientation在屏幕定向期间关闭/打开 Ionic 菜单
【发布时间】:2015-12-21 13:48:58
【问题描述】:

我是 Ionic 框架的新手。有没有办法在横向模式下打开菜单,在变为纵向模式时将其关闭,反之亦然,类似于 Hiding the Ionic Framework Header based on screen orientation

通过使用,

window.addEventListener("orientationchange", function(){

});

我可以检测到方向变化,但找不到隐藏/显示菜单的方法。有没有办法使用 CSS 来做到这一点?

/* portrait */
@media screen and (orientation:portrait) {

}
/* landscape */
@media screen and (orientation:landscape) {

}

如果两者都可能,那么处理这种情况的首选方法是什么?

【问题讨论】:

    标签: android ios css ionic-framework


    【解决方案1】:

    您可以使用服务$ionicSideMenuDelegate 以编程方式打开或关闭菜单。

    .controller('AppCtrl', function($scope, $ionicSideMenuDelegate) {
    //                                        ˆˆˆˆ injected ˆˆˆˆ 
    
      window.addEventListener("orientationchange", function(){
        $ionicSideMenuDelegate.toggleLeft(window.orientation !== 0);
      });
    
    })
    

    记得在你的控制器中注入服务$ionicSideMenuDelegate。在这个例子中,我在AppCtrl 中注入了$scope$ionicSideMenuDelegate

    这适用于 iOS 和 Android!

    【讨论】:

    • 如何将服务注入控制器?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-30
    • 1970-01-01
    相关资源
    最近更新 更多