fixed #1750: [iOS] CCEditBox's position is incorrect when it's added to a non-fullscreen CCNode.

This commit is contained in:
James Chen 2013-02-26 11:16:26 +08:00
parent 201fda1f58
commit efdb9180e4
3 changed files with 18 additions and 5 deletions

View File

@ -280,7 +280,10 @@ void CCEditBox::keyboardWillShow(CCIMEKeyboardNotificationInfo& info)
CCRect rectTracked = getRect(this);
// some adjustment for margin between the keyboard and the edit box.
rectTracked.origin.y -= 4;
if (m_pParent != NULL)
{
rectTracked.origin = m_pParent->convertToWorldSpace(rectTracked.origin);
}
// if the keyboard area doesn't intersect with the tracking node area, nothing needs to be done.
if (!rectTracked.intersectsRect(info.end))
{

View File

@ -403,11 +403,14 @@ static CGPoint convertDesignCoordToScreenCoord(const CCPoint& designCoord, bool
}
void CCEditBoxImplIOS::setPosition(const CCPoint& pos)
{
if (!m_obPosition.equals(pos))
{
m_obPosition = pos;
CCPoint designCoord = ccp(pos.x - m_tContentSize.width * m_obAnchorPoint.x, pos.y + m_tContentSize.height * (1 - m_obAnchorPoint.y));
[m_systemControl setPosition:convertDesignCoordToScreenCoord(designCoord, m_bInRetinaMode)];
}
}
void CCEditBoxImplIOS::setContentSize(const CCSize& size)
{
@ -424,7 +427,12 @@ void CCEditBoxImplIOS::setAnchorPoint(const CCPoint& anchorPoint)
void CCEditBoxImplIOS::visit(void)
{
if(getCCEditBox()->getParent()) {
CCPoint p = getCCEditBox()->getParent()->convertToWorldSpace(getCCEditBox()->getPosition());
setPosition(p);
} else {
setPosition(getCCEditBox()->getPosition());
}
}
void CCEditBoxImplIOS::openKeyboard()

View File

@ -75,6 +75,8 @@ EditBoxTest::EditBoxTest()
m_pEditEmail->setInputMode(kEditBoxInputModeEmailAddr);
m_pEditEmail->setDelegate(this);
addChild(m_pEditEmail);
this->setPosition(ccp(10, 20));
}
EditBoxTest::~EditBoxTest()