【问题标题】:MDCTabBar selection indicator animationMDCTabBar 选择指示器动画
【发布时间】:2019-01-25 21:02:45
【问题描述】:
【问题讨论】:
标签:
ios
material-components-ios
【解决方案1】:
假设您已经在视图控制器中实现了UIPageViewControllerDelegate,您可以执行以下操作:
func pageViewController(_ pageViewController: UIPageViewController, willTransitionTo pendingViewControllers: [UIViewController]) {
let index = pages.index(of: pendingViewControllers[0])!
tabBarView.setSelectedItem(tabBarView.items[index], animated: true)
}
加MDCTabBarDelegate部分:
func tabBar(_ tabBar: MDCTabBar, willSelect item: UITabBarItem) {
let currentIndex = tabBarView.items.index(of: tabBarView.selectedItem!)!
let nextIndex = tabBarView.items.index(of: item)!
var direction = currentIndex < nextIndex ? UIPageViewControllerNavigationDirection.forward : UIPageViewControllerNavigationDirection.reverse
setViewControllers([pages[nextIndex]], direction: direction, animated: true, completion: nil)
}