0

Не могу понять как в Material design iOS менять экран при нажатии на кнопки таб бара.

 func setup_TabBar(){
    colorScheme.backgroundColor = .white
    view.backgroundColor = colorScheme.backgroundColor


    let tabBarItem1 = UITabBarItem(title: "Home", image: UIImage(named: "Home"), tag: 0)
    let tabBarItem2 = UITabBarItem(title: "Trend", image: UIImage(named: "Disc"), tag: 1)
    let tabBarItem3 = UITabBarItem(title: "Subscribe", image: UIImage(named: "Sub"), tag: 2)
    let tabBarItem4 = UITabBarItem(title: "User", image: UIImage(named: "User"), tag: 3)

    bottomNavBar.items = [ tabBarItem1, tabBarItem2 , tabBarItem3 , tabBarItem4]
    bottomNavBar.selectedItem = tabBarItem1
    bottomNavBar.backgroundColor = .white
    view.addSubview(bottomNavBar)
    bottomNavBar.delegate = self
}

func bottomNavigationBar(_ bottomNavigationBar: MDCBottomNavigationBar, didSelect item: UITabBarItem){
    guard let fromView = selectedViewController?.view, let toView = customizableViewControllers?[item.tag].view else {
        print(item.tag)
        return
    }

    if fromView != toView {
        UIView.transition(from: fromView, to: toView, duration: 0.3, options: [.transitionCrossDissolve], completion: nil)
    }
    self.selectedIndex = item.tag
}

func layoutBottomNavBar() {
    let size = bottomNavBar.sizeThatFits(view.bounds.size)
    var bottomNavBarFrame = CGRect(x: 0, y: view.bounds.height - size.height, width: size.width, height: size.height)
    // Extend the Bottom Navigation to the bottom of the screen.
    if #available(iOS 11.0, *) {
        bottomNavBarFrame.size.height += view.safeAreaInsets.bottom
        bottomNavBarFrame.origin.y -= view.safeAreaInsets.bottom
    }
    bottomNavBar.frame = bottomNavBarFrame
}

При нажатий Tab Bar выполняется "bottomNavigationBar didselect". Что нужно добавить чтобы экран менялся?

4
  • Напишите более развернутый вопрос. 14 июн 2019 в 12:07
  • Поправку сделал. 14 июн 2019 в 12:41
  • Вообще говоря tab bar в iOS как правило не требует программной генерации (хотя она и возможна), все делается в IB и очень просто. Я не знаком с material-design, это специфика их библиотеки?
    – Olter
    14 июн 2019 в 13:27
  • Нашел решение! Надо было как раньше в swift-те создавать остальные экраны потом в Material Design добавлять. Вот маленький пример: func setup_TabBar(){ let one = UINavigationController(rootViewController: First_TB_ViewController()) one.tabBarItem = UITabBarItem(title: "Home", image: UIImage(named: "Home"), tag: 0) bottomNavBar.items = [ one.tabBarItem] viewControllers = [one] bottomNavBar.selectedItem = one.tabBarItem bottomNavBar.backgroundColor = .white view.addSubview(bottomNavBar) bottomNavBar.delegate = self } 15 июн 2019 в 4:30

0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Посмотрите другие вопросы с метками или задайте свой вопрос.