【问题标题】:Custom Bottom Bar transition to another view in Swift?自定义底部栏过渡到 Swift 中的另一个视图?
【发布时间】:2017-10-02 22:01:58
【问题描述】:

所以,我用 UIButton 制作了一个自定义底栏。现在我正在尝试复制淡入淡出过渡,因此当您单击底部栏中的一个按钮时,将发送到另一个视图控制器并显示该视图。我设法做到了,但我的导航栏不是自定义导航栏,每当我切换视图时,主视图都会位于导航栏下方。

我正在使用此代码:

//MARK: Main view
func yourFoodGoalAction() -> Bool {
    print("transition: YourFoodGoal")

    let nextViewController = YourFoodGoal()
    let toView = nextViewController.view

    UIView.transition(from: view!, to: toView!, duration: 0.3, options: [.transitionCrossDissolve]) { (true) in
        print("disolve")
        UIView.animate(withDuration: 0.3, animations: {
            self.navigationItem.title = "Your Goal"
        })
    }

    return true
}

然后返回视图(反之亦然):

func selectedBarButtonAction() -> Bool {
        print("transition: YourFoodGoal")

        let nextViewController = YourFoodVC()
        let toView = nextViewController.view

        UIView.transition(from: view!, to: toView!, duration: 0.3, options: [.transitionCrossDissolve]) { (true) in
            UIView.animate(withDuration: 0.3, animations: {
                self.navigationItem.title = "Today's Meals"
            })
        }

        return true
    }

我应该怎么做才能使我的视图在它们之间切换后不会出现在导航栏下方?我不想使用容器视图,因为每个视图都是自定义的。一切都是以编程方式制作的。

【问题讨论】:

  • 您是如何将工具栏添加到应用程序的?因为您应该能够将其作为子视图添加到主窗口。它应该在顶部
  • 工具栏是一个 NSObject,它通过函数被调用。它保持在顶部。问题是导航栏仍然存在,但是当我更改视图时,我的视图会在它下方。
  • 你能添加一些截图来说明问题
  • 刚刚添加了一个。看第三张图片 - 开始正常,但回到它被取代的同一张。在导航栏下方。
  • 在将自定义导航栏约束到 navigationController.tabBar 时,您是如何做到的?你用过 topLayoutGuide.bottomAnchor 吗?似乎顶级约束被打破了

标签: ios swift swift3 uinavigationbar ios10


【解决方案1】:

我找到了答案。我称模态转换错误。模式在主视图中全屏显示。我只是在呈现新视图并从那里调用模式时嵌入了导航:

func todaysMealsAction() {
    let yourFoodVC = YourFoodVC()
    yourFoodVC.modalTransitionStyle = UIModalTransitionStyle.crossDissolve
    let navBarOnModal: UINavigationController = UINavigationController(rootViewController: yourFoodVC)
    self.present(navBarOnModal, animated: false, completion: nil)
}

【讨论】:

    猜你喜欢
    • 2019-05-21
    • 2019-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多