仅将 UIView 添加为首次运行视图
我想向我的应用程序添加一个欢迎视图,其中描述了说明等。
我希望该视图仅在应用程序首次启动时出现一次...然后在后续启动时转到我的应用程序的主视图...这是一个导航控制器。
跟踪发布/实施这个想法的最佳方法是什么?
谢谢。
I would like to add a Welcome view to my app which describes the instructions etc.
I would like this to appear only once when the app is first launched... then with subsequent launches go to my app's main view... which is a navigation controller.
What is the best way to track launches/ implement this idea?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在导航控制器的根控制器(通常作为第一个可见的视图控制器)中,使用
presentModalViewController:animated:
的初始指令激活模态控制器。您可能想从
viewWillAppear:
中调用它。不要对模态视图控制器的呈现进行动画处理(否则您会看到下面的内容),但在关闭它时进行动画处理 - 它看起来非常优雅。使用UserDefaults来存储已经显示的信息,并且不再显示。
In your root controller of a navigation controller (the view controller that is normally visible as first one), activate a modal controller with those initial instructions with
presentModalViewController:animated:
.You probably want to call it from within
viewWillAppear:
. Do not animate presenting of modal view controller (otherwise you see what's below), but animate when dismissing it - it looks really elegant.Use UserDefaults to store the information that it had already been shown, and do not show it anymore.
NSUserDefault 正是为此类事情而设计的。
NSUserDefault is made exactly for these kind of things.
我同意 JustSid 的观点。在我的应用程序中,我为此用途设置了一个 NSUserDefault 值,然后在 viewDidLoad 时将其关闭。该应用程序会检查该值,但除非该应用程序已卸载,否则不会触发该消息。
I would agree with JustSid. In my app, I set a NSUserDefault value for that use and then turned it off when the viewDidLoad. The app checks for the value but, unless the app is uninstalled, will not fire the message.