更改 contentInset 后强制 UITextView 重新显示?

发布于 2024-10-10 14:45:57 字数 40 浏览 4 评论 0原文

我更改了 contentInset。如何强制它更新显示以反映新值?

I change the contentInset. How can I force it to update the display to reflect the new value?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

格子衫的從容 2024-10-17 14:45:57

我发现它确实立即更新了 contentInset,但看起来不像,因为它调整了 UITextView 滚动到的位置,使得 UITextView 的显示不会改变。

通过滚动回左上角,我认为您正在寻找使用新内容插图更新显示的效果:

[textView scrollRectToVisible:CGRectMake(0,0,1,1) animated:NO];

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:

[textView scrollRectToVisible:CGRectMake(0,0,1,1) animated:NO];
鸠魁 2024-10-17 14:45:57

如果不是同一个问题,我也有类似的问题。

我能够让 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.

稍尽春風 2024-10-17 14:45:57

尝试使用[textView setNeedsDisplay]

Try using [textView setNeedsDisplay].

邮友 2024-10-17 14:45:57

我能想到的唯一方法是使用新属性重新初始化它。不过,听起来有点浪费。

The only way I could think of is to re-init it with the new properties. Sounds like a waste, though.

浅忆 2024-10-17 14:45:57

您还可以尝试[textViewlayoutIfNeeded][textViewlayoutSubviews]

我收回它,该方法的文档表明:

这个的默认实现
方法什么都不做。

您不应该调用此方法
直接。

You could also try [textView layoutIfNeeded] or [textView layoutSubviews].

I take it back, the documentation of this method suggests that:

The default implementation of this
method does nothing.

and

You should not call this method
directly.

司马昭之心 2024-10-17 14:45:57

[textView setNeedsLayout] 这样做吗?

Does [textView setNeedsLayout] do it?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文