当 floatingViewController 出现时隐藏 FabButton。 Cosmicmind/Material
Hide FabButton when floatingViewController appears. Cosmicmind/Material
我想在每次出现 floatingViewController 时隐藏 FabButton,并在关闭视图时再次显示它。
我尝试用
隐藏 FabButton 本身
self.menuButton.hidden = true
但是当我关闭 floatingViewController 时没有回调函数,所以我没有办法取消隐藏它。
我也尝试过手动设置 zPosition,但按钮不受影响
有更好的方法吗?
NavigationBarViewController 具有用于检测 floatingViewController 状态的委托方法。设置委托对象,
navigationBarViewController?.delegate = self
然后尝试委托方法:
extension AppNavigationBarViewController: NavigationBarViewControllerDelegate {
/// Delegation method that executes when the floatingViewController will open.
func navigationBarViewControllerWillOpenFloatingViewController(navigationBarViewController: NavigationBarViewController) {
print("Will Open")
}
/// Delegation method that executes when the floatingViewController will close.
func navigationBarViewControllerWillCloseFloatingViewController(navigationBarViewController: NavigationBarViewController) {
print("Will Close")
}
/// Delegation method that executes when the floatingViewController did open.
func navigationBarViewControllerDidOpenFloatingViewController(navigationBarViewController: NavigationBarViewController) {
print("Did Open")
}
/// Delegation method that executes when the floatingViewController did close.
func navigationBarViewControllerDidCloseFloatingViewController(navigationBarViewController: NavigationBarViewController) {
print("Did Close")
}
}
您应该可以使用这些方法来达到预期的效果。
将此方法添加到 FloatingViewController class
override func viewWillDisappear(animated: Bool) {
let vc = ...assign to the viewcontroller that holds tour menu button
vc.menuButton.hidden = false
}
我想在每次出现 floatingViewController 时隐藏 FabButton,并在关闭视图时再次显示它。
我尝试用
隐藏 FabButton 本身self.menuButton.hidden = true
但是当我关闭 floatingViewController 时没有回调函数,所以我没有办法取消隐藏它。
我也尝试过手动设置 zPosition,但按钮不受影响
有更好的方法吗?
NavigationBarViewController 具有用于检测 floatingViewController 状态的委托方法。设置委托对象,
navigationBarViewController?.delegate = self
然后尝试委托方法:
extension AppNavigationBarViewController: NavigationBarViewControllerDelegate {
/// Delegation method that executes when the floatingViewController will open.
func navigationBarViewControllerWillOpenFloatingViewController(navigationBarViewController: NavigationBarViewController) {
print("Will Open")
}
/// Delegation method that executes when the floatingViewController will close.
func navigationBarViewControllerWillCloseFloatingViewController(navigationBarViewController: NavigationBarViewController) {
print("Will Close")
}
/// Delegation method that executes when the floatingViewController did open.
func navigationBarViewControllerDidOpenFloatingViewController(navigationBarViewController: NavigationBarViewController) {
print("Did Open")
}
/// Delegation method that executes when the floatingViewController did close.
func navigationBarViewControllerDidCloseFloatingViewController(navigationBarViewController: NavigationBarViewController) {
print("Did Close")
}
}
您应该可以使用这些方法来达到预期的效果。
将此方法添加到 FloatingViewController class
override func viewWillDisappear(animated: Bool) {
let vc = ...assign to the viewcontroller that holds tour menu button
vc.menuButton.hidden = false
}