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:
- Subclass
UIImageView
- Use
UIImageView.image
property to update content - it gives a better results comparing to ordinary UIView withsetNeedsDisplay
/setNeedsDisplayInRect
methods. - Use
[self performSelector:@selector(setImage:) withObject:img afterDelay:0];
instead of justUIImageView.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
Is There Any Limitation to Distribution of Apps in iOS Enterprise Program
Pop the Current View Using Segues/Storyboard on iOS 5
Are There Any Analogues of [Nsstring Stringwithformat:] for Nsattributedstring
Detect Uiimageview Touch in Swift
Orienting iOS Splash Image to Landscape/Portrait According to Launch Orientation
Delete a Device from My Developer Account to Increase the Count
App Crashes After Executing Background Fetch Completionhandler
Playing Video Inline in Ionic/Phonegap (Webkit-Playsinline Not Working)
Swift Images Change to Wrong Images While Scrolling After Async Image Loading to a Uitableviewcell
Encryption with Rsa Public Key on iOS
Can Swift Closures Be Set to a Default Value When Used as a Parameter in a Function
Xcode/Swift 'Filename Used Twice' Build Error
Flutter:Not Connecting to iOS Simulator in Android Studio
Move Xcode Project Causes Red Text (Missing Files from Project)
Uiview/Calayer: Transform Triggers Layoutsubviews in Superview