我试图在键盘出现时向上移动布局,因为它隐藏了我的输入文本字段,但我的应用程序从 HASH_FIND_PTR(_targets, &tmp, element); 行崩溃 从这堂课
void ActionManager::addAction(Action *action, Node *target, bool paused)
{
CCASSERT(action != nullptr, "");
CCASSERT(target != nullptr, "");
tHashElement *element = nullptr;
// we should convert it to Ref*, because we save it as Ref*
Ref *tmp = target;
HASH_FIND_PTR(_targets, &tmp, element); //error
if (! element)
{
element = (tHashElement*)calloc(sizeof(*element), 1);
element->paused = paused;
target->retain();
element->target = target;
HASH_ADD_PTR(_targets, target, element);
}
actionAllocWithHashElement(element);
CCASSERT(! ccArrayContainsObject(element->actions, action), "");
ccArrayAppendObject(element->actions, action);
action->startWithTarget(target);
}
我正在使用 cocos2d-x 3.2 我有调试,它在这行 m_pLayout->runAction(moveBy); 之后崩溃 任何人请给我一些建议我该如何解决谢谢
我的登录场景.h
#include "cocos2d.h"
#include "cocos-ext.h"
#include "CocosGUI.h"
USING_NS_CC;
USING_NS_CC_EXT;
using namespace ui;
class LoginScene : public Scene
{
public:
LoginScene(bool pPortrait=false);
~LoginScene();
virtual void onEnter();
virtual void onExit();
void onLogin(Ref* pSender, Widget::TouchEventType type);
void onRegister(Ref* pSender, Widget::TouchEventType type);
void TextFieldEvent(Ref* pSender,TextField::EventType type);
protected:
Layout* m_pLayout;
Layer* m_pUILayer;
};
和 LoginScene.cpp
#include "LoginScene.h"
#include "cocostudio/CCSSceneReader.h"
#include "cocostudio/CCSGUIReader.h"
#include "cocostudio/CCActionManagerEx.h"
#include <sqlite3.h>
LoginScene::LoginScene(bool pPortrait):m_pLayout(NULL),m_pUILayer(NULL)
{
Scene::init();
}
LoginScene::~LoginScene()
{
}
void LoginScene::onEnter()
{
Scene::onEnter();
m_pUILayer=Layer::create();
m_pUILayer->scheduleUpdate();
addChild(m_pUILayer);
//register root from json
m_pLayout=dynamic_cast<Layout*>(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("LoginScene/LoginScene.json"));
m_pUILayer->addChild(m_pLayout);
//button initialize
Button *btnLogin=static_cast<Button*>(Helper::seekWidgetByName(m_pLayout, "btnLogin"));
btnLogin->addTouchEventListener(CC_CALLBACK_2(LoginScene::onLogin, this));
Button *btnRegister=static_cast<Button*>(Helper::seekWidgetByName(m_pLayout, "btnRegister"));
btnRegister->addTouchEventListener(CC_CALLBACK_2(LoginScene::onRegister, this));
//textfield initialize
TextField *txtUsername=static_cast<TextField*>(Helper::seekWidgetByName(m_pLayout, "txtUsername"));
txtUsername->addEventListenerTextField(m_pLayout, textfieldeventselector(LoginScene::TextFieldEvent));
TextField *txtPassword=static_cast<TextField*>(Helper::seekWidgetByName(m_pLayout, "txtPassword"));
txtPassword->addEventListenerTextField(m_pLayout, textfieldeventselector(LoginScene::TextFieldEvent));
}
void LoginScene::onExit()
{
m_pUILayer->removeFromParent();
cocostudio::GUIReader::destroyInstance();
cocostudio::ActionManagerEx::destroyInstance();
cocostudio::SceneReader::destroyInstance();
Scene::onExit();
}
void LoginScene::onLogin(Ref* pSender, Widget::TouchEventType type)
{
if(type==Widget::TouchEventType::ENDED)
{
CCLOG("abc");
}
}
void LoginScene::onRegister(Ref* pSender, Widget::TouchEventType type)
{
if (type==Widget::TouchEventType::ENDED)
{
CCLOG("abc");
}
}
void LoginScene::TextFieldEvent(Ref* pSender,TextField::EventType type)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
switch (type)
{
case TextField::EventType::ATTACH_WITH_IME:
{
TextField* txtUsername=dynamic_cast<TextField*>(pSender);
MoveBy* moveBy=MoveBy::create(0.5f, Vec2(0,txtUsername->getContentSize().height*2.5));
m_pLayout->runAction(moveBy);
}
break;
case TextField::EventType::DETACH_WITH_IME:
{
TextField* txtUsername=dynamic_cast<TextField*>(pSender);
MoveBy* moveBy=MoveBy::create(0.1f, Vec2(0,-txtUsername->getContentSize().height*2.5));
m_pLayout->runAction(moveBy);
}
break;
default:
break;
}
#endif
}