【问题标题】:How do I link an app's tutorial storyboard to the main app?如何将应用的教程故事板链接到主应用?
【发布时间】:2014-12-06 18:03:10
【问题描述】:

简介
我目前必须在我的项目中使用故事板,其中一个是在 pageView 控制器中设置的应用程序教程,第二个是实际应用程序的故事板。目前该教程仅出现在初始应用程序启动时(如预期的那样),但实际上我必须杀死该应用程序,然后重新打开它才能显示主应用程序视图。

尝试
我尝试在教程的 pageView 控制器中以编程方式加载主应用程序的 viewController, 确实 工作,但绝不是流畅或优雅的。我这样做的方式类似于我发布的代码here

问题
我将如何在两个 Storyboard viewControllers 之间进行流畅的转换?在它们之间转换的最合适的方式是什么?我应该阅读哪些文件?提前致谢!

【问题讨论】:

    标签: ios objective-c xcode uiviewcontroller


    【解决方案1】:

    我建议像往常一样展示您的主视图,并且(对于首次发布)以模态方式展示您的教程视图。这是一个清晰的交互模式;演示动画关闭动画都对用户有意义。

    或者,您可以模态显示教程视图,使用 animate:NO 以防止可能出现尴尬的过渡。

    代码相当简单。只需像往常一样加载您的主视图,然后在适当的时候显示模态视图:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        // Load main view
        self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainScreen" bundle:nil];
        UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"firstView"]; // determine the initial view controller here 
        self.window.rootViewController = viewController;
        [self.window makeKeyAndVisible];
    
        if (self.isFirstLaunch)
        {
            // Display tutorial
            UIStoryboard *tutorialStoryboard = [UIStoryboard storyboardWithName:@"MainScreen" bundle:nil];
             UIViewController *tutorialViewController = [tutorialStoryboard instantiateViewControllerWithIdentifier:@"firstTutorialView"];
            [self.window.rootViewController presentViewController:tutorialViewController animated:NO completion:nil];
        }
    }
    

    【讨论】:

    • 谢谢我回家试试这个!
    • 在这种情况下,您会收到有关控制台中不平衡外观调用的警告。目前这不是问题,但将来可能会导致更多问题。 2014-12-09 18:13:40.518 Test[5964:197973] Unbalanced calls to begin/end appearance transitions for <UISplitViewController: 0x7fc1b041bf60>.
    【解决方案2】:

    在这种情况下,您会遇到有关从视图控制器(根)显示模式视图控制器(教程)的问题,该控制器尚未显示和加载。 我用rootViewController直接替换:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
        if (self.isFirstLaunch) {
            UIStoryboard *tutorialStoryboard = [UIStoryboard storyboardWithName:@"Tutorial" bundle:nil];
            self.window.rootViewController = [tutorialStoryboard instantiateInitialViewController];
    
        } else {
            UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainScreen" bundle:nil];
            self.window.rootViewController = [mainStoryboard instantiateInitialViewController];
        }
    
        [self.window makeKeyAndVisible];
        return YES;
    }
    
    - (void)closeTutorial
    {
        // This is solution without animation
        UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainScreen" bundle:nil];
        self.window.rootViewController = [mainStoryboard instantiateInitialViewController];
    
        // This is solution with animation
        [self.window.rootViewController presentViewController:[mainStoryboard instantiateInitialViewController] animated:YES completion:nil];
    }
    

    【讨论】:

      猜你喜欢
      • 2020-04-18
      • 1970-01-01
      • 2012-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-03
      • 2016-05-31
      • 1970-01-01
      相关资源
      最近更新 更多