2016-03-03 32 views
0

我想在每次出現floatingViewController時隱藏FabButton,並在關閉視圖時再次顯示它。當floatingViewController出現時隱藏FabButton。 Cosmicmind /材質

我試圖隱藏FabButton本身

self.menuButton.hidden = true 

但沒有一個回調函數,當我關閉floatingViewController所以我沒有辦法取消隱藏它。

我也嘗試手動設置z位置,但按鈕不受影響

是否有這更好的方法呢?

回答

0

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") 
} 

}

您應該能夠使用這些方法來達到預期的效果。

+0

謝謝,這個問題解決了。我是新來的迅速,我不知道代表的概念。 –

+0

太棒了! :)您應該將答案標記爲已接受,以便將來的搜索顯示這有一個解決方案。 – CosmicMind

0

此方法添加到FloatingViewController類

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

它的工作,但我會堅持委託方法有更多的可讀代碼。 –

相關問題