我如何知道视图控制器是由于推送而加载还是由于 UINavigationController 上弹出后的视图重建而加载?

发布于 2024-11-03 22:24:34 字数 448 浏览 0 评论 0原文

我将 UINavigationController 与多个视图控制器一起使用。其中一个视图控制器是在 loadview: 中以编程方式构建的,它会执行一些自定义动画以从前一个视图控制器进行转换。

所以这些动画应该只在视图控制器被推送时发生,因为在推送之前创建视图控制器时只调用一次 loadview ,这通常都工作得很好。

然而,当其他一些视图控制器被推送并且内存紧张时,视图会被系统自动卸载并重建(如果在其他视图控制器弹出后再次出现)。
当然,我不希望发生转换动画,因为如果它们不遵循前一个视图控制器上的推动,它们看起来会很奇怪。

我可能可以保留一些状态信息,或者发送通知,自己知道是否由于pushViewController或popViewController而调用了loadview,但我想知道是否有任何内置方法可以知道loadView是否发生,因为视图是首先构造的时间,还是因为之前被清除了?

I use a UINavigationController with several viewcontrollers. One of the viewcontrollers, which is constructed programmatically in loadview:, does some custom animations to do a transition from the previous viewcontroller.

So these animations should only happen when the viewcontroller is pushed, since loadview is only called once when creating the viewcontroller before the push, this usually all works perfectly fine.

However when some other viewcontrollers get pushed, and memory gets tight, the view gets unloaded automatically by the system and reconstructed if it appears again after the other viewcontrollers are popped.
Naturally I don't want the transistion animation to occur, as they look rather weird if they don't follow a push on the previous viewcontroller.

I could probably keep some state info, or send notifications, myself to know if the loadview is called because of a pushViewController or a popViewController, but I wondered if there's any built in way to know if a loadView happens because the view is constructed the first time, or because it was previously purged?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷爱 2024-11-10 22:24:35

不,你在 UIViewController 中没有这样的内置方法,但你可以依靠 -(void)viewDidUnload 来知道你的视图不应该在 viewDidLoad 中显示你的动画。
所以是的,这意味着保留一些状态信息。

No you don't have such a built in method in UIViewController, but you could rely on -(void)viewDidUnload, to know that your view should not display your animation in the viewDidLoad.
So yes, that means keeping some state info.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文