对于我的手机应用程序,我想在3秒内在第一个屏幕上显示图像,并切换到主菜单而无需用户操作。
如何执行速度并自动切换视图?
谢谢。
答案 0 :(得分:1)
使用此
[self performSelector:@selector(loadMainView) withObject:nil afterDelay:3.0];
使用loadMainView
方法,您应该开始设置常用视图
答案 1 :(得分:1)
你想要做什么被称为启动画面, 见App Launch (Default) Images 或者参考此guide
答案 2 :(得分:0)
我通常通过创建一个视图控制器来实现这一点,该视图控制器的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];
}