我是iPhone开发人员的初学者,我正在开发我的第一个应用程序。实际上,我已经创建了一个Tab Bar应用程序,但我想在运行应用程序时添加启动画面。
我在Loading a Welcome Screen(Splash Screen) before TabBarController
找到了一个确切的问题但是当我尝试输入我的代码时,启动画面不会加载,只是继续显示我的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;
}
应用程序运行没有错误但只是无法加载启动画面,任何评论都非常感谢。谢谢!
答案 0 :(得分:3)
我的猜测是标签栏控制器忽略了您对presentModalViewController:animated:
的调用,因为它尚未显示在屏幕上。将标签栏视图添加为窗口的子视图后,尝试将呼叫移至。即使在调用makeKeyAndVisible
之后也可能发生这种情况。
答案 1 :(得分:0)
我建议只将启动画面视图控制器的视图添加到窗口并使其成为主窗口。无需使用标签栏控制器以模态方式呈现它。然后在启动画面中只有一个占据整个屏幕的按钮,每当按下它并移除并释放视图并进行常规窗口设置(配置标签栏等)。
编辑:一些代码来显示我的意思,
在你的app delegate中:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
SplashViewController *controller = [[SplashViewController alloc] initWithNibName:@"SplashView" bundle:nil];
[self.window addSubview:controller.view];
[self.window makeKeyAndVisible];
[controller release];
}
在启动视图控制器中:
-(IBAction) didPressButtonToDismiss:(id)sender {
//create a reference to the singleton class for easier typing
MyAppDelegate *delegate = (MyAppDelegate*) [[UIApplication sharedApplication] delegate];
[delegate.window addSubview:delegate.tabBarController.view];
[delegate.window bringSubviewToFront:delegate.tabBarController.view];
[self.view removeFromSuperview];
}
有一点需要注意:我假设您初始化并在笔尖中设置标签栏控制器(从您原来的帖子中看起来如此)。
答案 2 :(得分:0)
如果您的要求是在用户点击之前显示视图,那么MetaLik的建议就可以了。 或者,您可以将启动控制器的视图直接添加到应用程序窗口。
[self.window addSubview:MySplashController.view];
在任何一种情况下,你都需要创建一个UIResponder的按钮或子类来响应用户的点击,当你得到它时,要么dismissModalViewController或[self.view removeFromSuperview],这取决于你如何实例化它。
答案 3 :(得分:0)
迈克关于如何设置启动画面的优秀评论,为了使污垢简单的启动画面创建一个名为Default.png和presto magico的静态图像。它应显示最多约5秒或直到您的应用程序加载。我使用宽度x高度尺寸为320x480,它基本上就是我需要的。
谢谢Mike。!!
此外,这是一个有用的链接,同时创建一个闪屏和图标等... Custom Icon and Image Creation Guidelines
答案 4 :(得分:0)
我这样做了,效果很好。
AppDelegate.h:
@interface AppDelegate_Pad : NSObject
<UIApplicationDelegate, SplashViewControllerDelegate> {
UIWindow *window;
UITabBarController *tabBarController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@end
AppDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
SplashViewController *svc = [[SplashViewController alloc] initWithNibName:@"SplashViewController" bundle:nil];
svc.delegate = self;
[self.tabBarController presentModalViewController:svc animated:NO];
return YES;
}
-(void)splashViewControllerDidFinish:(SplashViewController *)splashViewController {
[self.tabBarController dismissModalViewControllerAnimated:NO];
}
SplashViewController.h:
@protocol SplashViewControllerDelegate;
@interface SplashViewController : UIViewController {
id<SplashViewControllerDelegate> delegate;
}
@property (nonatomic, assign) id <SplashViewControllerDelegate> delegate;
@end
@protocol SplashViewControllerDelegate
-(void)splashViewControllerDidFinish:(SplashViewController *)splashViewController;
@end
SplashViewController.m:
// Call the below line where you want to remove splash view
[self.delegate splashViewControllerDidFinish:self];