SetNeedsDisplay and subviews

In my opinion, setNeedsDisplay only affects the view it setNeedsDisplay . Is there an easy way to say "update this look and all its sub-points, recursively?"

In response to the comments, here is my situation: I have a custom view

 @interface ContainerView : UIView 

This view does not implement drawRect . My xib has an instance (called container ) of a ContainerView that has some (custom) sub items added to it. When in code I say

 [container setNeedsDisplay] 

I expect these routines to be updated. Where am I mistaken?

+4
source share
2 answers

Well, the UIView draws itself when its first displayed. CALayers no. Calling setNeedsDisplay on a UIView indicates that it is dirty, it will automatically redraw all SubViews as well (causing drawrect in all subviews). Calling setNeedsDisplay on a CALayer does not have the same effect; it will not redraw sublayers. Hope this helps.

Hello

Ref
IOS 7 programming Pushing the limits of Rob Napir, Mugunt Kumar

0
source

UIView class reference

The UIView class defines a rectangular area on the screen and interfaces for managing content in this area. At run time, the view object handles the rendering of any content in its area, and also handles any interactions with this content.

setNeedsDisplay
Marks recipient rectangles with whole borders because they need to be redrawn.
Note. If your view is supported by the CAEAGLLayer object, this method is not affected. It is intended to be used only with views that use proprietary drawing technologies (such as UIKit and Core Graphics) to render their contents.

Subsections are within the boundaries of the view, so the view will ask him how to display, what to display.
Are you trying to meet some case that repeats this definition?
If you are executing your own subclass of UIView, you need to handle the entire screen yourself in drawRect:

-1
source

Source: https://habr.com/ru/post/1389143/


All Articles