UIView setNeedsDisplay Not in the main topic?

In my iPhone application, I have a secondary thread that I made to complete tasks in the background, and every few milliseconds, the view needs to be updated (not from the main thread). I tried the following code in a subclass of UIView:

[self performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone:NO]; 

This works great on a simulator, however, on my device, it is very laggy. The only thing I can think of is that the main thread is linked to the usual UIKit routines, i.e. my setNeedsDisplay is called for a long time when it should (after about half a second). I think this is because in another user-based code, I immediately call setNeedsDisplay and it works fine without any lag. The secondary stream has fewer side calculations than the user interface stream. This leads to some very bad visual effects in my application.

So, to summarize, how can I fix this problem?


UPDATE:

Is there any other way to show me that I need to update myself x times per second? what could be the best performance for me, if possible. I tried CADisplayLink without success ...

0
source share
1 answer

If your UI is banging so your call is delayed a lot, try updating the UI updates a bit and / or run startUpdate / endUpdate around the TableView update packages (e.g..)

I am doing something similar in MonoTouch, and I do not see any lag behind this value. All my updates are related to background threads in the same way as with your application.

Alternatively, if your main user interface can use some CPU time, try lowering the background thread's priorities and see if that helps.

+3
source

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


All Articles