【问题标题】:Sencha Touch 2 button enable slide navigationSencha Touch 2 按钮启用滑动导航
【发布时间】:2018-04-05 03:02:30
【问题描述】:

我已经成功实现this幻灯片导航库。我可以将主视口滑入和滑出以显示和隐藏视口左侧的导航。

但是,我无法通过单击按钮找到隐藏和显示导航的方法。如何将现有的幻灯片导航绑定到按钮单击操作?

更新:

我尝试向 Main.js 添加自定义栏是在名为 CustomBar 的类中扩展 TitleBar。然后我通过 Main.js 中的 xtype 使用它。下面的代码显示了我的 Main.js 代码以及幻灯片导航库的配置:

    Ext.define('RT.view.Main', {
    extend: 'Ext.ux.slidenavigation.View',
    xtype: 'main',

    requires: [
        'Ext.TitleBar',
        // 'Ext.Video'
    ],

    config: {

        fullscreen: true,
        // slideSelector: 'x-toolbar',
        slideSelector: '',
        containerSlideDelay: 10,
        selectSlideDuration: 200,
        itemMask: true,
        /*slideButtonDefaults: {
            selector: 'toolbar'
        },*/
        listPosition: 'left',
        list: {
            maxDrag: 300,
            width: 200,
            items: [
                {
                    xtype: 'toolbar',
                    docked: 'top',
                    ui: 'light',
                    title: {
                        title: 'Menu',
                        centered: false,
                        width: 200,
                        left: 0,
                    },
                    items: [{
                        docked: 'top',
                        xtype: 'searchfield',
                        placeHolder: 'search',
                        width: 180
                    }]
                }
            ]
        },
        slideButton: true,
        slideButton: {
            selector: 'toolbar'
        },

        defaults: {
            style: 'background: red',
            xtype: 'container',
        },
/****************************************************/

        items: [
            {
                title: 'Welcome',
                iconCls: 'home',

                styleHtmlContent: true,
                scrollable: true,

                items: {
                    docked: 'top',
                    xtype: 'custombar',
                },

                html: [
                    "You've just generated a new Sencha Touch 2 project. What you're looking at right now is the ",
                    "contents of <a target='_blank' href=\"app/view/Main.js\">app/view/Main.js</a> - edit that file ",
                    "and refresh to change what's rendered here."
                ].join("")
            },
            {
                title: 'Messages',
                xtype: 'messages',
                iconCls: 'user',
            },
            {
                title: 'Sections',
                xtype: 'sections'
            },
            {
                title: 'submenu#1',
                html: 'submenu#1',
                group: 'Group 2',
            },
            {
                title: 'submenu#2',
                html: 'submenu#2'
            },
            {
                title: 'submenu#3',
                html: 'submenu#3'
            },
        ]
    }
});

我的customBar.js代码如下:

Ext.define('RT.view.CustomBar',{
        extend: 'Ext.TitleBar',
        xtype: 'custombar',

        config:{

            title: 'TESTING ...',
            items: [
                {
                    // name: 'BTNslidenav',
                    iconMask: true,
                    iconCls: 'list',
                    ui: 'plain',
                },
                {
                    iconMask: true,
                    // iconCls: 'user',
                    iconCls: 'star',
                    ui: 'plain',
                    align: 'right'
                }
            ]

        }// config
    });

这个 customBar 代码被 Views 静态使用。我的 LIST 组件使用不同的解决方案来获取 NavigationBar 并向其添加组件以生成与 CustomBar 相似的外观栏。

我需要将来自 CustomBar.js 的预先存在的 LIST 图标按钮与幻灯片导航功能建立联系 - 这样我就可以拖动或单击图标来显示/隐藏导航菜单。

更新#2

按照您在下面的更新和我的previous 问题中的指示,我实施的将我的 LIST 后退按钮放置在与我的自定义导航相同的工具栏中的解决方案不再有效。下图显示了我的结果:

我已经成功地使用以下代码来检测消息和部分列表视图,获取导航栏并将我的图标放入栏中。 我的想法是在列表图标上使用监听器来显示/隐藏菜单。但是,由于没有监听器,只有 slideButton 配置,所以我的代码是多余的:

