Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delay when dismissing a viewController on iOS 9

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.

like image 221
Ali Hus Avatar asked Dec 15 '22 11:12

Ali Hus


1 Answers

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

like image 167
ukaszm Avatar answered Dec 27 '22 10:12

ukaszm