UIScrollView 中getLocationInView的值问题

lblScrollView->setTouchEnabled(true);
lblScrollView->addTouchEventListener(this,toucheventselector(TalentUpgradeLayer::ccTouch));

void TalentUpgradeLayer::ccTouch(cocos2d::CCTouch *pTouch, TouchEventType type )
{
switch(type)
{
case TOUCH_EVENT_BEGAN:
printf(“event1”);
this->ccTouchBegan(pTouch,type);
break;
case TOUCH_EVENT_MOVED:
this->ccTouchMoved(pTouch,type);
break;
case TOUCH_EVENT_ENDED:
break;
case TOUCH_EVENT_CANCELED:
printf(“event3”);
break;
default:
break;
}
}

CCPoint TalentUpgradeLayer::locationFromTouch(CCTouch* touch)
{
return CCDirector::sharedDirector()->convertToGL(touch->getLocationInView());
}

bool TalentUpgradeLayer::ccTouchBegan(cocos2d::CCTouch *pTouch, TouchEventType type)
{
m_touchPoint = this->locationFromTouch(pTouch);
int x = m_touchPoint.x;
int y = m_touchPoint.y;
printf(\“touch (x, y) is (%d, %d)\\n\”, x, y);
return true;
}
不管从哪里开始拖动,打印的值都是touch (x, y) is (0, 1134),添加print发现getLoationInView获取到的坐标为0,0

楼主你这里方法的参数用错了,应该使用object对象,而不是touch

参考下面的函数实现
void touchEvent(CCObject *pSender, TouchEventType type);


case TOUCH_EVENT_BEGAN:
{
UIWidget* widget = static_cast<UIWidget*>(pSender);
CCPoint point = widget->getTouchStartPos();

    }
        break;

解决了 ~ 谢谢·~~~