What is the best way to add a topbar(View) in a tabbar iOS application that always remain on top of all the views, irrespective of which tab is selected like the image below?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
I would use UIViewControllerContainment. Take a look at
https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/CreatingCustomContainerViewControllers/CreatingCustomContainerViewControllers.html
The way I'd set it up is have a UIViewController that has two ContainerViews. One ContainerView will have the UITabBarController in it and the other would have the UIViewController for the top bar.
Here is what I did in a UIStoryboard
回答2:
Subclass UIViewController and change the title and title view in the viewDidLoad:
method with something like this:
- (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;
}
}
Then use this subclass on all the view controllers that you will have in your tabs.