我想重绘视图

发布于 2024-10-29 02:56:14 字数 241 浏览 2 评论 0原文

我想重画一个视图。 当我触摸按钮时,我的视图必须自行重绘。 (必须调用 viewWillAppear)

但是视图的 setNeedDisplay 方法不会立即重绘自身。 因为我要立即重画,所以这个方法不适合我。

我尝试删除 viewController 的所有视图的子视图并更改 viewController 的 视图到其他视图。 但这些都不起作用。 (不要重画)

我非常需要你的帮助。

感谢您的阅读。

I want to redraw a view.
When I touch a button, my view have to redraw itself. (have to call viewWillAppear)

But view's setNeedDisplay method doesn't redraw itself immediately.
Because I have to redraw it immediately, the method is not suitable to me.

I tried to remove all of viewController's view's subviews and to change viewController's
view to other view.
But these didn't work. (don't redraw)

I need your help acutely.

Thank you for your reading.

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

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

发布评论

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

评论(3

ま昔日黯然 2024-11-05 02:56:14

我认为这里存在一些误解。让我们把事情搞清楚:

  1. viewWillAppear: 与视图的绘制无关。
  2. 确实,setNeedsDisplay 不会立即重绘视图,但我们谈论的是毫秒。所以这根本不相关。

由于您希望调用 viewWillAppear: ,我假设您所说的重绘视图实际上应该称为重新布局视图。我假设您在 viewWillAppear: 中所做的是设置视图的框架,并可能添加/删除和/或显示/隐藏一些视图。

我建议您将该代码从 viewWillAppear: 中移出,并移入它自己的方法中,当您点击按钮时,该方法将从 viewWillAppear: 调用。

由于您没有提供 viewWillAppear: 代码,这一切都基于假设,因此如果我的假设错误,请告诉我,并请提供您的“重绘”代码。

I think there are some misunderstandings here. Let's set things straight:

  1. viewWillAppear: has nothing to do with the drawing of the view.
  2. It's true that setNeedsDisplay doesn't redraw the view instantly, but we're talking milliseconds. So that's not even relevant.

Since you want viewWillAppear: to be called I'm assuming that what you call redrawing the view really should be referred to as relayouting the view. I assume that what you do in viewWillAppear: is setting the frames of you're views and possibly add/remove and/or show/hide some views.

I suggest that you move that code out of viewWillAppear: and into it's own method that will be called from viewWillAppear: and when you tap the button.

Since you don't provide your viewWillAppear: code this is all based on assumptions, so if my assumptions are wrong, please let me know and please do provide your "redraw" code.

残龙傲雪 2024-11-05 02:56:14

如果没有更多详细信息,很难确切地知道您需要什么,但我可能建议您查看 UIView::setNeedsDisplay。这将反过来导致您的视图drawRect:被调用,您可以在其中更新绘图。

Without more details it's hard to know exactly what you need but I might suggest you look at UIView::setNeedsDisplay. This will in turn cause your views drawRect: to be called where you can update the drawing.

浅语花开 2024-11-05 02:56:14
[yourViewName setNeedsDisplay];
[yourViewName setNeedsDisplay];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文