issue #5176, add focus event listener to UIScrollView

This commit is contained in:
andyque 2014-05-23 11:18:26 +08:00
parent 3f363f0e51
commit 6d9a21d0ed
2 changed files with 26 additions and 1 deletions

View File

@ -136,6 +136,10 @@ void ScrollView::onEnter()
{
Layout::onEnter();
scheduleUpdate();
_eventListener = EventListenerFocus::create();
_eventListener->onFocusChanged = CC_CALLBACK_2(ScrollView::onFocusChanged, this);
_eventDispatcher->addEventListenerWithFixedPriority(_eventListener, 1);
}
bool ScrollView::init()
@ -1772,6 +1776,24 @@ Widget* ScrollView::findNextFocusedWidget(cocos2d::ui::Widget::FocusDirection di
}
}
void ScrollView::onFocusChanged(cocos2d::ui::Widget *widgetLostFocus, cocos2d::ui::Widget *widgetGetFocus)
{
if (dynamic_cast<Layout*>(widgetGetFocus) || dynamic_cast<Layout*>(widgetLostFocus)) {
return;
}
if (this->getLayoutType() == Layout::Type::VERTICAL) {
float loseFocusWidgetBoundary = widgetLostFocus->getTopInParent();
float getFocusWidgetBoundary = widgetGetFocus->getTopInParent();
if (loseFocusWidgetBoundary >= getFocusWidgetBoundary) {
CCLOG("down");
}
else{
CCLOG("up");
}
}
}
}
NS_CC_END

View File

@ -30,6 +30,8 @@ THE SOFTWARE.
NS_CC_BEGIN
class EventFocusListener;
namespace ui {
class ScrollInnerContainer : public Layout
@ -382,6 +384,7 @@ protected:
void bounceRightEvent();
virtual void onFocusChanged(Widget* widgetLostFocus, Widget* widgetGetFocus);
protected:
Layout* _innerContainer;
@ -430,7 +433,7 @@ protected:
float _bounceOriginalSpeed;
bool _inertiaScrollEnabled;
EventListenerFocus *_eventListener;
Ref* _scrollViewEventListener;
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))