Пример #1
0
void CAAutoCollectionView::updateSectionHeaderAndFooterRects()
{
	DRect rect = this->getBounds();
	rect.origin = getContentOffset();

	for (int i = 0; i < m_rCollectionViewSection.size(); i++)
	{
		CollectionViewSection& cvs = m_rCollectionViewSection[i];

		CC_CONTINUE_IF(!rect.intersectsRect(cvs.rSectionRect));

		CAView* header = cvs.pSectionHeaderView;
		CAView* footer = cvs.pSectionFooterView;
		
		float headerHeight = cvs.nSectionHeaderHeight;
		float footerHeight = cvs.nSectionFooterHeight;

		if (header && m_bAlwaysTopSectionHeader)
		{
			DPoint p1 = rect.origin;
			p1.y = MAX(p1.y, cvs.rSectionRect.origin.y);
			p1.y = MIN(p1.y, cvs.rSectionRect.origin.y + cvs.rSectionRect.size.height
				- headerHeight - footerHeight);
			header->setFrameOrigin(p1);
		}
		if (footer && m_bAlwaysBottomSectionFooter)
		{
			DPoint p2 = DPointZero;
			p2.y = MIN(rect.origin.y + this->getBounds().size.height - footerHeight,
				cvs.rSectionRect.origin.y + cvs.rSectionRect.size.height - footerHeight);
			p2.y = MAX(p2.y, cvs.rSectionRect.origin.y + headerHeight);
			footer->setFrameOrigin(p2);
		}
	}
}
Пример #2
0
// [email protected]: 2015-03-08
void CANavigationController::popToRootViewControllerAnimated(bool animated)
{
    if (m_pViewControllers.size() == 1)
    {
        return ;
    }
    
    float x = this->getView()->getBounds().size.width;
    
    CAView* backContainer = m_pContainers.back();
    backContainer->setFrameOrigin(DPointZero);
    
    size_t index = 0;
    CAViewController* showViewController = m_pViewControllers.at(index);
    showViewController->viewDidAppear();
    
    CAView* showContainer = m_pContainers.at(index);
    showContainer->setVisible(true);
    showContainer->setFrameOrigin(DPoint(-x/2.0f, 0));
    
    {
        DPoint point = this->getNavigationBarNowPoint(showViewController);
        
        DRect rect = this->getView()->getBounds();
        rect.origin.y = point.y + m_tNavigationBarSize.height;
        rect.size.height = rect.size.height - rect.origin.y;
        m_pNavigationBars.at(index)->setFrameOrigin(point);
        
        CAView* secondContainer = m_pSecondContainers.at(index);
        secondContainer->setFrame(rect);
        
        showViewController->getSuperViewRect(secondContainer->getBounds());
    }
    
    CAApplication::getApplication()->getTouchDispatcher()->setDispatchEventsFalse();
    
    if (animated)
    {
        CAViewAnimation::beginAnimations("", NULL);
        CAViewAnimation::setAnimationDuration(0.25f);
        CAViewAnimation::setAnimationDelay(0.02f);
        CAViewAnimation::setAnimationCurve(CAViewAnimationCurveEaseOut);
        showContainer->setFrameOrigin(DPointZero);
        CAViewAnimation::commitAnimations();
        
        CAViewAnimation::beginAnimations("", NULL);
        CAViewAnimation::setAnimationDuration(0.25f);
        CAViewAnimation::setAnimationDelay(0.03f);
        CAViewAnimation::setAnimationCurve(CAViewAnimationCurveEaseOut);
        CAViewAnimation::setAnimationDidStopSelector(this, CAViewAnimation0_selector(CANavigationController::popToRootViewControllerFinish));
        backContainer->setFrameOrigin(DPoint(x, 0));
        CAViewAnimation::commitAnimations();
    }
    else
    {
        this->popToRootViewControllerFinish();
    }
}
Пример #3
0
void CANavigationController::ccTouchEnded(CATouch *pTouch, CAEvent *pEvent)
{
    CC_RETURN_IF(CAViewAnimation::areBeginAnimationsWithID("navigation_animation"));
    CC_RETURN_IF(m_pViewControllers.size() <= 1);
    
    float x = this->getView()->getBounds().size.width;
    size_t index = m_pViewControllers.size() - 2;
    CAViewController* lastViewController = m_pViewControllers.at(index);
    
    CAView* lastContainer = m_pContainers.at(index);
    lastContainer->setVisible(true);
    lastContainer->setTouchEnabled(true);
    
    CAView* backContainer = m_pContainers.back();
    backContainer->setTouchEnabled(true);
    
    CAApplication::getApplication()->getTouchDispatcher()->setDispatchEventsFalse();
    
    if (m_bPopViewController)
    {
        lastViewController->viewDidAppear();
        
        CAViewAnimation::beginAnimations("navigation_animation", NULL);
        CAViewAnimation::setAnimationDuration(0.25f);
        CAViewAnimation::setAnimationDelay(0.02f);
        CAViewAnimation::setAnimationCurve(CAViewAnimationCurveEaseOut);
        lastContainer->setFrameOrigin(DPointZero);
        CAViewAnimation::commitAnimations();
        
        CAViewAnimation::beginAnimations("navigation_animation2", NULL);
        CAViewAnimation::setAnimationDuration(0.25f);
        CAViewAnimation::setAnimationDelay(0.03f);
        CAViewAnimation::setAnimationCurve(CAViewAnimationCurveEaseOut);
        CAViewAnimation::setAnimationDidStopSelector(this, CAViewAnimation0_selector(CANavigationController::popViewControllerFinish));
        backContainer->setFrameOrigin(DPoint(x, 0));
        CAViewAnimation::commitAnimations();
    }
    else
    {
        CAViewAnimation::beginAnimations("navigation_animation", NULL);
        CAViewAnimation::setAnimationDuration(0.25f);
        CAViewAnimation::setAnimationDelay(0.03f);
        CAViewAnimation::setAnimationCurve(CAViewAnimationCurveEaseOut);
        lastContainer->setFrameOrigin(DPoint(-x/2.0f, 0));
        CAViewAnimation::commitAnimations();
        
        CAViewAnimation::beginAnimations("navigation_animation2", NULL);
        CAViewAnimation::setAnimationDuration(0.25f);
        CAViewAnimation::setAnimationDelay(0.02f);
        CAViewAnimation::setAnimationCurve(CAViewAnimationCurveEaseOut);
        CAViewAnimation::setAnimationDidStopSelector(this, CAViewAnimation0_selector(CANavigationController::homingViewControllerFinish));
        backContainer->setFrameOrigin(DPointZero);
        CAViewAnimation::commitAnimations();
    }
}
Пример #4
0
void CANavigationController::replaceViewController(CrossApp::CAViewController *viewController, bool animated)
{
    if (this->getView()->getSuperview() == NULL)
    {
        return;
    }
    
    if (m_pNavigationBars.size() == 1)
    {
        CANavigationBarItem* item = viewController->getNavigationBarItem();
        if (item == NULL)
        {
            item = CANavigationBarItem::create("");
        }
        item->setShowGoBackButton(false);
        viewController->setNavigationBarItem(item);
    }
    
    float x = this->getView()->getBounds().size.width;

    CAView* lastContainer = m_pContainers.back();
    this->createWithContainer(viewController);
    this->layoutNewContainer();
    CAView* newContainer = m_pContainers.back();
    
    CAApplication::getApplication()->getTouchDispatcher()->setDispatchEventsFalse();
    
    if (animated)
    {
        newContainer->setFrameOrigin(DPoint(x, 0));
        
        CAViewAnimation::beginAnimations("", NULL);
        CAViewAnimation::setAnimationDuration(0.25f);
        CAViewAnimation::setAnimationDelay(1/30.0f);
        CAViewAnimation::setAnimationCurve(CAViewAnimationCurveEaseOut);
        lastContainer->setFrameOrigin(DPoint(-x/2.0f, 0));
        CAViewAnimation::commitAnimations();
        
        CAViewAnimation::beginAnimations("", NULL);
        CAViewAnimation::setAnimationDuration(0.25f);
        CAViewAnimation::setAnimationDelay(1/60.0f);
        CAViewAnimation::setAnimationCurve(CAViewAnimationCurveEaseOut);
        CAViewAnimation::setAnimationDidStopSelector(this, CAViewAnimation0_selector(CANavigationController::replaceViewControllerFinish));
        newContainer->setFrameOrigin(DPointZero);
        CAViewAnimation::commitAnimations();
    }
    else
    {
        this->replaceViewControllerFinish();
    }
}
Пример #5
0
void CANavigationController::ccTouchMoved(CATouch *pTouch, CAEvent *pEvent)
{
    CC_RETURN_IF(m_pViewControllers.size() <= 1);
    CC_RETURN_IF(m_bTouchMoved == false);
    float offDis = pTouch->getLocation().x - pTouch->getPreviousLocation().x;
    CAView* showContainer = m_pContainers.at(m_pContainers.size() - 2);
    if (!showContainer->getBounds().size.equals(this->getView()->getBounds().size))
    {
        showContainer->setFrame(this->getView()->getBounds());
    }
    showContainer->setVisible(true);
    showContainer->setTouchEnabled(false);
    
    CAView* backContainer = m_pContainers.back();
    
    DPoint point1 = backContainer->getFrameOrigin();
    point1.x += offDis;
    point1.x = MAX(point1.x, 0);
    point1.x = MIN(point1.x, this->getView()->getBounds().size.width);
    backContainer->setFrameOrigin(point1);
    backContainer->setTouchEnabled(false);
    
    DPoint point2 = showContainer->getCenterOrigin();
    point2.x = point1.x/2;
    showContainer->setCenterOrigin(point2);
    
    m_bPopViewController = ((offDis > 10) || point1.x > this->getView()->getBounds().size.width/4);
}
Пример #6
0
CAViewController* CANavigationController::popViewControllerAnimated(bool animated)
{
    if (m_pViewControllers.size() == 1)
    {
        return NULL;
    }

    float x = this->getView()->getBounds().size.width;
    
    size_t index = m_pViewControllers.size() - 2;
    CAViewController* showViewController = m_pViewControllers.at(index);
    showViewController->viewDidAppear();
    
    CAViewController* backViewController = m_pViewControllers.back();
    
    CAView* showContainer = m_pContainers.at(m_pContainers.size() - 2);
    showContainer->setVisible(true);
    showContainer->setFrameOrigin(CCPoint(-x/2.0f, 0));
    
    CAView* backContainer = m_pContainers.back();
    backContainer->setFrameOrigin(CCPointZero);
    
    CAApplication::getApplication()->getTouchDispatcher()->setDispatchEventsFalse();
    
    if (animated)
    {
        CAViewAnimation::beginAnimations("", NULL);
        CAViewAnimation::setAnimationDuration(0.25f);
        CAViewAnimation::setAnimationDelay(1/30.0f);
        CAViewAnimation::setAnimationCurve(CAViewAnimationCurveEaseOut);
        showContainer->setFrameOrigin(CCPointZero);
        CAViewAnimation::commitAnimations();
        
        CAViewAnimation::beginAnimations("", NULL);
        CAViewAnimation::setAnimationDuration(0.25f);
        CAViewAnimation::setAnimationDelay(1/60.0f);
        CAViewAnimation::setAnimationCurve(CAViewAnimationCurveEaseOut);
        CAViewAnimation::setAnimationDidStopSelector(this, CAViewAnimation0_selector(CANavigationController::popViewControllerFinish));
        backContainer->setFrameOrigin(CCPoint(x, 0));
        CAViewAnimation::commitAnimations();
    }
    else
    {
        this->popViewControllerFinish();
    }
    return backViewController;
}
Пример #7
0
void CANavigationController::pushViewControllerFinish()
{
    float x = this->getView()->getBounds().size.width;
    
    CAView* lastContainer = m_pContainers.at(m_pContainers.size() - 2);
    lastContainer->setVisible(false);
    lastContainer->setFrameOrigin(CCPoint(-x/2.0f, 0));
    
    CAView* newContainer = m_pContainers.back();
    newContainer->setFrameOrigin(CCPointZero);
    
    CAViewController* lastViewController = m_pViewControllers.at(m_pViewControllers.size() - 2);
    lastViewController->viewDidDisappear();
    
    m_bSlidingMinX = m_pViewControllers.size() <= 1;
    CAApplication::getApplication()->getTouchDispatcher()->setDispatchEventsTrue();
}
void CACollectionView::updateSectionHeaderAndFooterRects()
{
	DRect rect = this->getBounds();
	rect.origin = getContentOffset();

	std::vector<DRect>::iterator itr;
	for (itr = m_rSectionRects.begin(); itr != m_rSectionRects.end(); itr++)
	{
		CC_CONTINUE_IF(!rect.intersectsRect(*itr));
		int i = (int)(itr - m_rSectionRects.begin());
		CAView* header = NULL;
		CAView* footer = NULL;
		float headerHeight = 0;
		float footerHeight = 0;
		if (m_pSectionHeaderViews.find(i) != m_pSectionHeaderViews.end())
		{
			header = m_pSectionHeaderViews[i];
			headerHeight = m_pSectionHeaderViews[i]->getFrame().size.height;
		}
		if (m_pSectionFooterViews.find(i) != m_pSectionFooterViews.end())
		{
			footer = m_pSectionFooterViews[i];
			footerHeight = m_pSectionFooterViews[i]->getFrame().size.height;
		}
		if (header && m_bAlwaysTopSectionHeader)
		{
			DPoint p1 = rect.origin;
			p1.y = MAX(p1.y, itr->origin.y);
			p1.y = MIN(p1.y, itr->origin.y + itr->size.height
				- headerHeight - footerHeight);
			header->setFrameOrigin(p1);
		}
		if (footer && m_bAlwaysBottomSectionFooter)
		{
			DPoint p2 = DPointZero;
			p2.y = MIN(rect.origin.y + this->getBounds().size.height - footerHeight,
				itr->origin.y + itr->size.height - footerHeight);
			p2.y = MAX(p2.y, itr->origin.y + headerHeight);
			footer->setFrameOrigin(p2);
		}
	}
}
Пример #9
0
void CANavigationController::pushViewController(CAViewController* viewController, bool animated)
{
    if (this->getView()->getSuperview() == NULL)
    {
        return;
    }

    float x = this->getView()->getBounds().size.width;
    
    CAView* lastContainer = m_pContainers.back();
    this->createWithContainer(viewController);
    this->layoutNewContainer();
    CAView* newContainer = m_pContainers.back();
    
    
    CAApplication::getApplication()->getTouchDispatcher()->setDispatchEventsFalse();
    
    if (animated)
    {
        newContainer->setFrameOrigin(CCPoint(x, 0));
        
        CAViewAnimation::beginAnimations("", NULL);
        CAViewAnimation::setAnimationDuration(0.25f);
        CAViewAnimation::setAnimationDelay(1/30.0f);
        CAViewAnimation::setAnimationCurve(CAViewAnimationCurveEaseOut);
        lastContainer->setFrameOrigin(CCPoint(-x/2.0f, 0));
        CAViewAnimation::commitAnimations();
        
        CAViewAnimation::beginAnimations("", NULL);
        CAViewAnimation::setAnimationDuration(0.25f);
        CAViewAnimation::setAnimationDelay(1/60.0f);
        CAViewAnimation::setAnimationCurve(CAViewAnimationCurveEaseOut);
        CAViewAnimation::setAnimationDidStopSelector(this, CAViewAnimation0_selector(CANavigationController::pushViewControllerFinish));
        newContainer->setFrameOrigin(CCPointZero);
        CAViewAnimation::commitAnimations();
        
    }
    else
    {
        this->pushViewControllerFinish();
    }
}
Пример #10
0
void CANavigationController::pushViewControllerFinish()
{
    CAView* lastContainer = m_pContainers.at(m_pContainers.size() - 2);
    lastContainer->setVisible(false);
    
    CAView* newContainer = m_pContainers.back();
    newContainer->setFrameOrigin(DPointZero);
    
    CAViewController* lastViewController = m_pViewControllers.at(m_pViewControllers.size() - 2);
    lastViewController->viewDidDisappear();
    
    CAApplication::getApplication()->getTouchDispatcher()->setDispatchEventsTrue();
}
Пример #11
0
void CANavigationController::replaceViewControllerFinish()
{
    CAView* newContainer = m_pContainers.back();
    newContainer->setFrameOrigin(DPointZero);
    
    size_t index = m_pViewControllers.size() - 2;
    CAViewController* lastViewController = m_pViewControllers.at(index);
    lastViewController->viewDidDisappear();
    lastViewController->m_pNavigationController = NULL;
    lastViewController->removeViewFromSuperview();
    m_pViewControllers.erase(index);
    
    CAView* backContainer = m_pContainers.at(index);
    backContainer->removeFromSuperview();
    m_pContainers.erase(index);
    m_pSecondContainers.erase(index);
    m_pNavigationBars.erase(index);
    CAApplication::getApplication()->getTouchDispatcher()->setDispatchEventsTrue();
}
Пример #12
0
CAViewController* CANavigationController::popViewControllerAnimated(bool animated)
{
    if (m_pViewControllers.size() == 1)
    {
        return NULL;
    }

    float x = this->getView()->getBounds().size.width;
    
    CAViewController* backViewController = m_pViewControllers.back();
    CAView* backContainer = m_pContainers.back();
    {
        backContainer->setFrameOrigin(CCPointZero);
    }
    
    size_t index = m_pViewControllers.size() - 2;
    CAViewController* showViewController = m_pViewControllers.at(index);
    showViewController->viewDidAppear();
    
    CAView* showContainer = m_pContainers.at(index);
    showContainer->setVisible(true);
    
    
    {
        CCRect rect = this->getView()->getBounds();
        
        CCPoint point = this->getNavigationBarNowPoint(showViewController);
        
        switch (m_eNavigationBarVerticalAlignment)
        {
            case CABarVerticalAlignmentTop:
            {
                rect.origin.y = point.y + m_tNavigationBarSize.height;
                rect.size.height = rect.size.height - rect.origin.y;
            }
                break;
            case CABarVerticalAlignmentBottom:
            {
                rect.size.height = point.y;
            }
                break;
            default:
                break;
        }
        m_pNavigationBars.at(index)->setFrameOrigin(point);
        
        CAView* secondContainer = m_pSecondContainers.at(index);
        secondContainer->setFrame(rect);
        
        showViewController->getSuperViewRect(secondContainer->getBounds());
    }
    
    CAApplication::getApplication()->getTouchDispatcher()->setDispatchEventsFalse();
    
    if (animated)
    {
        showContainer->setFrameOrigin(CCPoint(-x/2.0f, 0));
        
        CAViewAnimation::beginAnimations("", NULL);
        CAViewAnimation::setAnimationDuration(0.25f);
        CAViewAnimation::setAnimationDelay(1/30.0f);
        CAViewAnimation::setAnimationCurve(CAViewAnimationCurveEaseOut);
        showContainer->setFrameOrigin(CCPointZero);
        CAViewAnimation::commitAnimations();
        
        CAViewAnimation::beginAnimations("", NULL);
        CAViewAnimation::setAnimationDuration(0.25f);
        CAViewAnimation::setAnimationDelay(1/60.0f);
        CAViewAnimation::setAnimationCurve(CAViewAnimationCurveEaseOut);
        CAViewAnimation::setAnimationDidStopSelector(this, CAViewAnimation0_selector(CANavigationController::popViewControllerFinish));
        backContainer->setFrameOrigin(CCPoint(x, 0));
        CAViewAnimation::commitAnimations();
    }
    else
    {
        this->popViewControllerFinish();
    }
    return backViewController;
}