Setneedsdisplayinrect: Causes the Whole View to Be Updated

setNeedsDisplayInRect: causes the whole view to be updated

Check this apple document

they said :

because of the way that iPhone/iPod touch/iPad updates its screen, the
entire view will be redrawn if you call -setNeedsDisplayInRect: or
-setNeedsDisplay:.

Also

Each UIView is treated as a single element. When you request a redraw, in part or whole, by calling -setNeedsDisplayInRect: or -setNeedsDisplay:, the entire view will be marked for updates.

so I think you need to use subviews to update independent rect of the whole View.

Why does a custom child view of a UIScrollView get redrawn entirely and not only partially and how to change this?

I think the reason is that in iOS a call to -setNeedsDisplayInRect: will always mark the entire view for updates. See a similar question here and this Technical Note.

A solution could be to split up your waveform view in several subviews and call setNeedsDisplay only for those with changed contents.

Implement drawRect: cause entire view to be updated

You probably have Core Animation layers enabled for your view or one of its ancestors. I think when you update a layer, the window server sees the entire contents as being updated, even if you only redrew part of it.

The Cocoa App template in recent versions of Xcode enables layers at the root view by default. The template in older versions of Xcode did not, and many of Apple's sample projects were created using older versions of Xcode.

Select your view in your storyboard or xib. Then choose View > Utilities > Show View Effects Inspector. If “Core Animation Layer” is enabled for the view or any of its ancestors, then the view is drawn into a layer. You can try disabling it to see if it makes a difference.

UIView with drawRect/update image performance issue on Retina displays

After spending several days I've came to unexpected (at least for myself) results.
I was able to achieve 30fps on retina iPad which is acceptable result for now.

The trick that worked for me was:

  1. Subclass UIImageView
  2. Use UIImageView.image property to update content - it gives a better results comparing to ordinary UIView with setNeedsDisplay/setNeedsDisplayInRect methods.
  3. Use [self performSelector:@selector(setImage:) withObject:img afterDelay:0]; instead of just UIImageView.image = img to set the updated image to UIImageView.

The last point is a kind of spell for me now however it gives the minimal necessary frame rate (even if the original image is redrawn fully each frame not only dirty regions).

My guess if why performSelector helped to gain fps for updating view in my case is that scheduling setImage on view's queue optimizes possible internal idles which may occur during touch event processing.
This is only my guess and if anyone can provide relevant explanation I'll be glad to post it here or accept that answer.



Related Topics



Leave a reply



Submit