如何在 appcelerator 中隐藏幻灯片菜单?

How can I hide slide menu in appcelerator?

我正在使用 appcelerator 构建应用程序。我也在构建一个自定义幻灯片菜单。因此,如果您单击按钮,幻灯片菜单会从左到右出现。

今天晚些时候我有这个固定宽度的菜单。为了隐藏这个菜单,我在 -width.

左边设置了一个 属性

现在我想用百分比设置菜单的宽度。但是我不知道怎么隐藏菜单。

所以这是我的 css 文件:

"#main_menu": {
    layout: "vertical",
    scrollType: "vertical",
    showVerticalScrollIndicator: true,
    top: 0,
    left: 0,
    width: "55%",
    height: Ti.UI.FILL,
    backgroundColor: "#70C662",
}

这是我的js文件

var menu_width = (Ti.Platform.displayCaps.platformWidth/2);
main_menu = Alloy.createController("_main_menu", args).getView();
$.sidebar.left = -menu_width;

但是menu_width的尺寸是不正确的,因为他的值是180,我的智能手机不可能有360px的尺寸。

如果您的菜单视图的宽度设置为 55%,则需要存储该百分比的 dp 版本。

"#main_menu": {
    width: "55%"
}

设备宽度:

var width = Ti.Platform.displayCaps.platformWidth;
//update this on orientation change

隐藏菜单:

$.main_menu.left = show ? 0 : -parseInt(width * 0.55));

如果设备宽度为360,则菜单宽度为198,隐藏时左侧值为-198

不要忘记在方向更改时更新值。