TabBarController 之前的启动屏幕

发布于 2024-10-28 13:23:27 字数 1137 浏览 1 评论 0原文

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

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

发布评论

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

评论(5

我早已燃尽 2024-11-04 13:23:27

我的猜测是,标签栏控制器忽略了对 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 to makeKeyAndVisible.

与往事干杯 2024-11-04 13:23:27

如果您的要求是显示视图直到用户点击它,那么 MetaLik 的建议就可以了。
或者,您可以将启动控制器的视图直接添加到应用程序窗口。

 [self.window addSubview:MySplashController.view];

在任何一种情况下,您都需要创建一个按钮或 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.

 [self.window addSubview:MySplashController.view];

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.

小…红帽 2024-11-04 13:23:27

我建议将闪屏视图控制器的视图添加到您的窗口中并将其设为主窗口。无需使用选项卡栏控制器以模态方式呈现它。然后在启动屏幕中只有一个按钮占据整个屏幕,每当按下该按钮时,就会删除并释放视图并进行正常的窗口设置(配置选项卡栏等)。

显示我的意思的一些代码

编辑:在您的应用程序委托中

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

需要注意的一件事:我假设您在笔尖中初始化并设置了选项卡栏控制器(正如您的原始帖子所示) 。

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:

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

In your splash View Controller:

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

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).

琴流音 2024-11-04 13:23:27

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

一抹苦笑 2024-11-04 13:23:27

我这样做了并且效果很好。

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

I did this and it works fine.

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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文