Material组件标签栏底部导航

Material component tab bar bottom navigation

如何创建 Material 组件标签栏底部导航?文档描述 我必须实施 positionForBar: 和 return UIBarPositionBottom 以将选项卡栏配置为底部导航栏。该栏将自动更新为适当的样式。怎么看起来好像不起作用-示例:

ViewController.h ...

@interface ViewController : MDCCollectionViewController <MDCTabBarDelegate>

ViewController.m

- (void)viewDidLoad {
 [super viewDidLoad];
 self.styler.cellStyle = MDCCollectionViewCellStyleCard;
// Do any additional setup after loading the view, typically from a nib.

self.appBar = [[MDCAppBar alloc] init];
[self addChildViewController:self.appBar.headerViewController];
self.appBar.headerViewController.headerView.backgroundColor = [UIColor colorWithRed:120.0/255 green:144.0/255 blue:156.0/255 alpha:1.0];//rgba(38,50,56 ,1)
self.appBar.headerViewController.headerView.trackingScrollView = self.collectionView;
self.appBar.navigationBar.tintColor = [UIColor blackColor];
[self.appBar addSubviewsToParent];

self.title = @"W0rX";

MDCTabBar *tabBar =  [[MDCTabBar alloc] initWithFrame:self.view.bounds];
tabBar.items = @[
                 [[UITabBarItem alloc] initWithTitle:@"Recents" image:[UIImage imageNamed:@"phone"] tag:0],
                 [[UITabBarItem alloc] initWithTitle:@"Favorites" image:[UIImage imageNamed:@"heart"] tag:0],
                 ];
tabBar.itemAppearance = MDCTabBarItemAppearanceTitledImages;
tabBar.delegate = self;

tabBar.autoresizingMask =
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;
[tabBar sizeToFit];
[self.view addSubview:tabBar];
}

- (UIBarPosition)positionForBar:(id <UIBarPositioning>)bar {
NSLog(@"######## UIBarPositionBottom");
return UIBarPositionBottom;
}

感谢使用 MDC-iOS。

看来您的代码快写好了!

缺少的是将标签栏的框架设置到屏幕底部。有关如何执行此操作的示例,请参阅 BottomNavigationBarExample。在该示例视图控制器中,选项卡栏位于屏幕底部 viewWillLayoutSubviews:

barFrame.origin.y = CGRectGetMaxY(bounds) - barFrame.size.height

我知道你只是在这里放了一段代码,但我没有看到你设置原点,除非你实例化标签栏。你的线路

MDCTabBar *tabBar =  [[MDCTabBar alloc] initWithFrame:self.view.bounds];

将左上角作为标签栏 (0,0) 的起点。这很好。但是您最终需要将其向下移动到视图的底部。

顺便说一句:还要看一下 MDCTabBarViewController,它很像 UITabBarViewController。它可能对您有用,具体取决于您要执行的操作。