What multithreading methods are available for iPhone OS, and what should I use?

Problem: I created a class that plays an animation of a 300 x 300 pixel image sequence consisting of 100 frames. This class has the -start method, which starts the animation, and then the -animate: method, which goes through the frames. In each frame, it extracts a large fragment of the raster data from png, wraps it in UIImage and assigns this property to the UIImageView image. Then it calls the deferred selector on its own to take the following frame:

[self performSelector:@selector(animate:) withObject:nil afterDelay:delay];

the animation itself is smooth, but the entire user interface freezes until it ends. On the iPhone Simulator, the user interface does not freeze. Therefore, I assume that when performing this animation, the processor runs at 100%.

Now the question arises: which multithreading method or strategy can help in this situation?

Should I start viewing POSIX? Or any other API / Library / Framework? Or should I rely on NSObject methods to create threads or use NSThread for this?

I tried to put the whole animation in a new NSThread thread, but that doesn't help anything. As far as I know, I have to call any user interface code in the main thread. Therefore, by updating the UIImageView image property during animation, this should be done in the main thread. So, the only real part where I could “save time” for UI-responsiveness is extracting bitmap image data from PNG? Or is there something else that will help?

+3
3

,

, . . .

, , , " " PerformSelectorOnMainThread: ( - , ), , PerformSelectorOnMainThread, , , .

:

. 9media.com/blog/?p=195

. forums.macrumors.com/showthread.php?t=683250

. www.xprogress.com/post-36-threading-tutorial-using-nsthread-in-iphone-sdk-objective-c

, NSThread.

-isdi -

+1

. , Object Alloc, , .

0

, Shark Time Profile ( ). ( , ) , . , . . Mo Dejong , 30 480x320 PNG 15 FPS iPhone .

, iPhone : NSThreads NSOperations . NSThreads ( detachNewThreadSelector: toTarget: withObject: NSObject SelectorInBackground: withObject:), . NSOperations NSOperationQueues , , . , NSOperationQueue .

NSOperation ( Mac). , , -, . NSOperationQueues, . , . ​​ . , NSOperation , , .

0
source

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


All Articles