コード例 #1
0
void UIScrollView::moveChildren(float offset)
{
    switch (m_eDirection)
    {
        case SCROLLVIEW_DIR_VERTICAL: // vertical
        {
            ccArray* arrayChildren = m_children->data;
            int childrenCount = arrayChildren->num;
            for (int i = 0; i < childrenCount; i++)
            {
                UIWidget* child = (UIWidget*)(arrayChildren->arr[i]);
                moveChildPoint.x = child->getPosition().x;
                moveChildPoint.y = child->getPosition().y + offset;
                child->setPosition(moveChildPoint);
                child->setVisible(child->checkBeVisibleInParent());
            }
            break;
        }
        case SCROLLVIEW_DIR_HORIZONTAL: // horizontal
        {
            ccArray* arrayChildren = m_children->data;
            int childrenCount = arrayChildren->num;
            for (int i=0;i<childrenCount;i++)
            {
                UIWidget* child = (UIWidget*)(arrayChildren->arr[i]);
                moveChildPoint.x = child->getPosition().x + offset;
                moveChildPoint.y = child->getPosition().y;
                child->setPosition(moveChildPoint);
                child->setVisible(child->checkBeVisibleInParent());
            }
            break;
        }
        default:
            break;
    }
}
コード例 #2
0
void UIScrollView::update(float dt)
{
    if (m_bAutoScroll)
    {
        autoScrollChildren(dt);
    }
    recordSlidTime(dt);
    
    if (m_eMoveMode == SCROLLVIEW_MOVE_MODE_ACTION)
    {
        if (isRunningAction)
        {
            ccArray* arrayChildren = m_children->data;
            int times = arrayChildren->num;
            for (int i = 0; i < times; ++i)
            {
                UIWidget* child = dynamic_cast<UIWidget*>(arrayChildren->arr[i]);
                child->setVisible(child->checkBeVisibleInParent());
            }
        }
    }
}