Ext.define('RT.controller.BarGenerator', {
    extend: 'Ext.app.Controller',

    config: {
        refs: {
            messagesView: 'messages',
            sectionsView: 'sections'
        },
        control: {
            'sections': {
                initialize: 'generateBarSections'
            },
            'messages': {
                initialize: 'generateBarMessages'
            },
        }
    },

    //called when the Application is launched, remove if not needed
    launch: function(app) {

    },
    generateBarSections: function(list, record){
        console.log('LOADING ICONS AND CUSTOMIZING BAR!');
        navigationview = this.getSectionsView().getNavigationBar();
        navigationview.add(
            {
                // name: 'BTNslidenav',
                id: 'BTNslidenav',
                iconMask: true,
                iconCls: 'list',
                ui: 'plain',
            },
            {
                id: 'BTNuser',
                iconMask: true,
                iconCls: 'user',
                ui: 'plain',
                align: 'right'
            }
        );
    },
    generateBarMessages: function(list, record){
        console.log('LOADING ICONS AND CUSTOMIZING BAR!');
        navigationview = this.getMessagesView().getNavigationBar();
        navigationview.add(
            {
                slideButton: {
                    selector: "custombar"
                },
                // name: 'BTNslidenav',
                id: 'BTNslidenav',
                iconMask: true,
                iconCls: 'list',
                ui: 'plain',
            },
            {
                id: 'BTNuser',
                iconMask: true,
                iconCls: 'user',
                ui: 'plain',
                align: 'right'
            }
        );
    }
});

