Igor Korolev Igor Korolev - 1 month ago 18
iOS Question

How not to block UI interaction simultaneously with intensive task on the main thread

I have several child controllers. One of them is out of visible frame.

When I should update UI in invisible controller it uses 100% of CPU for a few seconds that blocks UI interaction in visible controller (gestures don't work).

Unfortunately I can't update UI not on the main thread.
Is there any opportunity not to block UI in my case?

Answer

Finally I used NSOperationQueue to break the code into blocks. CPU is still used by 100% (Iphone 4s), but UI is not blocked.

NSOperationQueue *queue = [NSOperationQueue mainQueue];
queue.qualityOfService = NSQualityOfServiceUserInteractive;
queue.maxConcurrentOperationCount = 1;

[queue addOperationWithBlock:^{
    ...some UI Updates
}];
[queue addOperationWithBlock:^{
    ...some UI Updates
}];
[queue addOperationWithBlock:^{
    ...some UI Updates
}];
Comments