简体   繁体   English

iOS状态恢复动画bug

[英]iOS state restoration animation bug

I just wanted to implement the iOS State-Restoration APIs in one of my Apps. 我只是想在我的一个应用程序中实现iOS State-Restoration API。 After finally getting it to work, I discovered that a ViewController that I present modally gets restored using an animation, which is not what I want. 在最终实现它之后,我发现我以模态方式呈现的ViewController使用动画来恢复,这不是我想要的。 I would expect my app to just be in the state I left it, but not having the user to see hot he got there. 我希望我的应用程序只是在我离开它的状态,但没有让用户看到他到那里的热。

So I went ahead and downloaded Apple Sample Code on that: https://developer.apple.com/library/ios/samplecode/StateRestore/Introduction/Intro.html and wanted to see if it happens there as well. 所以我继续下载Apple示例代码: https//developer.apple.com/library/ios/samplecode/StateRestore/Introduction/Intro.html并想看看它是否也在那里发生。 And it turns out that it does. 事实证明它确实如此。

Further 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 Apples Sample Code are doing something wrong, or if it's a bug in iOS? 你能否告诉我,我和Apples示例代码是否做错了,或者是否是iOS中的错误?

Btw. 顺便说一句。 I was testing on iOS8 我在iOS8上测试

Thanks for any help, Georg 感谢任何帮助,乔治

The following solution comes directly from Apple. 以下解决方案直接来自Apple。

In your app delegate, you should be implementing application:willFinishLaunchingWithOptions: (instead of or in addition to didFinishLaunching ). 在你的app委托中,你应该实现application:willFinishLaunchingWithOptions:代替didFinishLaunching或者除了didFinishLaunching )。 In your implementation, probably as the last line just before returning true (or YES if this is Objective-C), insert this line: 在您的实现中,可能是返回true之前的最后一行(如果这是Objective-C,则为YES),插入以下行:

self.window?.makeKeyAndVisible()

Or, if this is Objective-C: 或者,如果这是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. 请参阅下面的清单中的第3项。

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; (必需)在app appate中实现应用程序:shouldSaveApplicationState:和application:shouldRestoreApplicationState:methods; 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; restorationIdentifier属性; 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; 如果要保存特定视图的状态,请将非空字符串分配给其restorationIdentifier属性; see Preserving the State of Your Views. 请参阅保留您的观点状态。

  • (Required) Show your app's window from the application:willFinishLaunchingWithOptions: method of your app delegate. (必填)从​​应用程序显示应用程序窗口:willFinishLaunchingWithOptions:应用程序委托的方法。 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; (推荐)使用encodeRestorableStateWithCoder:和decodeRestorableStateWithCoder:这些对象的方法对视图状态和视图控制器进行编码和解码; 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; 使用应用程序对应用程序的任何版本信息或其他状态信息进行编码和解码:willEncodeRestorableStateWithCoder:和application:didDecodeRestorableStateWithCoder:应用程序委托的方法; 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. 充当表视图和集合视图的数据源的对象应实现UIDataSourceModelAssociation协议。 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. Apple示例代码似乎在Xcode 8上运行良好。

So I suppose no additional code changes would be required 所以我认为不需要额外的代码更改

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM