4
votes

This is for my swift based sprite kit game. It was fine on iOS 8, but i notice this delay after I started to run the game on an iOS 9 device. Before my game goes back into the game scene from a menu or some other view that was presented, there's this one to two seconds of delay after the dismiss button is clicked in one of those views.

I dismiss the views with this code:

self.dismissViewControllerAnimated(true, completion: nil)

To solve this problem, I tried running the code inside the main dispatch queue. It didn't help.

dispatch_async(dispatch_get_main_queue()) {
     self.dismissViewControllerAnimated(true, completion: nil)
}

Checked if there's anything in my game view loaded methods that might cause a delay but looks good. The code doesn't have issues in iOS 8 anyways.

Anybody had a similar problem and perhaps fixed it?

EDIT: Realized that the game scene starts executing already and by the time my view is dismissed, i can see the animations are already playing. Example, a 3 seconds animation is already in mid way completion.

EDIT 2: This issue does not happen on iOS 9 with iPhone 4s but happens with later versions, in my case with iPhone 6. It could be the new Metal rendering causing this. 4s doesn't have Metal. New iOS patch didn't get this fixed as well.

EDIT 3 Same lag happens when using two SKViews as well. To get rid of UIControlView to SKView transition lag, I tried to replace my UIView, it's controls and UIControlView with another SKScene. Even when I set the transition time to zero seconds, there's a delay when the SKView gets dismissed. This time lag happens both ways, so it's worse. Current version iOS 9.2, Xcode 7.2.

2
I think I also have this problem, it happens on my iPhone 6 but not in the Simulator. I tried running it on the main queue, and I tried removing my SpriteKit scene entirely (just leaving the SKView) and it still happens. Did you find a solution? Is this question related? stackoverflow.com/questions/23437568/…kamatsu
Yes same for me. This does not happen on the simulator but happens on my iPhone 6 and 5s. Both phones have metal rendering in iOS9 for SpriteKit. It doesn't happen on 4s with iOS9. I saw that link you posted before and it didn't relate to my case. I tried few example projects to test it. Another test I did was to try doing a transition between two SKViews instead of UIViewController to SKView. Same lag exists in that case as well, between both SKViews there's a lag even when you set the transition time to zero seconds. So I still don't have a solution.Ali Hus

2 Answers

12
votes

It's a bit late, but maybe it will help someone else. I had similar problem (game in SpriteKit - delay when dismissing a MenuViewController presented by ViewController with SKView) and here is what helped:

When you presenting fullscreen ViewController (with menu, settings etc) set modalPresentationStyle to .OverFullScreen.

Here's short info what's happening (form Apple View Controller Programming Guide for iOS):

When presenting a view controller using the UIModalPresentationFullScreen style, UIKit normally removes the views of the underlying view controller after the transition animations finish. You can prevent the removal of those views by specifying the UIModalPresentationOverFullScreen style instead. You might use that style when the presented view controller has transparent areas that let underlying content show through.

I suppose this delay is related to process of restoring underlying views what may be complex in case of SKView with presented scene

0
votes

Okay. I had the same problem.

My project was created with very early version of Xcode. I have created new ViewController and call pushViewController() method. There was a delay for 2-3 seconds.

I have deleted this ViewController and created one more. The new one has the same name and the same class in Interface Builder.

The delay has disappeared. It works. It is magic, but it works.