zoukankan      html  css  js  c++  java
  • cocos代码研究(24)Widget子类PageView学习笔记

    理论基础

    PageView类又称Layout的管理器,可以让用户在多个Layout之间左右或者上下切换显示,继承自 Layout 。

    代码实践

    static PageView * create ()
    创建一个空的PageView。

    void addWidgetToPage (Widget *widget, ssize_t pageIdx, bool forceCreate)
    把一个widget添加到指定的PageView页中。

    void addPage (Layout *page)
    往PageView的最后插入一页。

    void insertPage (Layout *page, int idx)
    在指定位置插入一页。

    void removePage (Layout *page)
    从PageView中移除一页。

    void removePageAtIndex (ssize_t index)
    移除指定位置的页。

    void setDirection (Direction direction)
    变更容器翻页方向。

    Direction getDirection () const
    获取容器翻页方向。

    void removeAllPages ()
    移除PageView中所有页。

    void scrollToPage (ssize_t idx)
    滚动到一个指定的页。

    ssize_t getCurPageIndex () const
    获取当前显示页的索引号。

    void setCurPageIndex (ssize_t index)
    直接跳转至指定页面(非滚动)

    Vector< Layout * > & getPages ()
    获取所有页的列表。

    Layout * getPage (ssize_t index)
    获取指定的页。

    void addEventListenerPageView (Ref *target, SEL_PageViewEvent selector)
    添加一个页面切换时的回调函数,当页面切换时被调用。

    void addEventListener (const ccPageViewCallback &callback)
    添加一个页面切换时的回调函数,当页面切换时被调用。

    void setCustomScrollThreshold (float threshold)
    如果没有指定该值,pageView会在滚到页面一半时切换到下一页。

    float getCustomScrollThreshold () const
    请求设定的切换页面门限值。

    void setUsingCustomScrollThreshold (bool flag)
    是否使用用户设置的切换页面门限值。 如果设为false,那么pageView会在滚到页面一半时切换到下一页。

    bool isUsingCustomScrollThreshold () const
    请求是否使用用户自定义页面切换门限值。

    实例:

            // Create the page view
            PageView* pageView = PageView::create();
            pageView->setContentSize(Size(240.0f, 100.0f));
            Size backgroundSize = background->getContentSize();
            pageView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
                                       (backgroundSize.width - pageView->getContentSize().width) / 2.0f,
                                       (widgetSize.height - backgroundSize.height) / 2.0f +
                                       (backgroundSize.height - pageView->getContentSize().height) / 2.0f + 20));
            
            int pageCount = 4;
            for (int i = 0; i < pageCount; ++i)
            {
                Layout* layout = Layout::create();
                layout->setContentSize(Size(240.0f, 130.0f));
                
                ImageView* imageView = ImageView::create("cocosui/scrollviewbg.png");
                imageView->setScale9Enabled(true);
                imageView->setContentSize(Size(240, 130));
                imageView->setPosition(Vec2(layout->getContentSize().width / 2.0f, layout->getContentSize().height / 2.0f));
                layout->addChild(imageView);
                
                Text* label = Text::create(StringUtils::format("page %d",(i+1)), "fonts/Marker Felt.ttf", 30);
                label->setColor(Color3B(192, 192, 192));
                label->setPosition(Vec2(layout->getContentSize().width / 2.0f, layout->getContentSize().height / 2.0f));
                layout->addChild(label);
                
                pageView->insertPage(layout,i);
            }
            
            _uiLayer->addChild(pageView);
            pageView->setName("pageView");
  • 相关阅读:
    I/O性能优化
    磁盘性能指标
    磁盘I/O工作原理
    文件系统工作原理
    Linux命令行工具之free命令
    内存性能优化
    内存工作原理
    内存中的Buffer和Cache的区别
    proc文件系统
    oracle 查询 LOB 字段大小
  • 原文地址:https://www.cnblogs.com/damowang/p/4865074.html
Copyright © 2011-2022 走看看