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

View File

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

View File

@ -261,45 +261,20 @@ public:
CC_DEPRECATED_ATTRIBUTE void addEventListenerScrollView(Ref* target, SEL_ScrollViewEvent selector); CC_DEPRECATED_ATTRIBUTE void addEventListenerScrollView(Ref* target, SEL_ScrollViewEvent selector);
void addEventListener(const ccScrollViewCallback& callback); void addEventListener(const ccScrollViewCallback& callback);
//all of these functions are related to innerContainer.
virtual void addChild(Node * child) override; 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; 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; virtual void addChild(Node* child, int zOrder, int tag) override;
//override "removeAllChildrenAndCleanUp" method of widget.
virtual void removeAllChildren() override; virtual void removeAllChildren() override;
virtual void removeAllChildrenWithCleanup(bool cleanup) override; virtual void removeAllChildrenWithCleanup(bool cleanup) override;
//override "removeChild" method of widget.
virtual void removeChild(Node* child, bool cleaup = true) override; virtual void removeChild(Node* child, bool cleaup = true) override;
//override "getChildren" method of widget.
virtual Vector<Node*>& getChildren() override; virtual Vector<Node*>& getChildren() override;
virtual const Vector<Node*>& getChildren() const override; virtual const Vector<Node*>& getChildren() const override;
virtual ssize_t getChildrenCount() const override; virtual ssize_t getChildrenCount() const override;
virtual Node * getChildByTag(int tag) const override; virtual Node * getChildByTag(int tag) const override;
virtual Widget* getChildByName(const std::string& name) override; virtual Widget* getChildByName(const std::string& name) override;
//handle touch event
virtual bool onTouchBegan(Touch *touch, Event *unusedEvent) override; virtual bool onTouchBegan(Touch *touch, Event *unusedEvent) override;
virtual void onTouchMoved(Touch *touch, Event *unusedEvent) override; virtual void onTouchMoved(Touch *touch, Event *unusedEvent) override;
virtual void onTouchEnded(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 + (widgetSize.height - backgroundSize.height) / 2.0f +
(backgroundSize.height - pageView->getSize().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* layout = Layout::create();
layout->setSize(Size(240.0f, 130.0f)); 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)); label->setPosition(Vec2(layout->getSize().width / 2.0f, layout->getSize().height / 2.0f));
layout->addChild(label); 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)); pageView->addEventListener(CC_CALLBACK_2(UIPageViewTest::pageViewEvent, this));
_uiLayer->addChild(pageView); _uiLayer->addChild(pageView);