I'm trying to pre-load an array of texture atlases during which a UIActivityIndicator is displayed. Once the textures are loaded I want to stop the activity indicator using the .stopAnimating() method. I've inserted breakpoints and found that the compiler does get to the .stopAnimating() method, but nothing happens...the indicator continues...
What am I doing wrong here?
class Menu: SKScene {
var activityInd: UIActivityIndicatorView!
override func didMoveToView(view: SKView) {
activityInd = UIActivityIndicatorView(activityIndicatorStyle: .WhiteLarge)
activityInd.center = CGPointMake(self.frame.midX, self.frame.midY)
activityInd.startAnimating()
scene!.view?.addSubview(self.activityInd)
SKTextureAtlas.preloadTextureAtlases([saxAtlas, saxIdleAtlas, drumAtlas, drumIdleAtlas, pianoAtlas, pianoIdleAtlas, bassAtlas]) { () -> Void in
self.activityInd.stopAnimating()
}
}
Usually when you want to stop an activity indicator you just call removeFromSuperview()
as it's no good to have a static activity indicator sitting there doing nothing, and that's all that stopAnimating()
gives you.
You should also be calling this method on the main thread, since preloadTextureAtlases
is a background task and just about anything prefixed with 'UI' needs to be run on the main thread.
SKTextureAtlas.preloadTextureAtlases([saxAtlas, saxIdleAtlas, drumAtlas, drumIdleAtlas, pianoAtlas, pianoIdleAtlas, bassAtlas]) { () -> Void in
dispatch_async(dispatch_get_main_queue()) { () -> Void in
self.activityInd.stopAnimating()
}
}