开发者

I want to redraw a view

开发者 https://www.devze.com 2023-02-21 11:29 出处:网络
I want to redraw a view. When I touch a button, my view have to redraw itself. (have to call viewWillAppear)

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 meth开发者_如何学Pythonod 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.


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.


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.


[yourViewName setNeedsDisplay];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号