How to force a view to render itself?

前端 未结 4 1341
自闭症患者
自闭症患者 2020-12-13 07:24

In my app I have a number of small subviews. When the user taps a subview, I place one separate view over top of the tapped subview (same size) and then animate this separa

4条回答
  •  自闭症患者
    2020-12-13 07:59

    As I commented above, Joe asked something similar (as a more general question) here, to which Tom Swift provided an answer that manipulates the current run loop.

    His suggestion was to force the run loop through one iteration immediately after you call -setNeedsDisplay using the following code:

    [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode beforeDate: [NSDate date]];
    

    There are some caveats to this approach, which are discussed in the comments there.

    Also, it was pointed out there that

    [CATransaction flush];
    

    may also achieve the same effect of forcing an immediate redraw of the view.

提交回复
热议问题