0

我想知道如何设计自己的自定义选项卡,单击时可以在屏幕上显示多个视图

http://tinypic.com/r/2cxtjk7/5

我目前只能找到底部标签栏的方法。感谢您的帮助,我还是个新手,所以如果您能详细解释一下,那就太好了:)

4

2 回答 2

1

使用自定义选项卡显示多个视图

   - (id)initWithNibName:(NSString *)nibNameOrNil 
               bundle:(NSBundle *)nibBundleOrNil
    {
    AccountViewController *accountViewController = [[AccountViewController alloc]
                        initWithNibName:@"AccountViewController" bundle:nil];
    MoreViewController *moreViewController = [[MoreViewController alloc]
                        initWithNibName:@"MoreViewController" bundle:nil];
    BarTabViewController *barTabViewController = [[BarTabViewController alloc]
                        initWithNibName:@"BarTabViewController" bundle:nil];
    LocationsViewController *locationsViewController = [[LocationsViewController alloc]
                        initWithNibName:@"LocationsViewController" bundle:nil];

    self.viewControllers = [NSArray arrayWithObjects:locationsViewController, accountViewController,
                            barTabViewController, moreViewController, nil];

    [self.view addSubview:locationsViewController.view];
    self.selectedController = locationsViewController;
    self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.selectedIndex = 0;

self.tabBarController.viewControllers = [NSArray arrayWithObjects:locationsViewController, accountViewController,
                    barTabViewController, moreViewController, nil];
self.tabBarController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self.navigationController pushViewController:delegate.tabBarController animated:YES];
        return self;
    }

就像我说的,这将正确显示选定的控制器,但是当应用程序启动并且我尝试使用标签栏切换视图时,子视图变成灰色......以下是切换项目的代码:

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
    if (item == locationsTabBarItem) {
        UIViewController *locationsController = [viewControllers objectAtIndex:0];
        [self.selectedController.view removeFromSuperview];
        [self.view addSubview:locationsController.view];
        self.selectedController = locationsController;
    }
    else if (item == accountsTabBarItem) {
        UIViewController *accountsController = [viewControllers objectAtIndex:1];
        [self.selectedController.view removeFromSuperview];
        [self.view addSubview:accountsController.view];
        self.selectedController = accountsController;
    }
    else if (item == barTabTabBarItem) {
        UIViewController *barTabController = [viewControllers objectAtIndex:2];
        [self.selectedController.view removeFromSuperview];
        [self.view addSubview:barTabController.view];
        self.selectedController = barTabController;
    }
    else {
        UIViewController *moreController = [viewControllers objectAtIndex:3];
        [self.selectedController.view removeFromSuperview];
        [self.view addSubview:moreController.view];
        self.selectedController = moreController;
    }
}
于 2013-10-15T10:22:35.607 回答
0

我在视图中添加了最后加载的东西:

PatientDetailsViewController *patientDetailsView = [[PatientDetailsViewController alloc] initWithNibName:@"PatientDetailsViewController" bundle:nil]; [self addChildViewController:patientDetailsView]; [self.patientDetailsView addSubview:patientDetailsView.view]; [self.patientDetailsView setClipsToBounds:YES];

然后通过使用动画调整视图框架大小,使用按钮对其打开进行动画处理。

于 2013-12-11T16:11:51.257 回答