【问题标题】:Adding Video as a splash in storyboard ios7在故事板ios7中添加视频作为飞溅
【发布时间】:2014-02-23 06:42:14
【问题描述】:

我想在应用程序开始时显示一个视频,就像一个飞溅一样。我的整个应用程序将在导航中。首先,我在 splashViewController 中添加视频并将其在 appDelegate 中设置为 rootView,然后再次将 mainViewController 设置为 rootView。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
    splashViewController = [[SplashViewController alloc] init];
    splashViewController = (SplashViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"SplashViewController"];
    self.window.rootViewController = splashViewController;

    [NSTimer scheduledTimerWithTimeInterval:9.0 target:self selector:@selector(removeSplashScreen:) userInfo:nil repeats:NO];

    return YES;
}

-(void)removeSplashScreen:(id)userInfo
{
    [splashViewController removeFromParentViewController];

    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
    mainViewController = [[MainViewController alloc] init];
    mainViewController = (MainViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"MainViewController"];
    self.window.rootViewController = mainViewController;
}

现在我想从这个 mainViewController 开始导航。我使用故事板并在 mainViewController 中添加来自 Editor > Embed in > Navigation Controller 的导航。不要以编程方式进行。但我知道使用 Nib.xib 实现它的方式。在这里,我还将arrow(指示起始VC的箭头)标记放在它旁边。但是当我单击 mainVC 中的按钮转到下一个 VC 时,它会崩溃。如何在此处设置导航?

如果有人有答案,请与我分享。非常感谢。

我的故事板场景:

【问题讨论】:

  • 如果您阅读 Apple 人机界面指南,您会发现不推荐使用闪屏。没有启动画面之类的概念,而是启动图像。请记住,不遵循指南可能会导致应用被拒绝
  • 感谢您的评论和提醒指导线。但我想这样做。过去在 nib 文件中,我使用视频启动和应用商店从不拒绝它。
  • 我同意meda 的观点,如果不遵守准则,您的应用会被拒绝。尽管您所追求的并不违反准则,因为这只是一个播放视频的UIViewController。因此,据我了解,您的应用程序将启动,用户将看到启动图像,然后第一个呈现自身的视图控制器将是 SplashViewController。似乎与此无关,但我会注意这与xcode IDE 无关,因此请不要使用该标签。

标签: objective-c ios7 uinavigationcontroller storyboard


【解决方案1】:

很高兴分两步为您提供帮助

步骤 1- 您的 didFinishLaunchingWithOptions 代码几乎是正确的,但它是否正常工作并不重要。所以让我们专注于第二步。

步骤 2- in -(void)removeSplashScreen:(id)userInfo

   -first line is good , but you even dont need it because you are going to switch the   root controller (leave it for now)
   - second line (no need to write it)
   - third line is really bad , what you  doing here is trying to alloc you mainviewcontroller. really you need it with storyboard? no 
   - you should load you main view controller from storyboard
   MainViewController* mainViewController = (MainViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"MainViewController"];

“这一行足以从情节提要中加载您的主视图控制器” -下一行是正确的
self.window.rootViewController = mainViewController; 代码现在似乎可以工作了,但是您仍然缺少导航控制器,因为您从情节提要加载了 mainviewcontroller,而不是导航控制器。

- two solution for it
1- load navigation controller in place of mainviewcontroller(give a storyboard id to navigation controller , load it , and make it as root controller) --i will always go with it
2- make a navigation controller with allocating it & make its rootviewcontroller the mainviewcontroller

-----------------工作代码---------------

【讨论】:

  • 非常感谢帕万。这是工作 :)。我去你的第二个解决方案。 >> “2- 制作导航控制器并分配它并使其根视图控制器成为主视图控制器”,但这里将进行一些编辑。这是“2-通过分配它来制作导航控制器并将其rootviewcontroller作为navigationController”。非常感谢您的解释和选择。 :)
【解决方案2】:

好吧,尽管我提出了建议(在 cmets 中),但您可以通过以下方式实现这一目标:

显示飞溅:

//StoryBoard
UIStoryboard *mainStoryboard = [UIStoryboard 
                                   storyboardWithName:@"Main" bundle: nil];
//Splash Controller                                
SplashViewController *splashViewController = [mainStoryboard 
                instantiateViewControllerWithIdentifier:@"SplashViewController"];
//Show it                                 
[self.window.rootViewController presentViewController:splashViewController 
                                             animated:NO completion:nil];

删除它:

[self dismissViewControllerAnimated:YES completion:nil];

编辑:还是不行?

也许你叫它快。这样做:

viewDidLoad

   [NSTimer scheduledTimerWithTimeInterval:9.0 
                                    target:self 
                                  selector:@selector(removeSplashScreen:) 
                                  userInfo:nil repeats:NO];

要删除的功能:

-(void)removeSplashScreen:(id)userInfo
{
   [self dismissViewControllerAnimated:YES completion:nil];
}

【讨论】:

  • 虽然我同意您的建议,但他们正在努力实现的目标并不违背它。指南指的是启动图像之后发生的事情取决于您(按说),因此添加播放视频的视图控制器(仅此而已)是完全可以接受的,但它没有说不允许这样做。
  • 是的。这就是我的观点。这不像我在这里没有添加任何飞溅。我做到了。但在那之后只想添加一个splashVC。就是这样。
  • 是的,你们是对的,反正我该评判谁。
  • 它显示错误指向“dismissViewControllerAnimated:YES”并说“'AppDelegate' 没有可见的@interface 声明选择器'dismissViewControllerAnimated:completion:'”meda
  • @Tulon 是的,就像大力水手所说的,在 AppDelegate 中显示,在 SplashViewController 中隐藏
【解决方案3】:

因此,根据 pawan 给出的答案,解决方案是:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
    splashViewController = (SplashViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"SplashViewController"];
    self.window.rootViewController = splashViewController;

    [NSTimer scheduledTimerWithTimeInterval:9.0 target:self selector:@selector(removeSplashScreen:) userInfo:nil repeats:NO];

    return YES;
}

-(void)removeSplashScreen:(id)userInfo
{
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
    mainViewController = [[MainViewController alloc] init];
    mainViewController = (MainViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"MainViewController"];

    navigationContoller = [[UINavigationController alloc] initWithRootViewController:mainViewController];
    self.window.rootViewController = navigationContoller;
}

:)

【讨论】:

    猜你喜欢
    • 2014-09-12
    • 2018-08-13
    • 1970-01-01
    • 2014-02-04
    • 2016-04-07
    • 1970-01-01
    • 1970-01-01
    • 2012-08-12
    • 2012-11-03
    相关资源
    最近更新 更多