更改 contentInset 后强制 UITextView 重新显示?
我更改了 contentInset。如何强制它更新显示以反映新值?
I change the contentInset. How can I force it to update the display to reflect the new value?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我发现它确实立即更新了 contentInset,但看起来不像,因为它调整了 UITextView 滚动到的位置,使得 UITextView 的显示不会改变。
通过滚动回左上角,我认为您正在寻找使用新内容插图更新显示的效果:
I found that it did update the contentInset immediately, but it didn't look like it because it adjusts the location that the UITextView is scrolled to such that the display of the UITextView doesn't change.
By scrolling back to the top-left corner, it has the effect I think you're looking for of updating the display with the new content inset:
如果不是同一个问题,我也有类似的问题。
我能够让 setNeedsDisplay 工作,但您必须使用它并将其放置在正确的视图上并以正确的顺序调用它,否则它将无法工作。
我有一个想要重用的视图,我所做的只是更改一个 UITextView 和视图上的图像,具体取决于它的打开位置。我可以通过控制器上的插座访问该标签。我可以看出我的作业正在工作,因为更改后的值将在我第二次返回修改后的视图时显示。在我将 setNeedsDisplay 连接到控制器视图(不是 UITextView,因为我尝试过但没有采取)之前,我无法获得任何先前建议的工作方法,并且我必须在将文本更改为之前执行此操作如果我在 setText 之后拨打电话,它就不起作用。无论如何,也许以这种方式和顺序进行设置可能适合您。
I have a similar issue if not the same issue.
I was able to get setNeedsDisplay to work, but you have to use it and place it on the right view and call it in the right order or it won't work.
I have a view that I want to reuse, all I change is a UITextView and an image on the view depending on where it is opened from. I have the label accessible via Outlet on the controller. I could tell that my assignment was working as the changed value would show up the 2nd time I went back to the modified view. I could not get any of the previously suggested ways to work until I hooked up setNeedsDisplay on the controllers view (NOT the UITextView, as I tried that and it did not take) and I had to do it just before I make the text change as it did not work if I made the call after the setText. Anyway, maybe setting it up in this way and in that order may work for you.
尝试使用
[textView setNeedsDisplay]
。Try using
[textView setNeedsDisplay]
.我能想到的唯一方法是使用新属性重新初始化它。不过,听起来有点浪费。
The only way I could think of is to re-init it with the new properties. Sounds like a waste, though.
您还可以尝试
[textViewlayoutIfNeeded]
或[textViewlayoutSubviews]
。我收回它,该方法的文档表明:
和
You could also try
[textView layoutIfNeeded]
or[textView layoutSubviews]
.I take it back, the documentation of this method suggests that:
and
[textView setNeedsLayout] 这样做吗?
Does [textView setNeedsLayout] do it?