<p>感谢:<a target=_blank href="http://www.cocoachina.com/bbs/read.PHP?tID-312569.HTML">quick-3.5获取RichText高度</a></p><p>引擎版本:3.3</p><p>在布局RichText的时候,需要获得RichText的实际渲染高度,然后根据实际高度摆放位置才不会有大的偏差。</p><p>改动UIRichText.cpp,就一个函数,改动一句,加一句,具体如下,见高亮注释:</p>
voID RichText::formarRenderers(){ if (_ignoreSize) { float newContentSizeWIDth = 0.0f; float newContentSizeHeight = 0.0f; Vector<Node*>* row = (_elementRenders[0]); float nextPosX = 0.0f; for (ssize_t j=0; j<row->size(); j++) { Node* l = row->at(j); l->setAnchorPoint(Vec2::ZERO); l->setposition(nextPosX,0.0f); _elementRenderersContainer->addChild(l,1); Size iSize = l->getContentSize(); newContentSizeWIDth += iSize.wIDth; newContentSizeHeight = MAX(newContentSizeHeight,iSize.height); nextPosX += iSize.wIDth; } _elementRenderersContainer->setContentSize(Size(newContentSizeWIDth,newContentSizeHeight)); } else { float newContentSizeHeight = 0.0f; float *maxHeights = new float[_elementRenders.size()]; for (size_t i=0; i<_elementRenders.size(); i++) { Vector<Node*>* row = (_elementRenders[i]); float maxHeight = 0.0f; for (ssize_t j=0; j<row->size(); j++) { Node* l = row->at(j); maxHeight = MAX(l->getContentSize().height,maxHeight); } maxHeights[i] = maxHeight; newContentSizeHeight += maxHeights[i]; } float nextPosY = _customSize.height; for (size_t i=0; i<_elementRenders.size(); i++) { Vector<Node*>* row = (_elementRenders[i]); float nextPosX = 0.0f; nextPosY -= (maxHeights[i] + _verticalSpace); <strong >// custom:*** 2015.12.1,加上行间距 newContentSizeHeight += _verticalSpace;</strong> for (ssize_t j=0; j<row->size(); j++) { Node* l = row->at(j); l->setAnchorPoint(Vec2::ZERO); l->setposition(nextPosX,nextPosY); _elementRenderersContainer->addChild(l,1); nextPosX += l->getContentSize().wIDth; } }<span ><strong> // custom:*** 2015.12.1,重新设置高度 //_elementRenderersContainer->setContentSize(_contentSize); _elementRenderersContainer->setContentSize(Size(_contentSize.wIDth,newContentSizeHeight));</strong></span> delete [] maxHeights; }
注意:
1、需要先调用richText->formatText();,如下:
richText->formatText(); auto bbb = richText->getVirtualRendererSize();// 就可以获得高度了。
总结以上是内存溢出为你收集整理的RichText获取实际高度全部内容,希望文章能够帮你解决RichText获取实际高度所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)