dekatotoro / SlideMenuControllerSwift

iOS Slide Menu View based on Google+, iQON, Feedly, Ameba iOS app. It is written in pure swift.
MIT License
3.4k stars 754 forks source link

View will appear not called #95

Open Carpemeid opened 8 years ago

Carpemeid commented 8 years ago

An awesome menu library) thanks!

The view will appear method is not called on the main controller, the first time main controller appears.

The following discussion will be based on the code below:

//the existing storyboardControllerTemplate is just a convenience method for creating the controller from //a storyboard with using a storyboardIdentifier

let leftMenuController : LeftMenuController = LeftMenuController.existingStoryboardControllerTemplate()

//my leftMenuController holds a reference to all the controllers to which the slide menu will have to //change. As a result the "leftMenuController.headquarterControllerBranch is just another created //controller from storyboard

presentViewController( DrawerController(mainViewController: leftMenuController.headquarterControllerBranch, leftMenuViewController: leftMenuController), animated: false, completion: nil)

//it is to mention that the controller obtained from "leftMenuController.headquarterControllerBranch" is a //view controller embedded in a navigationController

The view will appear is never called on first appearance of the leftMenuViewController as it is the "main view controller" in the slide menu. It is called afterwords when I change from another view controller to the leftMenuViewController, but never on it's first appearance. The viewDidLoad and viewDidAppear get called, but not the viewWillAppear.

Carpemeid commented 8 years ago

I managed to solve this issue but I guess I changed it in a critical way. Specifically I moved the code in SlideMenuController from viewDidLayoutSubviews to viewWillAppear and now the viewWillAppear also gets called on mainViewController. The problem is probably you have some reasons for which you used the viewDidLayoutSubviews (probably you had some wrong frame calculations or .. ). But even though I moved the code from viewDidLayoutSubviews I don't experience absolutely any problems with the layouting of my controllers. Please comment on why is it important to call the appearance of the controllers in viewDidLayout instead of viewWillAppear (preferably with some real issues you had).

dekatotoro commented 8 years ago

Thank you for feed back! Certainly that's right, layout process is entrusted in each viewController, looks good the setup in viewWillAppear. What is the version of iOS of this problem?

harrymelka commented 8 years ago

SlideMenuControllerSwift.zip

Hi, Thank you for this library. I have the same problem, I am trying to go from a LoginView to mainview using https://github.com/dekatotoro/SlideMenuControllerSwift/issues/129 it's working but when I arrive on the mainview the ViewWillAppear method is not called. So I end up with a translucide navbar without the menu logo and the screen under this navbar. I can use the drag effect to open the menu. The weird think is that when I change the view with the menu or even when I clic on the same view inside the menu, it's calling the ViewWillAppear method with everything working but not the dragging effect

I did it on a clean project there is the same problem.

Do you have an idea maybe Thank you

nilshott commented 8 years ago

This issue is still on.

I fixed my code by moving the contents of viewWillAppear to viewDidAppear. But that may not be feasable for every situation.

hossamghareeb commented 8 years ago

Just as a temporary fix for you guys who suffer from this issue like me. You can subclass SlideMenuController and override the following functions:

override func changeMainViewController(mainViewController: UIViewController, close: Bool) {
    super.changeMainViewController(mainViewController, close: close)
    appearTransitionForViewController(mainViewController)
}
override func changeLeftViewController(leftViewController: UIViewController, closeLeft: Bool) {
    super.changeLeftViewController(leftViewController, closeLeft: closeLeft)
    appearTransitionForViewController(leftViewController)
}

override func changeRightViewController(rightViewController: UIViewController, closeRight: Bool) {
    super.changeRightViewController(rightViewController, closeRight: closeRight)
    appearTransitionForViewController(rightViewController)
}

private func appearTransitionForViewController(viewController: UIViewController){
    viewController.beginAppearanceTransition(true, animated: false)
    viewController.endAppearanceTransition()
}
bohachevskyy commented 8 years ago

I have fixed this issue with overriding viewWillAppear method in SlideMenuController

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)

        mainViewController?.viewWillAppear(animated)
        leftViewController?.viewWillAppear(animated)
    }

Then methods such us: viewDidLoad, viewWillAppear, viewDidAppear etc. will be called in main and left controllers.