I want to change button image whenever UISideMenuNavigationController Appear Or Disappear.
This is the class that has a button.
class MenuViewController
You simply need to subclass UISideMenuNavigationController
and override the viewDidAppear
& viewDidDisappear
methods to invoke a delegate.
protocol MyUISideMenuDelegate {
func menuDidAppear(_ menu:MyUISideMenuNavigationController) -> Void
func menuDidDisappear(_ menu:MyUISideMenuNavigationController) -> Void
}
open class MyUISideMenuNavigationController: UISideMenuNavigationController {
var menuDelegate: MyUISideMenuDelegate?
override open func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
self.menuDelegate?.menuDidAppear(self)
}
override open func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
self.menuDelegate?.menuDidDisappear(self)
}
}
Then have you view controller with the button implement the protocol and set itself as the delegate.
You could also have your menu subclass send NSNotification
and have any other objects that are interested subscribe to those. This way you completely decouple the menu and the other classes.
MenuViewController
class could have a function that changes the image on the button. Eg, func changeButtonMenuImage()
.@IBOutlet var menuController: MenuViewController
viewDidAppear
and viewDidDisappear
can call it's function. Eg, menuController.changeButtonMenuImage()