DrawRect causes slow scrolling, even if it is not called

In my application, I have scrollView with about 20 subviews in it. Each of these subzones has a drawRect method, which currently looks like this:

- (void)drawRect:(CGRect)rect { NSLog(@"drawRect called"); } 

When additional objects are added, drawRect is called, however when scrolling it is very slow, although drawRect is not called again.

If I remove the implementation for drawRect, the scroll is completely normal. Even if I can't get rid of slow scrolling, is there an alternative to drawRect that I could use instead?

+4
source share
2 answers

Why are you calling drawRect if it only registers that it was called? If this is just a goal for you, then just do not call it. In fact, I believe that when you first create a class that inherits from UIView, which has a drawRect method in it, it is commented on and above the commented drawRect method, it says something like strings "Do not call this method if it doesnโ€™t makes no drawing on the screen since it takes up a significant amount of memory. " In principle, do not call it in your case.

Hope this helps.

+1
source

You can try to assign pre-drawn CGImages to the contents of each custom CALayer view before the view first appears. This can be faster than using drawRect to customize the look.

0
source

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


All Articles