【问题讨论】:

    标签: button navigation sencha-touch-2 slide


    【解决方案1】:

    Ext.ux.slidenavigation.View 带有滑动按钮功能。 您只需要指定按钮的位置即可。

    您可以使用容器填充 Ext.ux.slidenaviagtion.View 的 items 数组。这些容器有一个属性slideButton,您可以在其中定义一个选择器,该选择器用于查找应插入按钮的组件。

    items : [
        {
            xtype : 'container',
            group : 'my first group',
            slideButton :
            {
                selector : 'toolbar'
            },
            items :
            [
                {
                    xtype : 'toolbar',
                    itemId : 'start_toolbar',
                    title : 'first view',
                    docked : 'top'
                },
                {
                    xtype : 'start'
                }
            ]
        },
        {
            xtype : 'container',
            group : 'my first group',
            slideButton :
            {
                selector : 'toolbar'
            },
            items :
            [
                {
                    xtype : 'toolbar',
                    title : 'second view',
                    docked : 'top'
                },
                {
                    xtype : 'anotherview'
                }
            ]
        }
    ]
    

    在示例中,Ext.ux.slidenavigation.View 的 items 数组包含 2 个容器。一个容器总是包含两个组件。我要显示的工具栏和实际视图。 slideButton config 属性定义按钮插入到带有 xtype 工具栏的组件中。

    更新:

    感谢您提供一些代码。我已经重新排列了你的代码,所以它适合我的例子。

    Ext.define('RT.view.CustomBar',{
            extend: 'Ext.TitleBar',
            xtype: 'custombar',
    
            config:{
    
                title: 'TESTING ...',
                items: [
                    {
                        iconMask: true,
                        // iconCls: 'user',
                        iconCls: 'star',
                        ui: 'plain',
                        align: 'right'
                    }
                ]
    
            }// config
        });
    

    首先,我已从您的自定义栏中删除了您的按钮。幻灯片导航将为您创建按钮。

    Ext.define('RT.view.Main', {
        extend: 'Ext.ux.slidenavigation.View',
        xtype: 'main',
    
        requires: [
            'Ext.TitleBar'
        ],
    
        config: {
            fullscreen: true,
            containerSlideDelay: 10,
            selectSlideDuration: 200,
            itemMask: true,
            listPosition: 'left',
            list: {
                maxDrag: 300,
                width: 200,
                items: [
                    {
                        xtype: 'toolbar',
                        docked: 'top',
                        ui: 'light',
                        title: {
                            title: 'Menu',
                            centered: false,
                            width: 200,
                            left: 0,
                        },
                        items: [{
                            docked: 'top',
                            xtype: 'searchfield',
                            placeHolder: 'search',
                            width: 180
                        }]
                    }
                ]
            },
            slideButton: true,
    
    
    /****************************************************/
            slideButtonDefaults: {
                iconMask: true,
                iconCls: 'list',
                ui: 'plain'
            },
            items: [
                {
                    xtype: "container",
                    group: "first group",
                    title: 'Welcome',
                    iconCls: 'home',
                    slideButton: {
                        selector:"custombar"
                    },
                    items: [
                        {
                                docked: 'top',
                                xtype: 'custombar',
                        },
                        {
                            styleHtmlContent: true,
                            scrollable: true,
                            html: [
                                "You've just generated a new Sencha Touch 2 project. What you're looking at right now is the ",
                                "contents of <a target='_blank' href=\"app/view/Main.js\">app/view/Main.js</a> - edit that file ",
                                "and refresh to change what's rendered here."
                            ].join("")
                        }
                    ]
                },
                {
                    xtype: "container",
                    group: "first group", 
                    title: 'Messages',
                    iconCls: 'user',
                    slideButton: {
                        selector: "custombar"
                    },
                    items: [
                        {
                                docked: 'top',
                                xtype: 'custombar',
                        },
                            {
                            xtype: 'messages'
                            }
                    ]
                }
            ]
        }
    });
    

    由于滑动导航会为您创建滑动按钮,您可以使用slideButtonDefaults进行自定义。

    幻灯片导航的items数组是重要的部分。 它现在包含两个容器。这意味着您会在侧边导航中获得两个条目。这些容器中的每一个都包含您的自定义栏和您在点击侧导航中的条目时实际想要显示的视图。

    每个包装容器都定义了滑动按钮在其子视图中的放置位置。这是由

    slideButton: {
      selector: 'custombar'
    }
    

    就是这样。

    更新#2

    这是因为您现在有多个工具栏。测试工具栏被插入到将由幻灯片导航显示的每个容器中。另一个工具栏来自位于幻灯片导航容器内的导航视图。

    有一些“修复”它的方法。

    首先,您可以在导航视图工具栏处于活动状态时隐藏它,并显示导航视图中的第一个视图。重要的是,此视图是永远不会有逻辑前身的视图。因此,永远不会有任何理由在该级别设置后退按钮。当您开始在导航视图中导航并向其推送越来越多的视图时,您可以隐藏“测试”工具栏。问题是:在每个子视图中都有滑动按钮是否重要,或者仅在顶视图中具有它是否足够好。考虑一下:工具栏中的许多按钮太多了,可能会使用户感到困惑。滑动导航仍然可以打开。

    或者您根本不使用自定义栏,而是自定义导航视图的标题栏。幻灯片导航的 items 数组如下所示:

    items: [
                {
                    xtype: "container",
                    group: "first group",
                    title: 'Welcome',
                    iconCls: 'home',
                    slideButton: {
                        selector:"titlebar"
                    },
                    items: [
                        {
                            xtype: "navview"
                        }
                    ]
                },
                {
                    xtype: "container",
                    group: "first group", 
                    title: 'Messages',
                    iconCls: 'user',
                    slideButton: {
                        selector: "tilebar"
                    },
                    items: [
                        {
                            xtype: 'navView2'
                        }
                    ]
                }
            ]
    

    但请注意,当您开始推送视图时,导航标题栏中(停靠在左侧)中有两个按钮。

    【讨论】:

    • 再次感谢马丁。我会尽快调查的
    • 嗨,马丁。请原谅我的无知,但我不明白您的示例代码将如何帮助解决我的问题。所以,我已经用代码更新了我的问题,这应该有助于更好地解释事情——如果你能抽出更多时间的话。
    • 马丁,非常感谢。我检查了你对我的代码所做的调整,这一切都说得通,我将我的部分视图添加到 Main.js。但是,您帮助我解决的上一个问题重新浮出水面。我指的是 LIST 项目详细信息视图中的双工具栏。我在 UPDATE#2 下添加了信息
    • 关于您的 PS 问题:我从 miamicoder.com/sencha-touch-tutorials 开始。这是一个很棒的教程。我经常查阅 sencha 文档,即使它们非常糟糕,有时甚至是错误的。但这是开始阅读他们的代码的好时机。有时你只需要这样做......所以基本上我经历了很多尝试和错误;)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多