TabBarController 之前的启动屏幕
我是 iPhone 开发新手,正在开发我的第一个应用程序。实际上,我已经创建了一个选项卡栏应用程序,但我想在运行应用程序时添加启动屏幕。
我在 Loading a Welcome Screen(Splash Screen) before TabBarController
但是当我尝试输入代码时,启动屏幕不会加载,只是继续显示我的选项卡控制器。
我创建了 SplashViewController.h、SplashViewController.m 和 SplashView.xib,以下是我的代码,
#import "SplashViewController.h"
...
...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
SplashViewController *controller = [[SplashViewController alloc] initWithNibName:@"SplashView" bundle:nil];
[self.tabBarController presentModalViewController:controller animated:YES];
[controller release];
// Add the tab bar controller's view to the window and display.
[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
return YES;
}
应用程序运行没有错误,但无法加载启动屏幕,任何评论都受到高度赞赏。谢谢!
I am a beginner of iPhone developer and I am working on my first apps. Actually, I already created a Tab Bar application well but I would like to add the Splash Screen when run the apps.
I found a exactly question at Loading a Welcome Screen(Splash Screen) before TabBarController
But when I try to put in my code, the splash screen doesn't load and just keep showing my tabbarcontroller.
I created a SplashViewController.h, SplashViewController.m and SplashView.xib and following is my code,
#import "SplashViewController.h"
...
...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
SplashViewController *controller = [[SplashViewController alloc] initWithNibName:@"SplashView" bundle:nil];
[self.tabBarController presentModalViewController:controller animated:YES];
[controller release];
// Add the tab bar controller's view to the window and display.
[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
return YES;
}
The apps run without error but just cannot load the splash screen, any comment is highly appreciated. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我的猜测是,标签栏控制器忽略了对
presentModalViewController:animated:
的调用,因为它尚未出现在屏幕上。尝试将调用移至标签栏视图作为子视图添加到窗口之后。即使在调用makeKeyAndVisible
之后,它也可能必须发生。My guess is that the tab bar controller is ignoring your call to
presentModalViewController:animated:
because it isn't on screen yet. Try moving the call to after the tab bar view has been added as a subview to the window. It may have to happen even after the call tomakeKeyAndVisible
.如果您的要求是显示视图直到用户点击它,那么 MetaLik 的建议就可以了。
或者,您可以将启动控制器的视图直接添加到应用程序窗口。
在任何一种情况下,您都需要创建一个按钮或 UIResponder 的某个子类来响应用户的点击,当您获得它时,可以解雇ModalViewController或[self.view removeFromSuperview],具体取决于您实例化它的方式。
If your requirement is to show a view until the user taps it, then MetaLik's suggestion would work.
Alternatively, you could add the splash controller's view directly to the app window.
In either case, you'll need to create a button or some subclass of UIResponder to respond to the user's tap, and when you get that, either dismissModalViewController or [self.view removeFromSuperview], depending on how you instantiated it.
我建议将闪屏视图控制器的视图添加到您的窗口中并将其设为主窗口。无需使用选项卡栏控制器以模态方式呈现它。然后在启动屏幕中只有一个按钮占据整个屏幕,每当按下该按钮时,就会删除并释放视图并进行正常的窗口设置(配置选项卡栏等)。
显示我的意思的一些代码
编辑:在您的应用程序委托中
:在您的启动视图控制器中:
需要注意的一件事:我假设您在笔尖中初始化并设置了选项卡栏控制器(正如您的原始帖子所示) 。
I would suggest just adding the view of the splash screen view controller to your window and making it main. No need to use the tab bar controller to present it modally. then in the splash screen just have a button that takes up the whole screen and whenever its pressed remove and release the view and do your normal window setup (configure the tab bar and etc).
Edit: some code to show what I mean,
in your app delegate:
In your splash View Controller:
One thing to note: I am assuming you initalize and set up your tab bar controller in a nib (as it seems from your original post).
Mike 关于如何设置启动屏幕的精彩评论,为了使一个简单的启动屏幕创建一个名为 Default.png 的静态图像,然后就可以正常工作了。它应该最多显示大约 5 秒或直到您的应用程序加载。我使用的宽度 x 高度尺寸为 320x480,它基本上正是我所需要的。
谢谢迈克。!!
另外,这里有一个有用的链接,可以创建启动画面和图标等......
自定义图标和图像创建指南
Excellent comment from Mike about how to setup a splash screen, in order to make a dirt simple splash screen create a static image called Default.png and presto magico it works. It should display for about 5 seconds max or until your app loads. I used width x height dimensions of 320x480 and it is basically exactly what I needed.
Thank you Mike.!!
Also, here is a useful link that goes along with creating a splash screen and icons etc...
Custom Icon and Image Creation Guidelines
我这样做了并且效果很好。
AppDelegate.h:
AppDelegate.m:
SplashViewController.h:
SplashViewController.m:
I did this and it works fine.
AppDelegate.h:
AppDelegate.m:
SplashViewController.h:
SplashViewController.m: