【问题标题】:Material component tab bar bottom navigation材质组件标签栏底部导航
【发布时间】:2018-04-10 14:10:31
【问题描述】:

如何创建材质组件标签栏底部导航?文档描述 我必须实现 positionForBar: 并返回 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;
}

【问题讨论】:

    标签: ios objective-c material-components


    【解决方案1】:

    感谢您使用 MDC-iOS。

    看起来您的代码就快到了!

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

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

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

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-27
      • 2021-04-02
      • 2019-04-20
      • 2020-04-18
      • 2019-05-04
      • 1970-01-01
      相关资源
      最近更新 更多