Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 当浮动视图控制器出现时隐藏按钮。宇宙思维/材料_Swift_Cosmicmind - Fatal编程技术网

Swift 当浮动视图控制器出现时隐藏按钮。宇宙思维/材料

Swift 当浮动视图控制器出现时隐藏按钮。宇宙思维/材料,swift,cosmicmind,Swift,Cosmicmind,我想在每次出现floatingViewController时隐藏一个按钮,并在关闭视图时再次显示该按钮 我试着把按钮藏起来 self.menuButton.hidden = true 但是当我关闭floatingViewController时没有回调函数,所以我没有办法取消隐藏它 我还尝试手动设置zPosition,但按钮不受影响 有更好的方法吗?NavigationBarViewController有委派方法来检测floatingViewController的状态。设置委托对象 naviga

我想在每次出现floatingViewController时隐藏一个按钮,并在关闭视图时再次显示该按钮

我试着把按钮藏起来

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类

override func viewWillDisappear(animated: Bool) {
  let vc = ...assign to the viewcontroller that holds tour menu button 
  vc.menuButton.hidden = false
}

这是可行的,但是我会坚持使用委托方法来获得更可读的代码。谢谢,这解决了问题。我是swift新手,不知道代表的概念。太好了!:)您应该将答案标记为已接受,以便将来的搜索显示这有一个解决方案。