Пример #1
0
CATabBarItem* CATabBarItem::create(std::string title, CAImage* image, int tag)
{
    CATabBarItem* item = new CATabBarItem();
    if (item && item->init(title, image, tag))
    {
        item->autorelease();
        return item;
    }
    CC_SAFE_DELETE(item);
    return NULL;
}
Пример #2
0
bool CATabBarController::initWithViewControllers(const std::vector<CAViewController*>& viewControllers, CABarVerticalAlignment var)
{
    CAViewController::init();

    do
    {
        CC_BREAK_IF(viewControllers.size() == 0);
        m_pViewControllers.insert(m_pViewControllers.begin(), viewControllers.begin(), viewControllers.end());

        std::vector<CATabBarItem*> items;

        for (unsigned int i=0; i<m_pViewControllers.size(); i++)
        {
            CAViewController* view = m_pViewControllers.at(i);
            view->retain();
            view->m_pTabBarController = this;
            if (view->getTabBarItem() == NULL)
            {
                const char* title = CCString::createWithFormat("item%d",i)->getCString();
                CATabBarItem* item = CATabBarItem::create(title, NULL);
                item->setTag(i);
                view->setTabBarItem(item);
            }
            items.push_back(view->getTabBarItem());
        }

        m_pTabBar = CATabBar::create(items);
        m_pTabBar->retain();
        m_pTabBar->setAnchorPoint(CCPointZero);
        m_pTabBar->setDelegate(this);

        m_pContainer = new CAScrollView();
        m_pContainer->initWithFrame(CCRectZero);
        m_pContainer->setScrollEnabled(false);
        m_pContainer->setBounces(false);
        m_pContainer->setShowsHorizontalScrollIndicator(false);
        m_pContainer->setShowsVerticalScrollIndicator(false);

    }
    while (0);

    m_eTabBarVerticalAlignment = var;

    return true;

}
Пример #3
0
void CDNewsViewController::scrollViewHeaderBeginRefreshing(CrossApp::CAScrollView *view)
{
    std::map<std::string,
    std::string> key_value;
    key_value["tag"] = menuTag[urlID];
    key_value["page"]= "1";
    key_value["limit"]= "20";
    key_value["appid"]="10000";
    key_value["sign_method"]="md5";
    string tempSign = getSign(key_value);
    CCLog("sign===%s",tempSign.c_str());
    key_value["sign"] = tempSign;
    string tempUrl = "http://api.9miao.com/news/";
    CommonHttpManager::getInstance()->send_post(tempUrl, key_value, this,
                                               CommonHttpJson_selector(CDNewsViewController::onRequestFinished));
    CATabBarItem* item = this->getTabBarItem();
    CCLog("BadgeValue====%s",item->getBadgeValue().c_str());
    if (!item->getBadgeValue().empty()) {
        item->setBadgeValue("");
        this->setTabBarItem(item);
    }
}
Пример #4
0
bool CATabBarController::initWithViewControllers(const CAVector<CAViewController*>& viewControllers, CABarVerticalAlignment var)
{
    CAViewController::init();
    
    do
    {
        CC_BREAK_IF(viewControllers.size() == 0);
        m_pViewControllers = viewControllers;
        
        std::vector<CATabBarItem*> items;
        
        for (unsigned int i=0; i<m_pViewControllers.size(); i++)
        {
            CAViewController* view = m_pViewControllers.at(i);
            if (view->getTabBarItem() == NULL)
            {
                char title[8];
                sprintf(title, "item%d", i);
                CATabBarItem* item = CATabBarItem::create(title, NULL);
                item->setTag(i);
                view->setTabBarItem(item);
            }
            items.push_back(view->getTabBarItem());
            view->m_pTabBarController = this;
        }
        
        m_pTabBar = CATabBar::create(items);
        m_pTabBar->retain();
        m_pTabBar->setDelegate(this);
        
    }
    while (0);
    
    m_eTabBarVerticalAlignment = var;
    
    return true;
    
}
Пример #5
0
void CATabBarController::viewDidLoad()
{
    std::vector<CATabBarItem*> items;
    
    for (unsigned int i=0; i<m_pViewControllers.size(); i++)
    {
        CAViewController* view = m_pViewControllers.at(i);
        if (view->getTabBarItem() == NULL)
        {
            char title[8];
            sprintf(title, "item%d", i);
            CATabBarItem* item = CATabBarItem::create(title, NULL);
            item->setTag(i);
            view->setTabBarItem(item);
        }
        items.push_back(view->getTabBarItem());
        view->m_pTabBarController = this;
    }
    
    m_pTabBar = CATabBar::create(items, DSize(this->getView()->getBounds().size.width, 0), m_eTabBarVerticalAlignment);
    this->getView()->addSubview(m_pTabBar);
    m_pTabBar->setDelegate(this);
    
    DRect container_rect = this->getView()->getBounds();
    
    DPoint tab_bar_rectOrgin = DPointZero;
    if (m_bTabBarHidden)
    {
        tab_bar_rectOrgin = this->getTabBarTakeBackPoint();
    }
    else
    {
        tab_bar_rectOrgin = this->getTabBarOpenPoint();
        
        container_rect.size.height -= m_pTabBar->getFrame().size.height;
        if (m_eTabBarVerticalAlignment == CABarVerticalAlignmentTop)
        {
            container_rect.origin.y = m_pTabBar->getFrame().size.height;
        }
    }
    
    DSize container_view_size = container_rect.size;
    container_view_size.width *= m_pViewControllers.size();
    
    m_pContainer = CAPageView::createWithFrame(container_rect, CAPageViewDirectionHorizontal);
    m_pContainer->setBackgroundColor(CAColor_clear);
    m_pContainer->setPageViewDelegate(this);
    m_pContainer->setScrollViewDelegate(this);
    m_pContainer->setScrollEnabled(m_bScrollEnabled);
    m_pContainer->setDisplayRange(true);
    this->getView()->addSubview(m_pContainer);
    
    CAVector<CAView*> views;
    for (int i=0; i<m_pViewControllers.size(); i++)
    {
        CAView* view = new CAView();
        views.pushBack(view);
        view->release();
    }
    m_pContainer->setViews(views);
    
    if (m_pTabBarBackgroundImage)
    {
        m_pTabBar->setBackgroundImage(m_pTabBarBackgroundImage);
    }
    else
    {
        m_pTabBar->setBackgroundColor(m_sTabBarBackgroundColor);
    }
    
    
    if (m_pTabBarSelectedBackgroundImage)
    {
        m_pTabBar->setSelectedBackgroundImage(m_pTabBarSelectedBackgroundImage);
    }
    else
    {
        m_pTabBar->setSelectedBackgroundColor(m_sTabBarSelectedBackgroundColor);
    }
    
    
    if (m_pTabBarSelectedIndicatorImage)
    {
        m_pTabBar->setSelectedIndicatorImage(m_pTabBarSelectedIndicatorImage);
    }
    else
    {
        m_pTabBar->setSelectedIndicatorColor(m_sTabBarSelectedIndicatorColor);
    }
    
    
    m_pTabBar->setTitleColorForNormal(m_sTabBarTitleColor);
    m_pTabBar->setTitleColorForSelected(m_sTabBarSelectedTitleColor);
    
    if (m_bShowTabBarSelectedIndicator)
    {
        m_pTabBar->showSelectedIndicator();
    }
    
    m_pTabBar->setFrameOrigin(tab_bar_rectOrgin);
    
    
    m_pTabBar->setSelectedAtIndex(m_nSelectedIndex);
    this->renderingSelectedViewController();
}