0

I am using left side menu from this pod https://github.com/jonkykong/SideMenu. here I have given storyboard side menu button to UISideMenuNavigationController Present Modually Segue and side menu is working fine but my issue is, if I click(open) side menu button then I have changed background view colour which is not changing to its original colour when I close side menu.

like below mentioned answer if i change my code:

import UIKit
import SwiftKeychainWrapper
import SideMenu

class ProfileViewController: UIViewController, UITextFieldDelegate {

  override func viewDidLoad() {
      super.viewDidLoad()
  }
 @IBAction func sideMenubtn(_ sender: Any) {
   view?.backgroundColor = UIColor(white: 1, alpha: 0.9)
}
}


extension ProfileViewController : SideMenuNavigationControllerDelegate 
{
func sideMenuWillDisappear(menu: SideMenuNavigationController, animated: Bool) {
  view?.backgroundColor = UIColor.white
}
}

i got this error:

Use of undeclared type 'SideMenuNavigationControllerDelegate'

Use of undeclared type 'SideMenuNavigationController'

how do I remove this colour when I close the side menu, please help me.

Community
  • 1
  • 1
Swift
  • 1,074
  • 12
  • 46

3 Answers3

1
import SideMenu
import UIKit

class ViewController: UIViewController {

    var menu: SideMenuNavigationController?

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        menu = SideMenuNavigationController(rootViewController: MenuListController())
        menu?.leftSide = true
        menu?.setNavigationBarHidden(true, animated: false)
        SideMenuManager.default.addPanGestureToPresent(toView: self.view)
        SideMenuManager.default.leftMenuNavigationController = menu
    }

    @IBAction func didTappedMenu() {
        present(menu!, animated: true)

    }
}

class MenuListController: UITableViewController {

    var item = ["one","two","there","four","five","six","seven","eight","nine"]
    let darkColor = UIColor(red: 33/255.0, green: 33/255.0, blue: 33/255.0, alpha: 1)

    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
        tableView.backgroundColor = darkColor

    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return item.count
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell" , for: indexPath)
        cell.textLabel?.text = item[indexPath.row]
        cell.textLabel?.textColor = .white
        cell.backgroundColor = darkColor
        return cell
    }

    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
    }
}

Ely
  • 8,259
  • 1
  • 54
  • 67
Mobile Mh
  • 11
  • 1
  • When possible, please make an effort to provide additional explanation instead of just code. Such answers tend to be more useful as they help members of the community and especially new developer better understand the reasoning of the solution, and can help prevent the need to address follow-up questions. – Rajan May 07 '20 at 06:28
0

You can implement SideMenuNavigationControllerDelegate methods in your view controller and then change color when sideMenuWillDisappear triggers

cmashinho
  • 605
  • 5
  • 21
  • yes, i have added `extension MyViewController: SideMenuNavigationControllerDelegate { }` in my viewcontroller ......... then i got this error `Use of undeclared type 'SideMenuNavigationControllerDelegate'` why?? – Swift Dec 24 '19 at 11:11
  • yes, i have edited my question with my total code and error, please check it once.. and please let me know where i did mistake – Swift Dec 24 '19 at 14:13
  • how to add side menu delegate in view didload – Swift Dec 24 '19 at 16:14
0

Add delegate methods. it will work you can see the following code-

extension YourClassName : SideMenuNavigationControllerDelegate {
func sideMenuWillDisappear(menu: SideMenuNavigationController, animated: Bool) {
    *do the color thing*
}
}

And keep in mind to do-

import SideMenu

But i will not recommend you to change the color of view like this. You can use alpha property of side menu to dark the background view while presenting the side menu. Take reference from -

let menu = storyboard!.instantiateViewController(withIdentifier: "SideMenuNavigationController") as! SideMenuNavigationController
    var set = SideMenuSettings()
    set.statusBarEndAlpha = 0
    set.presentationStyle = SideMenuPresentationStyle.menuSlideIn
    set.presentationStyle.presentingEndAlpha = 0.5


    set.menuWidth = min(view.frame.width, view.frame.height) * 0.90
    //menu.sideMenuManager.addScreenEdgePanGesturesToPresent(toView: self.view)
    menu.settings = set
    //SideMenuManager.default.addScreenEdgePanGesturesToPresent(toView: view)
    SideMenuManager.default.leftMenuNavigationController = menu
  • I have added my total code in above question and mentioned my error as well please look at it once, and let me know mistake in code – Swift Dec 24 '19 at 14:15
  • for color change in background while side menu in and out, where should i place your 2nd mentioned code – Swift Dec 24 '19 at 14:17
  • how to add side menu delegate in view didload – Swift Dec 24 '19 at 16:13
  • You dont need to add delegate in view didload. you can place the second code in a function and call the function in the veiwdidload(of the masterview on which the side menu will appear.) – Piyush Sharma Dec 26 '19 at 11:47
  • yes, same error Use of undeclared type 'SideMenuNavigationController' in first line – Swift Dec 26 '19 at 11:52
  • r u using side menu in your project.. i mean in latest version – Swift Dec 26 '19 at 11:53
  • okay, then why i am getting above mentioned error in my project – Swift Dec 26 '19 at 14:28