Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to reduce unnecessary drawing in ios

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you "how to reduce unnecessary rendering in ios", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to reduce unnecessary rendering in ios" this article.

Shows an upgraded version of the-addBrushStrokeAtPoint: method that redraws only the area near the frontline brush. In addition, the area near the previous line brush will also be refreshed, and we can also use CGRectIntersectsRect () to avoid redrawing any old line brush so as not to cover the updated area. Doing so will significantly improve the efficiency of painting.

SetNeedsDisplayInRect: to reduce unnecessary rendering

The single-threaded nature of UIKit means that the host graph is unobstructed and updated on the main thread, which means that drawing interrupts user interaction and even makes the entire app appear unresponsive. There's nothing we can do about it, but it would be better if we could prevent users from waiting for the drawing to be finished.

To solve this problem, there are some methods that can be used: in some cases, we can speculatively draw content on another thread in advance, and then set the resulting picture directly to the content of the layer. This may not be very convenient to implement, but it is feasible under certain circumstances. CoreAnimation provides some options: the CATiledLayer and drawsAsynchronously properties.

In addition to splitting the layer into independently updated chunks again (similar to the concept of automatic update of dirty rectangles), CATiledLayer has an interesting feature: the-drawLayer:inContext: method is called simultaneously for each chunk in multiple threads. This avoids blocking user interaction and can take advantage of multi-core new films to draw faster. Only a small piece of CATiledLayer is an easy way to update picture views asynchronously.

Different from the asynchronous drawing used by CATiledLayer

In iOS6, Apple introduced this curious attribute for CALayer. The drawsAsynchronously attribute changes the CGContext passed in-drawLayer:inContext: to allow CGContext to delay the execution of drawing commands so as not to block user interaction.

It is not the same as the asynchronous drawing used by CATiledLayer. Its own-drawLayer:inContext: method is called only on the main thread, but CGContext does not wait for the end of each drawing command. Instead, it queues the command and performs the actual drawing in the background thread one by one when the method returns.

According to Apple. This feature works best on views that need to be redrawn frequently (such as our drawing application, or things like UITableViewCell), and is not very helpful for layer content that is only drawn once or rarely redrawn.

The above is all the content of the article "how to reduce unnecessary drawing in ios". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report