我正在尝试使用Google的MDC制作重要的应用。尽管我可以获取物料标签栏,但无法通过滑动来更改标签。我知道可以通过向每个视图控制器添加滑动手势识别器并根据我可以操纵MDCTabBar的选定索引的方向来完成此操作,但是MDCTabBar是否有任何内置支持? 在一个SO答案中,用户说他们的github存储库中有一个示例,但我找不到任何示例。我该怎么办?
到目前为止,我的代码
let tabBar = MDCTabBar(frame: view.bounds)
tabBar.items = [
UITabBarItem(title: "Rules", image: nil, tag: 0),
UITabBarItem(title: "Live", image: nil, tag: 1),
UITabBarItem(title: "Scenes", image: nil, tag: 2),
UITabBarItem(title: "Things", image: nil, tag: 3)
]
tabBar.itemAppearance = .titles
tabBar.autoresizingMask = [.flexibleWidth, .flexibleBottomMargin]
tabBar.alignment = .center
tabBar.sizeToFit()
tabBar.backgroundColor = UIColor(netHex: "1B59A8")
tabBar.translatesAutoresizingMaskIntoConstraints=false
view.addSubview(tabBar)
let upperConstraint = NSLayoutConstraint(item: tabBar, attribute: NSLayoutAttribute.top, relatedBy: NSLayoutRelation.equal, toItem: appBar.view, attribute: NSLayoutAttribute.bottom, multiplier: 1, constant: 0)
let leftConstraint = NSLayoutConstraint(item: tabBar, attribute: NSLayoutAttribute.left, relatedBy: NSLayoutRelation.equal, toItem: self.view, attribute: NSLayoutAttribute.left, multiplier: 1, constant: 0)
let rightConstraint = NSLayoutConstraint(item: tabBar, attribute: NSLayoutAttribute.right, relatedBy: NSLayoutRelation.equal, toItem: self.view, attribute: NSLayoutAttribute.right, multiplier: 1, constant: -0)
let heightConstraint = NSLayoutConstraint(item: tabBar, attribute: NSLayoutAttribute.height, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: 50)
NSLayoutConstraint.activate([upperConstraint,leftConstraint,rightConstraint,heightConstraint])
appBar.didMove(toParentViewController: self)