jonkykong / SideMenu

Simple side/slide menu control for iOS, no code necessary! Lots of customization. Add it to your project in 5 minutes or less.
MIT License
5.67k stars 693 forks source link

Keyboard Hides when sidemenu appears but after closing side menu keyboard appears again. #570

Open Piyush-Sharma-Pandit opened 5 years ago

Piyush-Sharma-Pandit commented 5 years ago

I have read the guidelines for contributing and I understand

Describe the bug The bug is Keyboard Hides when sidemenu appears but after closing side menu keyboard appears again. normally this thing does not cause any problem at all. but the only big problem occurs while going to other view from side menu. more explaination in "To Reproduce".

To Reproduce Steps to reproduce the behavior:

  1. click on search bar so keyboard will appear.
  2. than go to side menu using screen edge pan gesture.
  3. from there go to another view by clicking any button in side menu.
  4. now on this new view controller you will find a black rectangle at the place of keyboard.

Expected behavior A clear and concise description of what you expected to happen.

Screenshots Screenshot 2019-10-21 at 4 02 21 PM Screenshot 2019-10-21 at 4 02 37 PM Screenshot 2019-10-21 at 4 02 49 PM

Note:= if i do all this without opening keyboard in starting than it works fine.

Additional context Add any other context about the problem here.

rehmanateeq commented 5 years ago

Did you find any solution. I am facing same issue and did not find any solution.

rehmanateeq commented 5 years ago

@jonkykong is there any solution for this behaviour??

relisiuol commented 5 years ago
override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    textField.endEditing(true)
}
rehmanateeq commented 5 years ago
override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    textField.endEditing(true)
}

It was the very first thing i tried

Piyush-Sharma-Pandit commented 5 years ago

@rehmanateeq No i have tried many things but cant find any way of doing this. So i have disabled the pan gesture and currently having sidemenu only from tapping the side menu button. Note:- There are some delegate method of the sidemenu Screenshot 2019-10-25 at 11 22 31 AM

So logically calling end editing in them should work fine but it is not working. if someone has the solution of this problem please let me know.

rtemple6 commented 4 years ago

Anyone find an update for this? I am experiencing the same thing :(

aherpooja commented 4 years ago

I was facing the same issue. Simulator Screen Shot - iPhone 8 - 2020-01-02 at 16 30 30

For me issue occurred when: I clicked textField and then opened new ViewController by selecting another SideMenu option. Then there was black view at bottom.

Below solution worked for me.

self.dismiss(animated: true) { () -> Void in self.customNavigationController.pushViewController(viewController, animated: true) }

I found this on one of Issue: "The problem is the presenting controller of Menu still live although SidMenu go away , so you should make it nil , to do that call self.dismiss(animated: false, completion: nil) method when you want go away from SideMenu."

I was not dismissing my SideMenu while pushing another ViewController. So when I did dismiss SideMenu and on its completion then I pushed my ViewController. It resolved the issue for me.

P.S.: I am using customNavigationController so that it will not push ViewController on SideMenuNavigationController.

rehmanateeq commented 4 years ago

I was facing the same issue. Simulator Screen Shot - iPhone 8 - 2020-01-02 at 16 30 30

For me issue occurred when: I clicked textField and then opened new ViewController by selecting another SideMenu option. Then there was black view at bottom.

Below solution worked for me.

self.dismiss(animated: true) { () -> Void in self.customNavigationController.pushViewController(viewController, animated: true) }

I found this on one of Issue: "The problem is the presenting controller of Menu still live although SidMenu go away , so you should make it nil , to do that call self.dismiss(animated: false, completion: nil) method when you want go away from SideMenu."

I was not dismissing my SideMenu while pushing another ViewController. So when I did dismiss SideMenu and on its completion then I pushed my ViewController. It resolved the issue for me.

P.S.: I am using customNavigationController so that it will not push ViewController on SideMenuNavigationController.

This Fixed my issue. Thanks

rehmanateeq commented 4 years ago

Anyone find an update for this? I am experiencing the same thing :(

Just dismiss Side Menu before pushing/showing another controller

Piyush-Sharma-Pandit commented 4 years ago

@aherpooja can you please provide a proper example with original code .

aherpooja commented 4 years ago

@Piyush-Sharma-Pandit When you select any menu option from Side menu before pushing/presenting another view controller first dismiss Side menu.

self.dismiss(animated: true) { () -> Void in self.customNavigationController.pushViewController(viewController, animated: true) }

soztemir commented 4 years ago

@aherpooja How did you create the sample customNavigationController? Can you share please?

phoney commented 4 years ago

I also ran into this problem. It appears that UIKit tries to remember if the keyboard is visible when a view controller is shown over another view controller and then closes the keyboard. When the front view controller goes away it restores the keyboard if it was showing. To avoid this problem you have to close the keyboard before showing the side menu. Once the side menu starts to become visible it's too late to prevent UIKit from this process of saving and restoring the keyboard state. I worked around this by closing the keyboard from a custom back button before showing the side menu. This code uses some other methods of mine but you get the idea.

    private func setupNavigationItem() {
        navigationItem.leftBarButtonItem = UIBarButtonItem.buttonWithBurgerMenu(action: #selector(self.openSideMenuSpecial), target: self)
    }
    @objc func openSideMenuSpecial() {
        // resignFirstResponder before opening the sideMenu
        // Otherwise there are crazy animations with the keyboard
        resignFirstResponderTextFields()
        openSideMenu()
    }

There is some code in SideMenuNavigationController that attempts to avoid this problem but in my case that code was too late. Any of the viewWillAppear, viewDidAppear or SideMenu delegate callbacks were also too late and resulted in the keyboard going away but it still came back with some crazy animations.

jonkykong commented 4 years ago

@phoney feel free to propose a more robust solution directly to the source code that alleviates this issue.

kishorekankata commented 4 years ago

Any update

FarhanBykea commented 4 years ago

Any update

@objc func openMenu() { self.view.endEditing(true) let leftRootVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(identifier: "LeftMenuViewController") let leftMenuNavigationController = SideMenuNavigationController(rootViewController: leftRootVC) leftMenuNavigationController.leftSide = true self.present(leftMenuNavigationController, animated: true, completion: nil) }