2

I am using left side menu from jonkykong/SideMenu. If I open side menu I need transparent background view and if i close then background should change to its original colour. For that i am trying to set alpha value for side menu.

I have tried two ways:

1) Here i have installed pod 'SideMenu' and added below code:

 import UIKit
 import SideMenu

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        sideMenuConfig()
    }
    func sideMenuConfig(){
        // Define the menus
        SideMenuManager.default.menuLeftNavigationController = storyboard!.instantiateViewController(withIdentifier: "UISideMenuNavigationController") as? UISideMenuNavigationController
        var set = SideMenuSettings()
        set.presentationStyle.presentingEndAlpha = 1
        SideMenuManager.default.menuPresentMode = .menuSlideIn
        SideMenuManager.default.menuFadeStatusBar  = false
        SideMenuManager.default.menuAddPanGestureToPresent(toView: self.navigationController!.navigationBar)
        SideMenuManager.default.menuAddScreenEdgePanGesturesToPresent(toView: self.navigationController!.view)
    }
} 

here why pod not recognising SideMenuSettings.

error: Use of unresolved identifier 'SideMenuSettings'

2) Updated pod to swift 5 pod 'SideMenu', '~> 6.0' and below code:

 import UIKit
 import SideMenu

 class ViewController: UIViewController, SideMenuNavigationControllerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        menuSettings()
    }
    func menuSettings(){
        let menu = storyboard!.instantiateViewController(withIdentifier: "SideMenuNavigationController") as! SideMenuNavigationController
        menu.blurEffectStyle = nil
        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.settings = set
        SideMenuManager.default.leftMenuNavigationController = menu
    }
}

here background view also moving with side menu like below How add give alpha value to side menu in swift.

Please help with the side menu code.

enter image description here

Swift
  • 1,074
  • 12
  • 46
  • Try - SideMenuSettings.presentationStyle.presentingEndAlpha = 1. – Aditya Jan 27 '20 at 14:34
  • @Aditya, error `Use of unresolved identifier 'SideMenuSettings'` ..Please do help – Swift Jan 27 '20 at 15:27
  • Change `SideMenuSettings().presentationStyle.presentingEndAlpha = 1` – Aditya Jan 27 '20 at 15:34
  • @Aditya, same error `Use of unresolved identifier 'SideMenuSettings'` – Swift Jan 27 '20 at 15:40
  • You can check jonkykong/SideMenu Example project by running it. – Aditya Jan 27 '20 at 16:27
  • Try `let presentationStyle = selectedPresentationStyle() ` and `presentationStyle.presentingEndAlpha = 0` and assign `var settings = SideMenuSettings()` and `settings.presentationStyle = presentationStyle` – Kishan Bhatiya Jan 28 '20 at 05:28
  • @KishanBhatiya, not working, `Use of unresolved identifier 'selectedPresentationStyle'` and `Use of unresolved identifier 'SideMenuSettings'` errors..... is there any other way.. please do help – Swift Jan 28 '20 at 09:33
  • @KishanBhatiya, I have updated code.. please have a look – Swift Jan 28 '20 at 09:43
  • just remove `let presentationStyle = selectedPresentationStyle()` ,`presentationStyle.presentingEndAlpha = 0` and add `settings.presentationStyle. presentingEndAlpha = 0` – Kishan Bhatiya Jan 28 '20 at 09:45
  • @KishanBhatiya, Use of unresolved identifier 'SideMenuSettings'... actually pod not recognising `SideMenuSettings` i dont know why.. i have imported SideMenu in project – Swift Jan 28 '20 at 09:50
  • @KishanBhatiya, which pod u have installed `pod 'SideMenu', '~> 6.0'` or `pod 'SideMenu', '~> 5.0'` ....... in Swift 5 i have demo project can i share the github link so u can find the issue quickely – Swift Jan 28 '20 at 10:07
  • 1
    Yes, add `pod 'SideMenu'` in your podfile which install latest pods – Kishan Bhatiya Jan 28 '20 at 10:08
  • @KishanBhatiya, yes.. if yours demo project in github, please share the link – Swift Jan 28 '20 at 11:34
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/206785/discussion-between-kishan-bhatiya-and-devios). – Kishan Bhatiya Jan 28 '20 at 12:22
  • @DevIos try to check my comment in chat – Kishan Bhatiya Jan 29 '20 at 05:50
  • menu.presentationStyle.presentingEndAlpha = 0.7 – Mohan Mar 09 '21 at 13:21

2 Answers2

7

Just create a subclass of SideMenuNavigationController and set the presentationStyle's backgroundColor and presentingEndAlpha properties in it. From now on, you can use your CustomSideMenuNavigationController as your SideMenuNavigationController.

class CustomSideMenuNavigationController: SideMenuNavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()

        setNavigationBarHidden(true, animated: false)

        self.presentationStyle = .menuSlideIn
        self.presentationStyle.backgroundColor = .white
        self.presentationStyle.presentingEndAlpha = 0.7

        self.statusBarEndAlpha = 0.0
        self.menuWidth = (UIScreen.main.bounds.width / 5) * 4
    }

}
Vmark
  • 156
  • 3
  • 6
1

For Transparent background need to change value of menuAnimationFadeStrength.

  • Demo::

SideMenuManager.default.menuAnimationFadeStrength = 0.5

  • thank u, its perfectly worked for option One... have u tried second option updating pod in swift 5 pod 'SideMenu', '~> 6.0' – Swift Feb 03 '20 at 11:36