Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

modal view controller animates on state restoration

I have a strange problem with state restoration for a Universal app with Split View Controller.

The strange thing that I am doing things in a very standard way using a Storyboard and segues and with a restoration identifier for alle relevant view controllers. There is not really any code, as the logic is in the Storyboard and a minimal XCode project shows this.

The problem is with a settings screen that is shown modally as a form sheet presented from the split view controller. My view controller hierarchy ends up correct, but the transition doesn't really make sense. For some reason state restoration animates the modal controller into place.

Since the screen starts out with a screenshot from the last time the app was running, with the settings controller already present, the animation is just visual noise.

I have tried to disable animation on the segue which is respected when entering the settings interactively, but when state restoration does the same thing, the animation is there.

What is the standard way to avoid this?

like image 961
palmin Avatar asked Aug 22 '16 11:08

palmin


1 Answers

Calling self.window?.makeKeyAndVisible() in application(_:willFinishLaunchingWithOptions:) solved the issue for me.

More info in the docs:

Important

If your app relies on the state restoration machinery to restore its view controllers, always show your app’s window from this method. Do not show the window in your app’s application:didFinishLaunchingWithOptions: method. Calling the window’s makeKeyAndVisible method does not make the window visible right away anyway. UIKit waits until your app’s application:didFinishLaunchingWithOptions: method finishes before making the window visible on the screen.

like image 182
Franco Solerio Avatar answered Nov 11 '22 06:11

Franco Solerio