【问题标题】:Presenting walkthrough in iOS app在 iOS 应用中演示演练
【发布时间】:2014-04-23 17:12:30
【问题描述】:

我正在推出我的应用程序的第 2 版,并且需要对新功能进行简短的演练。我浏览了一个教程并在另一个应用程序中创建了我的演练,其中一个 UIViewController 是根视图,一个 UIPageViewController 包含一个 UIView 我在其中显示我的屏幕。它按我的意愿工作。

现在我想将它集成到我的应用程序中。我可以轻松地从示例应用中导入我的代码。

我相信应用程序委托我会查看用户是否曾经通过演练,如果没有,切换到启动演练的 UIViewController,并写入用户已经看过演练的默认值(所以他们不需要再看一遍)。我在演练中有一个按钮可以转到主屏幕。

我的方法“applicationdidFinishLaunchingWithOptions”的部分代码如下:

                - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        UIPageControl *pageControl = [UIPageControl appearance];
        pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
        pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
        pageControl.backgroundColor = [UIColor whiteColor];

        UIStoryboard *storyBoard;
        storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard.storyboard" bundle:nil];
        UIViewController *walkthrough = [storyBoard instantiateViewControllerWithIdentifier:@"NextViewController"];
        //[self presentViewController:walkthrough animated:YES completion:nil];
        [self.window setRootViewController:walkthrough];

        return YES;
    }

这是完整的有效代码。非常感谢您的帮助:

      // User Defaults
      UserDefaults *thisUserDefaults = [[UserDefaults alloc] init];
      [thisUserDefaults registerDefaults];

      if (![[[NSUserDefaults standardUserDefaults]
              valueForKey:kAppHasRunBeforeKey] boolValue]) {

        UIPageControl *pageControl = [UIPageControl appearance];
        pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
        pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
        pageControl.backgroundColor = [UIColor whiteColor];

        UIStoryboard *storyBoard;
        storyBoard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
        UIViewController *walkthrough =
            [storyBoard instantiateViewControllerWithIdentifier:@"ViewController"];
        [self.window setRootViewController:walkthrough];

        [[NSUserDefaults standardUserDefaults] setBool:YES
                                                forKey:kAppHasRunBeforeKey];
      }

【问题讨论】:

标签: ios uistoryboard uipageviewcontroller


【解决方案1】:

显示提示的最好和最简单的方法是使用这个库: https://github.com/chrismiles/CMPopTipView

否则,如果你想用你提到的方法来做,那么你需要在NSUserDefaults 中保留一个变量,比如说一个布尔值walkthroughShownOnce。最初,如果您从 NSUserDefaults 访问应用程序委托中的变量,如下所示:

bool tempInt = [[NSUserDefaults standardUserDefaults] boolForKey:@"walkthroughShownOnce"];

然后它将返回false。这是当你展示你的演练时,最后在你展示了演练之后,只需像这样将变量设为 true:

[[NSUserDefaults standardUserDefaults] setBool:TRUE forKey:@"walkthroughShownOnce"];

【讨论】:

  • 那太好了。但我真的在两件事上苦苦挣扎。一,将代码放在哪里,在应用程序委托或根视图控制器中。二,我如何以编程方式切换到 viewController 开始演练,然后回到原来的视图控制器?
  • 将 NSUserDefaults 代码写在 applicationDidFinishLaunchingWithOptions 方法中的以下行上方:UIStoryboard *storyBoard; 您的代码将如下所示: if([[NSUserDefaults standardUserDefaults] boolForKey:@"walkthroughShownOnce"]==true) { //这里是你从UIStoryboard *storyBoard; 开始写的四行 } else { //这里你打开你现在打开的另一个视图控制器 //如果它自动打开而不在 AppDelegate 中编写代码,那么你不需要需要这个 else 语句}
  • 然后在你的演练控制器中,一旦你完全展示了演练,就叫你第一个视图控制器
  • 感谢 Khawari,我使用了您的代码并发现了我的一个问题,即我的故事板 ID 不正确。我现在可以完美地工作。投票并检查为正确。
  • 我在 GitHub 上有一个代码可以做类似的工作。这是链接:github.com/karanthakakr04/Walkthrough-Demo.git 我希望它能满足您的需要。如果有人需要,还有这个参考教程:youtu.be/tNCsQe5vfRk
【解决方案2】:

还有这个库SwiftyWalkthrough

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-07
    • 1970-01-01
    • 2021-02-04
    • 2012-04-28
    • 2013-07-23
    • 2012-11-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多