将顶栏添加到所有视图可见的iOS应用程序

在一个tabbar iOS应用程序中添加一个顶栏(View)的最好方法是什么,它始终保留在所有视图之上,而不pipeselect哪个选项卡,如下图所示?

在这里输入图像说明

我会使用UIViewControllerContainment。 看一眼

https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/CreatingCustomContainerViewControllers/CreatingCustomContainerViewControllers.html

我设置它的方式是有一个UIViewController有两个ContainerViews。 一个ContainerView将在其中有UITabBarController,另一个将有顶部栏的UIViewController。

这是我在UIStoryboard做的 在这里输入图像说明

子类UIViewController和更改viewDidLoad:方法中的标题和标题视图像这样:

 - (void)viewDidLoad { [super viewDidLoad]; if (!self.title || [self.title isEqualToString:@""]) { self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Logo.png"]]; } else { self.navigationItem.title = self.title; } } 

然后在你的选项卡中的所有视图控制器上使用这个子类。