issue #5176. fix UIScrollView

This commit is contained in:
andyque 2014-05-21 16:40:42 +08:00
parent e184ac9e0c
commit 3b777646c4
4 changed files with 24 additions and 34 deletions

View File

@ -173,9 +173,12 @@ void PageView::insertPage(Layout* page, int idx)
else
{
_protectedChildren.insert(idx, page);
page->setParent(this);
page->setPosition(Vec2(getPositionXByIndex(idx), 0));
Size pSize = page->getSize();
Size pvSize = getSize();
if (!pSize.equals(pvSize))
{
CCLOG("page size does not match pageview size, it will be force sized!");
@ -248,8 +251,11 @@ void PageView::updateChildrenSize()
Size selfSize = getSize();
for (auto& page : _protectedChildren)
{
//FIXME: should call node->setContentSize
Layout* layout = dynamic_cast<Layout*>(page);
layout->setSize(selfSize);
if (layout) {
layout->setSize(selfSize);
}
}
}
@ -269,7 +275,9 @@ void PageView::updateChildrenPosition()
for (int i=0; i<pageCount; i++)
{
Layout* page = dynamic_cast<Layout*>(_protectedChildren.at(i));
page->setPosition(Vec2((i-_curPageIdx)*pageWidth, 0));
if (page) {
page->setPosition(Vec2((i-_curPageIdx)*pageWidth, 0));
}
}
}

View File

@ -258,12 +258,12 @@ const Size& ScrollView::getInnerContainerSize() const
void ScrollView::addChild(Node *child)
{
Layout::addChild(child);
ScrollView::addChild(child, child->getZOrder(), child->getTag());
}
void ScrollView::addChild(Node * child, int zOrder)
{
Layout::addChild(child, zOrder);
ScrollView::addChild(child, zOrder, child->getTag());
}
void ScrollView::addChild(Node *child, int zOrder, int tag)

View File

@ -260,46 +260,21 @@ public:
*/
CC_DEPRECATED_ATTRIBUTE void addEventListenerScrollView(Ref* target, SEL_ScrollViewEvent selector);
void addEventListener(const ccScrollViewCallback& callback);
//all of these functions are related to innerContainer.
virtual void addChild(Node * child) override;
/**
* Adds a child to the container with a z-order
*
* If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately.
*
* @param child A child node
* @param zOrder Z order for drawing priority. Please refer to setLocalZOrder(int)
*/
virtual void addChild(Node * child, int zOrder) override;
/**
* Adds a child to the container with z order and tag
*
* If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately.
*
* @param child A child node
* @param zOrder Z order for drawing priority. Please refer to setLocalZOrder(int)
* @param tag A interger to identify the node easily. Please refer to setTag(int)
*/
virtual void addChild(Node* child, int zOrder, int tag) override;
//override "removeAllChildrenAndCleanUp" method of widget.
virtual void removeAllChildren() override;
virtual void removeAllChildrenWithCleanup(bool cleanup) override;
//override "removeChild" method of widget.
virtual void removeChild(Node* child, bool cleaup = true) override;
//override "getChildren" method of widget.
virtual Vector<Node*>& getChildren() override;
virtual const Vector<Node*>& getChildren() const override;
virtual ssize_t getChildrenCount() const override;
virtual Node * getChildByTag(int tag) const override;
virtual Widget* getChildByName(const std::string& name) override;
//handle touch event
virtual bool onTouchBegan(Touch *touch, Event *unusedEvent) override;
virtual void onTouchMoved(Touch *touch, Event *unusedEvent) override;
virtual void onTouchEnded(Touch *touch, Event *unusedEvent) override;

View File

@ -47,7 +47,10 @@ bool UIPageViewTest::init()
(widgetSize.height - backgroundSize.height) / 2.0f +
(backgroundSize.height - pageView->getSize().height) / 2.0f));
for (int i = 0; i < 3; ++i)
pageView->removeAllPages();
int pageCount = 4;
for (int i = 0; i < pageCount; ++i)
{
Layout* layout = Layout::create();
layout->setSize(Size(240.0f, 130.0f));
@ -63,8 +66,12 @@ bool UIPageViewTest::init()
label->setPosition(Vec2(layout->getSize().width / 2.0f, layout->getSize().height / 2.0f));
layout->addChild(label);
pageView->addPage(layout);
pageView->insertPage(layout,i);
}
pageView->removePageAtIndex(0);
pageView->scrollToPage(pageCount-2);
pageView->addEventListener(CC_CALLBACK_2(UIPageViewTest::pageViewEvent, this));
_uiLayer->addChild(pageView);