// tableSize.height == cell个数*cell的height
CCSize tableSize = table->getContentSize();
// CCTableView
CCSize tableViewSize = table->getViewSize();
// 每次拖动的偏移量?(负值)
CCPoint contOffsetPos = table->getContentOffset();
// 总的偏移量
float maxOff = tableViewSize.height - tableSize.height;
// 每次拖动的偏移量
float curOff = contOffsetPos.y - maxOff;
// 计算百分比
float percentage = fabs(curOff)/fabs(maxOff);
printf("curOff:%f, maxOff:%f, per:%f\n", curOff, maxOff, percentage);
// 拖拉到最顶端或最低端后继续拖动(弹回)会出现percentage值小于0.1和大于1.0的情况,我们分别把percentage重置为0和1.0f
if(percentage < 0.1f)
{
percentage = 0;
}
if(percentage > 1.0f)
{
percentage = 1.0f;
}
// bar移动到最顶端的position.y
float barTopPosY = bar->getPosition().y;
// bar移动到最低端的position.y
float barLowPosY = 75.0f;
// ....
float h = barTopPosY - percentage*(barTopPosY- barLowPosY);;
bar->setPosition(ccp(bar->getPosition().x, h));
网上给的方法,为什么 拖拉到最顶端 (弹回)会没有出现percentage值小于0.1 的情况
还有到了底端,滚动条就上不去了barTopPosY- barLowPosY=0了