带按钮的 iOS 启动画面
我是 iOS 开发新手。我有一个启动屏幕,想用初始视图替换它,我的意思是用一个图像和两个按钮。如何设置初始视图?我正在将 Xcode 4 与 iOS 4 一起使用。这是我的代码...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIView *backgroundView = [[UIView alloc] initWithFrame: window.frame];
backgroundView.backgroundColor = [UIColor lightGrayColor];
[window addSubview:backgroundView];
[backgroundView release];
// Override point for customization after application launch.
DataController *appController = [DataController sharedObject];
tabController = [[UITabBarController alloc] init];
HomeViewController *hemView = [[HomeViewController alloc] init];
[hemView setTitle:@"Hem"];
hemView.tabBarItem.image = [UIImage imageNamed:@"icon_home.png"];
UINavigationController *homeNavigationController = [[UINavigationController alloc] initWithRootViewController:hemView];
[homeNavigationController.navigationBar setTintColor:[UIColor colorWithRed:(0.96) green:(0.96) blue:(0.96) alpha:0.0]];
[hemView release];
SearchViewController *sdkView = [[SearchViewController alloc] init];
[sdkView setTitle:@"Search"];
sdkView.tabBarItem.image = [UIImage imageNamed:@"icon_search.png"];
UINavigationController *sdkNavigationController = [[UINavigationController alloc] initWithRootViewController:sdkView];
[sdkNavigationController.navigationBar setTintColor:[UIColor colorWithRed:(0.96) green:(0.96) blue:(0.96) alpha:0.0]];
[sdkView release];
NSArray * arrayOfControllers = [[NSArray alloc] initWithObjects:homeNavigationController, sdkNavigationController, nil];
tabController.viewControllers = arrayOfControllers;
SplashScreenViewController *controller = [[SplashScreenViewController alloc] init];
[tabController presentModalViewController:controller animated:YES];
[controller release];
[self.window makeKeyAndVisible];
[window addSubview:tabController.view];
[homeNavigationController release];
[sdkNavigationController release];
[appController release];
return YES;
}
但是此代码不显示启动屏幕,它直接将我带到 HomeViewController ,请帮忙。
I am new to iOS dev. I've a splash screen and want to replace it with an initial view, I mean with an image and two buttons. How can I set up an initial view ? I'm using Xcode 4 with iOS 4. Here's my code...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIView *backgroundView = [[UIView alloc] initWithFrame: window.frame];
backgroundView.backgroundColor = [UIColor lightGrayColor];
[window addSubview:backgroundView];
[backgroundView release];
// Override point for customization after application launch.
DataController *appController = [DataController sharedObject];
tabController = [[UITabBarController alloc] init];
HomeViewController *hemView = [[HomeViewController alloc] init];
[hemView setTitle:@"Hem"];
hemView.tabBarItem.image = [UIImage imageNamed:@"icon_home.png"];
UINavigationController *homeNavigationController = [[UINavigationController alloc] initWithRootViewController:hemView];
[homeNavigationController.navigationBar setTintColor:[UIColor colorWithRed:(0.96) green:(0.96) blue:(0.96) alpha:0.0]];
[hemView release];
SearchViewController *sdkView = [[SearchViewController alloc] init];
[sdkView setTitle:@"Search"];
sdkView.tabBarItem.image = [UIImage imageNamed:@"icon_search.png"];
UINavigationController *sdkNavigationController = [[UINavigationController alloc] initWithRootViewController:sdkView];
[sdkNavigationController.navigationBar setTintColor:[UIColor colorWithRed:(0.96) green:(0.96) blue:(0.96) alpha:0.0]];
[sdkView release];
NSArray * arrayOfControllers = [[NSArray alloc] initWithObjects:homeNavigationController, sdkNavigationController, nil];
tabController.viewControllers = arrayOfControllers;
SplashScreenViewController *controller = [[SplashScreenViewController alloc] init];
[tabController presentModalViewController:controller animated:YES];
[controller release];
[self.window makeKeyAndVisible];
[window addSubview:tabController.view];
[homeNavigationController release];
[sdkNavigationController release];
[appController release];
return YES;
}
But this code doesn't show the splash screen , it takes me directly to the HomeViewController , help please .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
(警告,基于 ARC 的代码...不要忘记发布)
我是这样做的:
首先,我将
SplashScreenViewController
*controller
和tabController
作为appDelegate
的属性。然后我将
didFinishLaunchingWithOption
更改为仅显示SplashScreenViewController
,因此,在您的
SplashScreenViewController
中,添加一个指向您的应用程序appDelegate
的属性 appDelegate代码>.然后,在启动屏幕上执行您想要的操作(登录、按钮等...)
在此示例中,这是一个简单的登录按钮。当您单击按钮时,它会在您的
appDelegate
中调用一个函数。该函数现在将加载 tabBarController 并删除启动屏幕登录屏幕
,这就是技巧
(Warning, ARC based code ... don't forget to release)
I've did it like that:
First I put both
SplashScreenViewController
*controller
andtabController
as properties ofappDelegate
.Then I change
didFinishLaunchingWithOption
to show only theSplashScreenViewController
so, in your
SplashScreenViewController
, add a property appDelegate pointing to your ApplicationappDelegate
.Then, do what you want on your splashscreen (login, button, etc...)
In this example, this is a simple login button. When you click on the button, it calls a function into your
appDelegate
This function will now load the tabBarController and remove the splashcreen login screen
And here is the trick