【问题标题】:MDCTabBar selection indicator animationMDCTabBar 选择指示器动画
【发布时间】:2019-01-25 21:02:45
【问题描述】:

我是 iOS 开发的新手,我正在尝试通过在页面之间滑动来重新创建 Android 风格的顶部标签。 https://material.io/design/components/tabs.html#behavior

我正在使用 UIPageViewController 和 MDCTabBar 来复制 Android ViewPager+TabView 组合。但是,我不能使标签指示器(活动标签的突出显示)与标签滑动一起移动。使用 MDCTabBar 是不可能的还是我错过了什么?

【问题讨论】:

    标签: 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)
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多