带按钮的 iOS 启动画面

发布于 2024-11-14 10:38:13 字数 2044 浏览 0 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤单情人 2024-11-21 10:38:14

(警告,基于 ARC 的代码...不要忘记发布)
我是这样做的:

首先,我将 SplashScreenViewController *controllertabController 作为 appDelegate 的属性。

然后我将 didFinishLaunchingWithOption 更改为仅显示 SplashScreenViewController

- (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];

    [self controller] = [[SplashScreenViewController alloc] init];

    [[self controller]setAppDelegate:self];
    self.window.rootViewController = self.controller;
    [self.window makeKeyAndVisible];
    return YES;
}

因此,在您的 SplashScreenViewController 中,添加一个指向您的应用程序 appDelegate 的属性 appDelegate代码>.

然后,在启动屏幕上执行您想要的操作(登录、按钮等...)
在此示例中,这是一个简单的登录按钮。当您单击按钮时,它会在您的 appDelegate 中调用一个函数。

- (IBAction)loginButton:(id)sender 
{
    [[self appDelegate]setMainTabBarControllerOnScreen];
}

该函数现在将加载 tabBarController 并删除启动屏幕登录屏幕

self.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]];

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]];

NSArray * arrayOfControllers = [[NSArray alloc] initWithObjects:homeNavigationController, sdkNavigationController, nil];
self.tabController.viewControllers = arrayOfControllers;

,这就是技巧

[[self window] addSubview:self.tabController.view];
[[self window]setRootViewController:[self tabController]];
[[[self viewController]view] removeFromSuperview];

(Warning, ARC based code ... don't forget to release)
I've did it like that:

First I put both SplashScreenViewController *controller and tabController as properties of appDelegate.

Then I change didFinishLaunchingWithOption to show only the SplashScreenViewController

- (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];

    [self controller] = [[SplashScreenViewController alloc] init];

    [[self controller]setAppDelegate:self];
    self.window.rootViewController = self.controller;
    [self.window makeKeyAndVisible];
    return YES;
}

so, in your SplashScreenViewController, add a property appDelegate pointing to your Application appDelegate.

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

- (IBAction)loginButton:(id)sender 
{
    [[self appDelegate]setMainTabBarControllerOnScreen];
}

This function will now load the tabBarController and remove the splashcreen login screen

self.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]];

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]];

NSArray * arrayOfControllers = [[NSArray alloc] initWithObjects:homeNavigationController, sdkNavigationController, nil];
self.tabController.viewControllers = arrayOfControllers;

And here is the trick

[[self window] addSubview:self.tabController.view];
[[self window]setRootViewController:[self tabController]];
[[[self viewController]view] removeFromSuperview];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文