【问题标题】:iOS: First screen display imageiOS:首屏显示图片
【发布时间】:2013-04-07 00:25:06
【问题描述】:

对于我的手机应用程序,我想在 3 秒内在第一个屏幕上显示一个图像,并在没有用户操作的情况下切换到主菜单。

如何执行速度和自动切换视图?

谢谢。

【问题讨论】:

  • 仅使用 xcode 标签来回答有关 IDE 本身的问题。

标签: iphone ios uiview


【解决方案1】:

您想要做的就是启动画面, 见App Launch (Default) Images 或者参考这个guide

【讨论】:

  • 但是你无法控制启动图片的显示时间
  • 是的,使用这种方法你不能它会显示大约 1 秒钟,但我参考了该指南,因为它很容易遵循
  • 您可以在applicationDidFinishLauching中调用sleep(3),等待3秒再显示主视图
【解决方案2】:

使用这个

[self performSelector:@selector(loadMainView) withObject:nil afterDelay:3.0];

使用loadMainView 方法,您应该开始设置常用视图

【讨论】:

    【解决方案3】:

    我通常通过创建一个视图控制器来做到这一点,该控制器在其视图中具有一个 UIImageView 和启动图像。

    使用模态

    您可以通过这种方式将其作为模式视图控制器呈现在您的 rootViewController 之上。 在 AppDelegate 的 application:didFinishLaunchingWithOptions: 中,您通过调用

    来呈现模式
    // rootViewController is the view controller attached to the UIWindow
    [rootViewController presentViewController:imageViewController animated:NO completion:nil];
    

    在 imageViewController 中你可以这样做:

    - (void)dismiss {
        // You can animate it or not, depending on your needs
        [self.presentingViewController dismissViewControllerAnimated:YES completion:nil];    
    }
    
    - (void)viewDidApper {
        [self performSelector:@selector(dismiss) withObject:nil afterDelay:AMOUNT_OF_TIME];
    }
    

    作为 UINavigationController 堆栈的第一个控制器

    不涉及模态的类似方法是将此视图控制器推送到您的 UINavigationController 中(如果您使用它)

    在 AppDelegate 的 application:didFinishLaunchingWithOptions: 中,您必须使用类似这样的内容设置导航控制器的第一个控制器

    UINavigationController * navController = [[UINavigationController alloc] initWithRootViewController:imageViewController];
    self.window.rootViewController = navController;
    [self.window makeKeyAndVisible];
    

    在 imageViewController 中你可以这样做:

    - (void)dismiss {
        // Here you should init your nextViewController, the real "home" of the app
        ....
    
        // Then you can present it. You can animate it or not, depending on your needs.
        // I prefer to replace the whole stack, since user shouldn't go back to the image screen.  
        [self.navigationController setViewControllers:@[nextViewController] animated:YES];    
    }
    
    - (void)viewDidApper {
        [self performSelector:@selector(dismiss) withObject:nil afterDelay:AMOUNT_OF_TIME];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多