在显示 UITabBar 之前显示视图

发布于 2024-11-04 11:08:44 字数 56 浏览 0 评论 0原文

我需要在显示基于选项卡的应用程序之前显示一个视图,一旦用户点击按钮,视图就会消失。 有什么想法吗?

I need to display a view before I display a tab based app and once the user taps a button the view goes away.
Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

长途伴 2024-11-11 11:08:44

这是演示该过程的一些代码。您可以将此代码粘贴到应用程序委托中来运行。请注意,这是意大利面条式代码,但我这样做是为了让您可以在一个地方看到所有步骤。通常,您会将部分代码放入其自己的视图控制器和类中。

这是在 appdelegate 中。请注意,这还没有完全测试泄漏和其他内容。它只是一个示例。

@synthesize  tabViewController;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{


    UIWindow *w = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];;
    self.window = w; //property defined in the .h file
    [w release];


    //create the tab bar controller
    UITabBarController *tbc = [[UITabBarController alloc]init];
    self.tabViewController = tbc;
    [w addSubview:tbc.view];

    //create the two tabs
    NSMutableArray *a = [[NSMutableArray alloc]init];

    //create the first viewcontroller 
    UIViewController *vca = [[UIViewController alloc]init];
    vca.view.backgroundColor = [UIColor redColor];
    vca.title = @"View A";
    [a addObject:vca];
    [vca release];

    //and the second
    UIViewController *vcb = [[UIViewController alloc]init];
    vcb.view.backgroundColor = [UIColor blueColor];
    vcb.title = @"View B";
    [a addObject:vcb];
    [vcb release];

    //assign the viewcontrollers to the tabcontroller
    tbc.viewControllers=a;

    //release the array now that its retained by the tabcontroller
    [a release];
    [tbc release];  //tabbarcontroller is retained by our property


    UIViewController *vcc = [[UIViewController alloc]init];  //this is the popup view
    vcc.view.backgroundColor = [UIColor whiteColor];
    UIButton *b = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    b.titleLabel.text = @"Click here";
    [b addTarget:self action:@selector(buttonDismiss:) forControlEvents:UIControlEventTouchUpInside]; //hook into the buttons event
    b.frame = CGRectMake(10, 10, 300, 40);  
    [vcc.view addSubview:b]; //add it to the popup view



    [tbc presentModalViewController:vcc animated:YES];

    [self.window makeKeyAndVisible];
    return YES;
}

-(void) buttonDismiss:(UIButton *)sender
{
    [self.tabViewController dismissModalViewControllerAnimated:YES];

}

here is some code that demonstrates the process. You can paste this code into the app delegate to run. Note, that this is spaghetti code, but I did it this way so you can see all the steps in one place. Normally, you will put parts of this code into its own view controller and classes.

this is in the appdelegate.. note that this is not completely tested for leaks and stuff.. its meant for an example.

@synthesize  tabViewController;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{


    UIWindow *w = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];;
    self.window = w; //property defined in the .h file
    [w release];


    //create the tab bar controller
    UITabBarController *tbc = [[UITabBarController alloc]init];
    self.tabViewController = tbc;
    [w addSubview:tbc.view];

    //create the two tabs
    NSMutableArray *a = [[NSMutableArray alloc]init];

    //create the first viewcontroller 
    UIViewController *vca = [[UIViewController alloc]init];
    vca.view.backgroundColor = [UIColor redColor];
    vca.title = @"View A";
    [a addObject:vca];
    [vca release];

    //and the second
    UIViewController *vcb = [[UIViewController alloc]init];
    vcb.view.backgroundColor = [UIColor blueColor];
    vcb.title = @"View B";
    [a addObject:vcb];
    [vcb release];

    //assign the viewcontrollers to the tabcontroller
    tbc.viewControllers=a;

    //release the array now that its retained by the tabcontroller
    [a release];
    [tbc release];  //tabbarcontroller is retained by our property


    UIViewController *vcc = [[UIViewController alloc]init];  //this is the popup view
    vcc.view.backgroundColor = [UIColor whiteColor];
    UIButton *b = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    b.titleLabel.text = @"Click here";
    [b addTarget:self action:@selector(buttonDismiss:) forControlEvents:UIControlEventTouchUpInside]; //hook into the buttons event
    b.frame = CGRectMake(10, 10, 300, 40);  
    [vcc.view addSubview:b]; //add it to the popup view



    [tbc presentModalViewController:vcc animated:YES];

    [self.window makeKeyAndVisible];
    return YES;
}

-(void) buttonDismiss:(UIButton *)sender
{
    [self.tabViewController dismissModalViewControllerAnimated:YES];

}
本王不退位尔等都是臣 2024-11-11 11:08:44

使用 UIViewController。使用选项卡栏控制器将该控制器呈现为模态视图。之后关闭视图控制器以隐藏它

Use a UIViewController. Present that controller as a modal view with the tab bar controller. Dismiss the view controller after that to hide it

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