mirror of https://github.com/axmolengine/axmol.git
fixed #3599. use a scheduler to fix the position of editbox when it's parent postion has been changed
This commit is contained in:
parent
be0ac5dc1c
commit
7d2db27cae
|
@ -28,6 +28,8 @@
|
|||
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
static const float CHECK_EDITBOX_POSITION_INTERVAL = 0.1f;
|
||||
|
||||
EditBox::EditBox(void)
|
||||
: _editBoxImpl(NULL)
|
||||
, _delegate(NULL)
|
||||
|
@ -332,8 +334,19 @@ void EditBox::onEnter(void)
|
|||
{
|
||||
_editBoxImpl->onEnter();
|
||||
}
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
|
||||
this->schedule(schedule_selector(EditBox::updatePosition), CHECK_EDITBOX_POSITION_INTERVAL);
|
||||
#endif
|
||||
}
|
||||
|
||||
void EditBox::updatePosition(float dt)
|
||||
{
|
||||
if (nullptr != _editBoxImpl) {
|
||||
_editBoxImpl->updatePosition(dt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void EditBox::onExit(void)
|
||||
{
|
||||
ControlButton::onExit();
|
||||
|
|
|
@ -418,6 +418,7 @@ public:
|
|||
void touchDownAction(Ref *sender, Control::EventType controlEvent);
|
||||
|
||||
protected:
|
||||
void updatePosition(float dt);
|
||||
EditBoxImpl* _editBoxImpl;
|
||||
EditBoxDelegate* _delegate;
|
||||
|
||||
|
|
|
@ -69,6 +69,11 @@ public:
|
|||
virtual void setVisible(bool visible) = 0;
|
||||
virtual void setContentSize(const Size& size) = 0;
|
||||
virtual void setAnchorPoint(const Point& anchorPoint) = 0;
|
||||
|
||||
/**
|
||||
* check the editbox's position, update it when needed
|
||||
*/
|
||||
virtual void updatePosition(float dt){};
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
|
|
|
@ -101,6 +101,7 @@ public:
|
|||
virtual void setVisible(bool visible);
|
||||
virtual void setContentSize(const Size& size);
|
||||
virtual void setAnchorPoint(const Point& anchorPoint);
|
||||
virtual void updatePosition(float dt) override;
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
|
@ -116,7 +117,6 @@ public:
|
|||
virtual void closeKeyboard();
|
||||
|
||||
virtual void onEndEditing();
|
||||
|
||||
private:
|
||||
void initInactiveLabels(const Size& size);
|
||||
void setInactiveText(const char* pText);
|
||||
|
|
|
@ -614,7 +614,6 @@ void EditBoxImplIOS::setAnchorPoint(const Point& anchorPoint)
|
|||
|
||||
void EditBoxImplIOS::visit(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void EditBoxImplIOS::onEnter(void)
|
||||
|
@ -626,6 +625,15 @@ void EditBoxImplIOS::onEnter(void)
|
|||
}
|
||||
}
|
||||
|
||||
void EditBoxImplIOS::updatePosition(float dt)
|
||||
{
|
||||
if (nullptr != _systemControl) {
|
||||
this->adjustTextFieldPosition();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void EditBoxImplIOS::adjustTextFieldPosition()
|
||||
{
|
||||
Size contentSize = _editBox->getContentSize();
|
||||
|
|
|
@ -107,6 +107,7 @@ public:
|
|||
virtual void doAnimationWhenKeyboardMove(float duration, float distance);
|
||||
virtual void openKeyboard();
|
||||
virtual void closeKeyboard();
|
||||
virtual void updatePosition(float dt) override;
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
|
|
|
@ -382,6 +382,14 @@ NSPoint EditBoxImplMac::convertDesignCoordToScreenCoord(const Point& designCoord
|
|||
return screenPos;
|
||||
}
|
||||
|
||||
void EditBoxImplMac::updatePosition(float dt)
|
||||
{
|
||||
if(nullptr != _sysEdit)
|
||||
{
|
||||
adjustTextFieldPosition();
|
||||
}
|
||||
}
|
||||
|
||||
void EditBoxImplMac::adjustTextFieldPosition()
|
||||
{
|
||||
Size contentSize = _editBox->getContentSize();
|
||||
|
|
Loading…
Reference in New Issue