我想重绘视图
我想重画一个视图。 当我触摸按钮时,我的视图必须自行重绘。 (必须调用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为这里存在一些误解。让我们把事情搞清楚:
viewWillAppear:
与视图的绘制无关。setNeedsDisplay
不会立即重绘视图,但我们谈论的是毫秒。所以这根本不相关。由于您希望调用
viewWillAppear:
,我假设您所说的重绘视图实际上应该称为重新布局视图。我假设您在 viewWillAppear: 中所做的是设置视图的框架,并可能添加/删除和/或显示/隐藏一些视图。我建议您将该代码从
viewWillAppear:
中移出,并移入它自己的方法中,当您点击按钮时,该方法将从viewWillAppear:
调用。由于您没有提供
viewWillAppear:
代码,这一切都基于假设,因此如果我的假设错误,请告诉我,并请提供您的“重绘”代码。I think there are some misunderstandings here. Let's set things straight:
viewWillAppear:
has nothing to do with the drawing of the view.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 inviewWillAppear:
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 fromviewWillAppear:
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.如果没有更多详细信息,很难确切地知道您需要什么,但我可能建议您查看 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.