iOS state restoration animation bug

 ̄綄美尐妖づ 提交于 2019-12-04 06:29:30

The following solution comes directly from Apple.

In your app delegate, you should be implementing application:willFinishLaunchingWithOptions: (instead of or in addition to didFinishLaunching). In your implementation, probably as the last line just before returning true (or YES if this is Objective-C), insert this line:

self.window?.makeKeyAndVisible()

Or, if this is Objective-C:

[self.window makeKeyAndVisible];

It turns out that this was always needed, but the documentation has never been clear about it.

From documentation: Preserving Your App’s Visual Appearance Across Launches

See the 3rd item from the checklist below.

Checklist for Implementing State Preservation and Restoration

Supporting state preservation and restoration requires modifying your app delegate and view controller objects to encode and decode the state information. If your app has any custom views that also have preservable state information, you need to modify those objects too.

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

  • (Required) Implement the application:shouldSaveApplicationState: and application:shouldRestoreApplicationState: methods in your app delegate; see Enabling State Preservation and Restoration in Your App.
  • (Required) Assign restoration identifiers to each view controller you want to preserve by assigning a non empty string to their
    restorationIdentifier property; see Marking Your View Controllers for Preservation.

    If you want to save the state of specific views too, assign non empty strings to their restorationIdentifier properties; see Preserving the State of Your Views.

  • (Required) Show your app’s window from the application:willFinishLaunchingWithOptions: method of your app delegate. The state restoration machinery needs the window so that it can restore scroll positions and other relevant bits of your app’s interface.

  • Assign restoration classes to the appropriate view controllers. (If
    you do not do this, your app delegate is asked to provide the
    corresponding view controller at restore time.) See Restoring Your
    View Controllers at Launch Time.

  • (Recommended) Encode and decode the state of your views and view controllers using the encodeRestorableStateWithCoder: and decodeRestorableStateWithCoder: methods of those objects; see Encoding and Decoding Your View Controller’s State.
  • Encode and decode any version information or additional state information for your app using the application:willEncodeRestorableStateWithCoder: and application:didDecodeRestorableStateWithCoder: methods of your app delegate; see Preserving Your App’s High-Level State.

  • Objects that act as data sources for table views and collection views should implement the UIDataSourceModelAssociation protocol. Although not required, this protocol helps preserve the selected and visible items in those types of views. See Implementing Preservation-Friendly Data Sources.

Apple sample code seems to work fine on Xcode 8.

So I suppose no additional code changes would be required

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!