在 Xcode 中制作和呈现应用程序教程视图 [英] making and presenting app tutorial views in Xcode
问题描述
我有一个不是超级直观的应用.我想截取混乱的屏幕截图,然后使用 MSpaint 编写说明和涂鸦.当用户第一次在应用程序中打开视图时,我想展示一系列更改过的屏幕截图以及一个确定"按钮.按 OK 将关闭屏幕截图,并且不会再次显示.有没有一种有效的方法来做到这一点?我是 Swift 和 Xcode 的新手.任何帮助将不胜感激
你需要使用 NSUserDefaults 保存应用程序的状态(是否显示教程) - NSUserDefaults 将应用程序运行之间的数据保存到设备存储.
然后您需要更改 AppDelegate 以根据您保存的值更改初始视图控制器 - 这样,如果教程已显示,它将不会再次显示.
假设您有名为 toturialShown
的变量将其设置为 false,每次运行检查其值以确定是否需要显示教程当用户点击关闭教程按钮时,使用 NSUSerDefaults 来保存这个新状态
商店
UserDefaults.standard.set(toturialShown, forKey: "toturialShownKey")
检索
UserDefaults.standard.bool(forKey: "toturialShownKey")
删除 - 如果您想从存储中完全删除它
UserDefaults.standard.removeObject(forKey: "toturialShownKey")
在 applicationDidFinishWithOptions
函数中的 AppDelegate(注意我没有测试代码)
var vc = ""如果toturialShown {vc = "普通VC"} 别的 {vc = "toturialVC"}让 initialViewController = mainStoryboard.instantiateViewController(withIdentifier: vc)让 initialViewController = mainStoryboard.instantiateViewController(withIdentifier: "LoginSignupVC")self.window?.rootViewController = initialViewControllerself.window?.makeKeyAndVisible()
注意1:您需要在故事板中为您的VC添加标识符
注意 2:如果您将初始 VC(在情节提要上)设置为常规 VC,则可以更改上面的代码以仅在教程尚未显示时以编程方式设置初始 VC,从而生成稍微更优雅的代码 >
I have an app that is not super intuitive. I want to take screenshots of the confusing screens and then use MSpaint to write instructions and doodles. When the user opens the view in the app for the first time, I want to present the series of altered screenshots along with an "OK" button. pressing OK will dismiss the screenshot and it will not be shown again. Is there an efficient way to do this? I am new to Swift and Xcode. Any help would be appreciated
You need to use NSUserDefaults to save the state of the app (tutorial shown or not) - NSUserDefaults saves data between the runs of the app to the device storage.
Then you need to change AppDelegate to change the initial view controller according to the value you saved - that way if tutorial has been shown it will not show again.
Assuming you have var called toturialShown
Set it to false and each run check its value to determine if the tutorial needs to be shown
When the user taps on dismiss tutorial button use NSUSerDefaults to save this new status
Store
UserDefaults.standard.set(toturialShown, forKey: "toturialShownKey")
Retrieve
UserDefaults.standard.bool(forKey: "toturialShownKey")
Remove - in case you want to delete it completely from storage
UserDefaults.standard.removeObject(forKey: "toturialShownKey")
On AppDelegate in applicationDidFinishWithOptions
function
(Note that I didn't test the code)
var vc = ""
If toturialShown {
vc = "regularVC"
} else {
vc = "toturialVC"
}
let initialViewController = mainStoryboard.instantiateViewController(withIdentifier: vc)
let initialViewController = mainStoryboard.instantiateViewController(withIdentifier: "LoginSignupVC")
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()
Note1: you need to add identifiers to you VCs in storyboard
Note 2: if you set your initial VC (on storyboard) to the regular VC, you can change the code above to set the initial VC programmatically only if the tutorial has not been shown, results in slightly more elegant code
这篇关于在 Xcode 中制作和呈现应用程序教程视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!