Fix iOS status animation

I just wanted to implement the iOS State-Restoration API in one of my applications. After it finally started working, I found that the ViewController, which I represent modally, is being restored using animation, which I don't want. I would expect my application to just be in the state that I left, but not having the user to see how it got there.

So, I went ahead and downloaded the Apple Sample code on this: https://developer.apple.com/library/ios/samplecode/StateRestore/Introduction/Intro.html and wanted to see what was going on there. And it turns out that this is so.

In addition, there is a warning in the logs:

Unbalanced calls to begin/end appearance transitions for <UINavigationController: 0x7b0512b0>. 

Can you tell me if I and, obviously, the sample code for apple examples do something wrong, or if this is a bug in iOS?

Btw. I tested iOS8

Thanks for any help, Georg

+6
source share
3 answers

The next solution comes directly from Apple.

In your application, you must implement application:willFinishLaunchingWithOptions: (instead of or in addition to didFinishLaunching ). In your implementation, probably as the last line before returning true (or YES if it is Objective-C), insert this line:

 self.window?.makeKeyAndVisible() 

Or, if it is Objective-C:

 [self.window makeKeyAndVisible]; 

Turns out it was always necessary, but the documentation was never clear.

+20
source

From the documentation: Saving your Visual Appearance applications on all starts

See the 3rd item from the checklist below.

Checklist for implementing state conservation and restoration

Support for saving and restoring state requires changing your application delegate and viewing controller objects to encode and decode state information. If your application has any user views that also contain information about the save state, you also need to modify these objects.

When adding save and restore state to your code, use the following list to remind you of the code you need to write.

  • (required) Application implementation: shouldSaveApplicationState: and application: shouldRestoreApplicationState: delegate methods in your application; see "Securing and restoring state in your App.
  • (required) Assign recovery identifiers to each view controller you want to save by assigning a non-empty string to their restoreIdentifier property; see "Labeling View Controllers" for Saving.

    If you want to preserve the state of certain views, assign non-empty strings to their recovery properties; see Saving The status of your views.

  • (required). Show application window from application: willFinishLaunchingWithOptions: delegate your application method. State restoration equipment needs a window so that it can restore scroll positions and other relevant bits of your application interface.

  • Assign recovery classes to the appropriate view controllers. (If
    you donโ€™t do this, the delegate of your application is asked to provide the appropriate view controller during recovery.) See โ€œRestoring yourโ€ View controllers during startup.

  • (recommended) Encode and decode the state of your views and view controllers using encodeRestorableStateWithCoder: and decodeRestorableStateWithCoder: methods of these objects; See Encoding and decoding the status of View controllers.
  • Encode and decode any version information or additional state information for your application using application: willEncodeRestorableStateWithCoder: and application: didDecodeRestorableStateWithCoder: delegate your application methods; see Saving high-level state applications.

  • Objects that act as data sources for viewing tables and collection types must implement the UIDataSourceModelAssociation protocol. Although not required, this protocol helps save selected and visible items in these types of views. See "Implementation of conservation-friendly" Data Sources.

+1
source

Apple Code Sample seems to work fine on Xcode 8.

Therefore, I do not assume that any additional code changes are required.

-1
source

Source: https://habr.com/ru/post/976684/


All Articles