IPhone uiview refresh

Source: Internet
Author: User

It should be clear that if you want to refresh a uiview, call setneedsdisplay.

The problem is, when will the uiview be refreshed after you call setneedsdisplay of a uiview?

After investigation, we found that it should be refreshed at the final stage of a runloop.

What is a runloop? I personally think it can be simply understood as an event handling process.

For example, the user clicks two runloops on the screen.

When the user presses, a series of processing operations...> touchesbegan function of uiview> A series of processing operations here is a runloop

When the user looks up, a series of processing-> the touchesend function of uiview-> A series of processing-here is another runloop

In general, calling setneedsdisplay in the touches event processing function of uiview ensures that the interface is refreshed before the next touches event (no matter how many times you call setneedsdisplay in a touches event processing function, the interface will only be refreshed once ).

 

However, there are some exceptions. For example, uiscrollview.

Because uiscrollview needs to determine whether the current user operation is dragged, it will delay the callback touches processing function. It may appear that the touches processing function is called back multiple times in a runloop at the same time.

If you have done something in uiscrollview touchesbegan to change the interface, then restore the interface in touchesend.

It is very likely that the interface has not been changed and you will not see a process of restoring the interface.

What if you want to display the interface changes?

One feasible method is to call setneedsdisplay after the interface is changed in other threads.

Nscondition may be suitable for this situation.

 

In addition, if the setneeddisplayinrect function is a runloop that calls different regions for Refresh multiple times, it only calls drawrect once, multiple Regions are combined during the call (the drawrect parameter is the combined region ).

The combination principle seems to be to use the smallest rectangle to install the multiple areas you want to refresh.

If you call a refresh in the lower left corner and upper right corner continuously, the actual call to drawrect is probably the frame of your entire uiview.

 

I am so confused that I don't know whether normal humans can understand it.

There is no guarantee that the above conclusion is correct. You 'd better write a demo to verify it yourself.

-By anerevol

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.