第一个矩形返回无限帧 [英] First rect returning the infinite frame

查看:28
本文介绍了第一个矩形返回无限帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取添加到单元格中的 textview 中最后一个字符的位置矩形.当我重新加载单元格时会发生什么,然后此方法返回无限矩形.我不知道为什么会这样.请帮我改正.到目前为止,我的代码如下-

i am trying to get the position rect of the last character in textview which is added in a cell. what happens when i reload the cell then this method returns infinite rect. I don't know why this is happening. Please help me to correct it. My code so far is below-

UITextPosition *Pos2 = [_txt_EventName positionFromPosition: _txt_EventName.endOfDocument offset: 0];
    UITextPosition *Pos1 = [_txt_EventName positionFromPosition: _txt_EventName.endOfDocument offset: -1];

    UITextRange *range = [_txt_EventName textRangeFromPosition:Pos1 toPosition:Pos2];

    CGRect rect=[_txt_EventName firstRectForRange:range];

    CGPoint lastCharPoint=rect.origin;

推荐答案

我遇到了同样的问题(实际上是无意中发现了您的问题)并通过在我的文本上调用 layoutIfNeeded 解决了我的问题看法.在此调用之后,正确计算了返回的矩形.花了很多时间来解决这个问题.

I've been running into the same problem (actually found your question accidentally) and solved my problem by calling layoutIfNeeded on my text view. After this call the rectangle that gets returned is correctly calculated. Spent a lot of time figuring this out.

祝你好运Z.

这篇关于第一个矩形返回无限帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