how to display UIActivityIndicatorView BEFORE rotation begins

前端 未结 4 2005
既然无缘
既然无缘 2020-12-12 06:33

I\'d like to display an activity indicator BEFORE the work undertaken by willAnimateRotationToInterfaceOrientation:duration: begins. Most of the time in my

4条回答
  •  时光取名叫无心
    2020-12-12 07:14

    Either execute the heavy lifting in a background thread and post the results in the foreground thread to update the UI (UIKit is only thread safe since iOS 4.0):

    [self performSelectorInBackground:@selector(simulateHardWorkNeededToGetDisplayInShapeBeforeRotation) withObject:nil]
    

    Or you can schedule the heavy lifting method to be executed after the rotation took place:

    [self performSelector:@selector(simulateHardWorkNeededToGetDisplayInShapeBeforeRotation) withObject:nil afterDelay:0.4]
    

    But these are only hacks and the real solution is to have proper background processing if your UI needs heavy processing to get updated, may it be in portrait or landscape. NSOperation and NSOperationQueue is a good place to start.

提交回复
热议问题