【发布时间】:2013-04-07 00:25:06
【问题描述】:
对于我的手机应用程序,我想在 3 秒内在第一个屏幕上显示一个图像,并在没有用户操作的情况下切换到主菜单。
如何执行速度和自动切换视图?
谢谢。
【问题讨论】:
-
仅使用 xcode 标签来回答有关 IDE 本身的问题。
对于我的手机应用程序,我想在 3 秒内在第一个屏幕上显示一个图像,并在没有用户操作的情况下切换到主菜单。
如何执行速度和自动切换视图?
谢谢。
【问题讨论】:
您想要做的就是启动画面, 见App Launch (Default) Images 或者参考这个guide
【讨论】:
applicationDidFinishLauching中调用sleep(3),等待3秒再显示主视图
使用这个
[self performSelector:@selector(loadMainView) withObject:nil afterDelay:3.0];
使用loadMainView 方法,您应该开始设置常用视图
【讨论】:
我通常通过创建一个视图控制器来做到这一点,该控制器在其视图中具有一个 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 中(如果您使用它)
在 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];
}
【讨论】: