mirror of https://github.com/axmolengine/axmol.git
fix scrollView rotate issue
This commit is contained in:
parent
8161d2ad34
commit
952e52365b
|
@ -1422,10 +1422,12 @@ void ScrollView::endRecordSlidAction()
|
|||
}
|
||||
float totalDis = 0.0f;
|
||||
Vec2 dir;
|
||||
Vec2 touchEndPositionInNodeSpace = this->convertToNodeSpace(_touchEndPosition);
|
||||
Vec2 touchBeganPositionInNodeSpace = this->convertToNodeSpace(_touchBeganPosition);
|
||||
switch (_direction)
|
||||
{
|
||||
case Direction::VERTICAL:
|
||||
totalDis = _touchEndPosition.y - _touchBeganPosition.y;
|
||||
totalDis = touchEndPositionInNodeSpace.y - touchBeganPositionInNodeSpace.y;
|
||||
if (totalDis < 0.0f)
|
||||
{
|
||||
dir = SCROLLDIR_DOWN;
|
||||
|
@ -1436,7 +1438,7 @@ void ScrollView::endRecordSlidAction()
|
|||
}
|
||||
break;
|
||||
case Direction::HORIZONTAL:
|
||||
totalDis = _touchEndPosition.x - _touchBeganPosition.x;
|
||||
totalDis = touchEndPositionInNodeSpace.x - touchBeganPositionInNodeSpace.x;
|
||||
if (totalDis < 0.0f)
|
||||
{
|
||||
dir = SCROLLDIR_LEFT;
|
||||
|
@ -1448,7 +1450,7 @@ void ScrollView::endRecordSlidAction()
|
|||
break;
|
||||
case Direction::BOTH:
|
||||
{
|
||||
Vec2 subVector = _touchEndPosition - _touchBeganPosition;
|
||||
Vec2 subVector = touchEndPositionInNodeSpace - touchBeganPositionInNodeSpace;
|
||||
totalDis = subVector.getLength();
|
||||
dir = subVector.getNormalized();
|
||||
break;
|
||||
|
|
|
@ -211,7 +211,7 @@ g_guisTests[] =
|
|||
UISceneManager* sceneManager = UISceneManager::sharedUISceneManager();
|
||||
sceneManager->setCurrentUISceneId(kUIScrollViewTest_Vertical);
|
||||
sceneManager->setMinUISceneId(kUIScrollViewTest_Vertical);
|
||||
sceneManager->setMaxUISceneId(kUIScrollViewNestTest);
|
||||
sceneManager->setMaxUISceneId(kUIScrollViewRotated);
|
||||
Scene* scene = sceneManager->currentUIScene();
|
||||
Director::getInstance()->replaceScene(scene);
|
||||
}
|
||||
|
|
|
@ -91,6 +91,7 @@ static const char* s_testArray[] =
|
|||
"UIScrollViewTest_ScrollToPercentBothDirection",
|
||||
"UIScrollViewTest_ScrollToPercentBothDirection_Bounce",
|
||||
"UIScrollViewNestTest",
|
||||
"UIScrollViewRotated",
|
||||
|
||||
"UIPageViewTest",
|
||||
"UIPageViewButtonTest",
|
||||
|
@ -323,6 +324,9 @@ Scene *UISceneManager::currentUIScene()
|
|||
return UIScrollViewTest_ScrollToPercentBothDirection_Bounce::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||
case kUIScrollViewNestTest:
|
||||
return UIScrollViewNestTest::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||
case kUIScrollViewRotated:
|
||||
return UIScrollViewRotated::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||
|
||||
case kUIPageViewTest:
|
||||
return UIPageViewTest::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||
case kUIPageViewButtonTest:
|
||||
|
|
|
@ -82,6 +82,8 @@ enum
|
|||
kUIScrollViewTest_ScrollToPercentBothDirection,
|
||||
kUIScrollViewTest_ScrollToPercentBothDirection_Bounce,
|
||||
kUIScrollViewNestTest,
|
||||
kUIScrollViewRotated,
|
||||
|
||||
kUIPageViewTest,
|
||||
kUIPageViewButtonTest,
|
||||
kUIPageViewCustomScrollThreshold,
|
||||
|
|
|
@ -426,3 +426,81 @@ bool UIScrollViewNestTest::init()
|
|||
|
||||
return false;
|
||||
}
|
||||
// UIScrollViewRotated
|
||||
|
||||
UIScrollViewRotated::UIScrollViewRotated()
|
||||
: _displayValueLabel(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
UIScrollViewRotated::~UIScrollViewRotated()
|
||||
{
|
||||
}
|
||||
|
||||
bool UIScrollViewRotated::init()
|
||||
{
|
||||
if (UIScene::init())
|
||||
{
|
||||
Size widgetSize = _widget->getContentSize();
|
||||
|
||||
// Add a label in which the scrollview alert will be displayed
|
||||
_displayValueLabel = Text::create("Move by vertical direction", "fonts/Marker Felt.ttf", 32);
|
||||
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
|
||||
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f,
|
||||
widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f));
|
||||
_uiLayer->addChild(_displayValueLabel);
|
||||
|
||||
// Add the alert
|
||||
Text* alert = Text::create("ScrollView vertical", "fonts/Marker Felt.ttf", 30);
|
||||
alert->setColor(Color3B(159, 168, 176));
|
||||
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
|
||||
_uiLayer->addChild(alert);
|
||||
|
||||
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
|
||||
|
||||
Layout* background = dynamic_cast<Layout*>(root->getChildByName("background_Panel"));
|
||||
|
||||
// Create the scrollview by vertical
|
||||
ui::ScrollView* scrollView = ui::ScrollView::create();
|
||||
scrollView->setContentSize(Size(280.0f, 150.0f));
|
||||
scrollView->setDirection(ui::ScrollView::Direction::BOTH);
|
||||
Size backgroundSize = background->getContentSize();
|
||||
scrollView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
|
||||
(backgroundSize.width - scrollView->getContentSize().width) / 2.0f,
|
||||
(widgetSize.height - backgroundSize.height) / 2.0f +
|
||||
(backgroundSize.height - scrollView->getContentSize().height) / 2.0f + 100) );
|
||||
scrollView->setRotation(45);
|
||||
_uiLayer->addChild(scrollView);
|
||||
|
||||
ImageView* imageView = ImageView::create("cocosui/ccicon.png");
|
||||
|
||||
float innerWidth = scrollView->getContentSize().width;
|
||||
float innerHeight = scrollView->getContentSize().height + imageView->getContentSize().height;
|
||||
|
||||
scrollView->setInnerContainerSize(Size(innerWidth, innerHeight));
|
||||
|
||||
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
|
||||
button->setPosition(Vec2(innerWidth / 2.0f, scrollView->getInnerContainerSize().height - button->getContentSize().height / 2.0f));
|
||||
scrollView->addChild(button);
|
||||
|
||||
Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
|
||||
titleButton->setTitleText("Title Button");
|
||||
titleButton->setPosition(Vec2(innerWidth / 2.0f, button->getBottomBoundary() - button->getContentSize().height));
|
||||
scrollView->addChild(titleButton);
|
||||
|
||||
Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
|
||||
button_scale9->setScale9Enabled(true);
|
||||
button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
|
||||
button_scale9->setPosition(Vec2(innerWidth / 2.0f, titleButton->getBottomBoundary() - titleButton->getContentSize().height));
|
||||
scrollView->addChild(button_scale9);
|
||||
|
||||
imageView->setPosition(Vec2(innerWidth / 2.0f, imageView->getContentSize().height / 2.0f));
|
||||
scrollView->addChild(imageView);
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
|
@ -99,4 +99,16 @@ protected:
|
|||
Text* _displayValueLabel;
|
||||
};
|
||||
|
||||
class UIScrollViewRotated : public UIScene
|
||||
{
|
||||
public:
|
||||
UIScrollViewRotated();
|
||||
~UIScrollViewRotated();
|
||||
bool init();
|
||||
|
||||
protected:
|
||||
UI_SCENE_CREATE_FUNC(UIScrollViewRotated)
|
||||
Text* _displayValueLabel;
|
||||
};
|
||||
|
||||
#endif /* defined(__TestCpp__UIScrollViewTest__) */
|
||||
|
|
Loading…
Reference in New Issue