Giter VIP home page Giter VIP logo

sidemenu's Introduction

Version Swift5 Carthage compatible License Platform

Overview

SideMenu is an easy-to-use side menu container controller written in Swift 5.

Besides all the features a Side Menu should have, it supports:

  • Four kinds of status bar behaviors (iOS 12 only)
  • Three different menu position
  • Both storyboard and programmatically
  • Caching the content view controller and lazy initialization
  • Rubber band effect while panning
  • Custom transition animation
  • RTL supports
  • API References
  • CHANGELOG

Preview

Menu Position / Status Menu Behavior

Above + None Below + Slide
SideBySide + Fade SideBySide + HideOnMenu

We call the left/right view controller as the menu view controller, the central view controller as content view controller.

Installation

For Swift 5.0 and later, please use 2.0.0 or later version.

CocoaPods

To install SideMenu with CocoaPods, add the below line in your Podfile:

pod 'SideMenuSwift'
# Note it's NOT 'SideMenu'

Carthage

To install SideMenu with Carthage, add the below line in your Cartfile:

github "kukushi/SideMenu" "master"

Swift Package Manager

  1. In your project's Package Description, click the + to add a new package.
  2. Paste https://github.com/kukushi/SideMenu.git into the search field.
  3. Choose the project to integrate in the Add to Project selection box.
  4. Click Add Package.
  5. Note that you should use import SideMenu to import SideMenu.

Usages

Storyboard

To set up `SideMenu` in storyboard:
  1. Open the view controller's Identity inspector. Change its Class to SideMenuController and Module to SideMenuSwift.
  2. Set up the menu view controller and the initial content view controller in your Storyboard. Add a Custom segue from the SideMenuController to each of them.
    • Change the menu segue's identifier to SideMenu.Menu, Class to SideMenuSegue and Module to SideMenuSwift.
    • Change the content segue's identifier to SideMenu.Content, Class to SideMenuSegue and Module to SideMenuSwift.
  3. (Optional) If you want to use custom segue identifier:
    • Open the SideMenuController's Attribute inspector.
    • In the Side Menu Controller section, modify the Content SegueID/Menu SegueID to the desired value and change the corresponding segue's identifier.
  4. It's done. Check this screenshot a for clear view.

Programmatically

To start the app with `SideMenu` programmatically:
import UIKit
import SideMenuSwift
// If you are using Carthage, uses `import SideMenu`

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    @objc func applicationDidFinishLaunching(_ application: UIApplication) {
        let contentViewController = ...
        let menuViewController = ...

        window = UIWindow(frame: UIScreen.main.bounds)
        window?.rootViewController = SideMenuController(contentViewController: contentViewController, 
        menuViewController: menuViewController)
        
        window?.makeKeyAndVisible()
        return true
    }
}

Use the sideMenuController method which provided in UIViewController's extension to get the parent SideMenuController:

viewController.sideMenuController?.revealMenu()

Preferences

All the preferences of SideMenu can be found in SideMenuController.preferences. It's recommend to check out the Example to see how those options will take effect.

SideMenuController.preferences.basic.menuWidth = 240
SideMenuController.preferences.basic.statusBarBehavior = .hideOnMenu
SideMenuController.preferences.basic.position = .below
SideMenuController.preferences.basic.direction = .left
SideMenuController.preferences.basic.enablePanGesture = true
SideMenuController.preferences.basic.supportedOrientations = .portrait
SideMenuController.preferences.basic.shouldRespectLanguageDirection = true

// See a lot more options on `Preferences.swift`.

Caching the Content

One of the coolest features of SideMenu is caching.

// Cache the view controllers somewhere in your code
sideMenuController?.cache(viewController: secondViewController, with: "second")
sideMenuController?.cache(viewController: thirdViewController, with: "third")

// Switch to it when needed
sideMenuController?.setContentViewController(with: "second")

What about the content view controller initialized from the Storyboard? We can use the preferences to apply a default key for it!

SideMenuController.preferences.basic.defaultCacheKey = "default"

What if we can't want to load all the content view controllers so early? We can use lazy caching:

sideMenuController?.cache(viewControllerGenerator: { self.storyboard?.instantiateViewController(withIdentifier: "SecondViewController") }, with: "second")
sideMenuController?.cache(viewControllerGenerator: { self.storyboard?.instantiateViewController(withIdentifier: "ThirdViewController") }, with: "third")

Requirements

  • Xcode 15 or later
  • iOS 12.0 or later

License

SideMenu is available under the MIT license. See the LICENSE file for more info.

sidemenu's People

Contributors

alinradut avatar dependabot[bot] avatar kukushi avatar mamtakukreja avatar microbee23 avatar msalmanst avatar renanwillamy avatar ruchinsinghal avatar xxi511 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sidemenu's Issues

Left and right Menu

HI guys,

Is it possible to use one menu on the left side and another on the right ?

Thanks

Programatic example

I see stroyboard everywhere but I see no programatic example. Can anyone point me in the direction of now

SideMenuControllerDelegate func not called

Following functions are not called when SideMenu is opened.
I need to print SideMenu frame / bounds before and after the reveal for layout debugging.

    func sideMenuWillHide(_ sideMenu: SideMenuController) {
        print("[Example] Menu will hide")
    }
    
    func sideMenuDidHide(_ sideMenu: SideMenuController) {
        print("[Example] Menu did hide.")
    }
    
    func sideMenuWillReveal(_ sideMenu: SideMenuController) {
        print("[Example] Menu will show.")
    }
    
    func sideMenuDidReveal(_ sideMenu: SideMenuController) {
        print("[Example] Menu did show.")
    }

View doesn't display correctly

Hello,

First thanks for your library. I've got some issue tu display the drawer.
I used the library programmatically.
This is the hierarchy of my view controllers :
UINavigationController -> UIRootCollectionViewController -> (DrawerViewController, ContentVieController)

screen shot 2018-07-04 at 09 59 24

screen shot 2018-07-04 at 09 59 33

screen shot 2018-07-04 at 10 05 24

screen shot 2018-07-04 at 10 05 34

As you can see there is a "gap" between the root and the content / drawer. The content and the drawer are not sticked to the top of the root view.
To fix it i've change in contentFrame() and sideMenuFrame() functions the baseFrame variable (see comment below).
I don't really know if it's the good way, but it works.

Thanks

Side menu pan gesture overrides tableview's cell swipe gesture

I think the menu's gesture should be a Screen Edge Pan, not a classic pan. I want to swipe over my tableview's cell and it triggers the sliding menu, even from the middle of the screen.

I will disable the pan gesture in this screen, but I think a better solution is needed.

Push View

Hi, really nice side menu.

I have a problem when I push to a view controller ,I can acces a view through the side menu or with a push , but when i call the side menu from a push view with the "sm_sideMenuController" it wont work , only when i call the view from the side menu i cant keet calling the side menu.

Thanks

Increase shadow opacity

Thanks for this wonderful library!

I am using the .above position to show the sidemenu, but I need to reduce the opacity of the viewcontroller that's hidden behind. Is there any property to do the same?

Passing data in prepareForSegue

Currently there is no way to pass data with prepareForSegue, when a content view is segued to from another controller. Due to the file's access control permissions, there is no way to subclass SideMenuController since its target module is not the same as the main project

Support for Objective C

I try to implement side menu on my objective c based project and it works fine on pan gesture. I create bridging header to call revealMenu method on a button , but it doesn't work ..

I double check the file and I see this line of code

  /// Access the nearest ancestor view controller hierarchy that is a side menu controller.
    public var sideMenuController: SideMenuController? {
        return findSideMenuController(from: self)
    }
    
    @available(*, deprecated, message: "Renamed to `sideMenuController`.")
    /// `SideMenu` currently doesn't support Objective-C, therefore the prefix was removed.
    public var sm_sideMenuController: SideMenuController? {
        return sideMenuController
    }
    

Please give me ideas to work on it.

first time menu not show after login

after login menu not show how to show menu when pressed in login button

    if UserDefaults.standard.string(forKey: "id") != nil {
        let story = UIStoryboard(name: "Main", bundle: nil)
        let side = UIStoryboard(name: "SideMenu", bundle: nil)
        window?.rootViewController = SideMenuController(contentViewController: story.instantiateInitialViewController()!, menuViewController: side.instantiateInitialViewController()!)
        SideMenuController.preferences.basic.menuWidth = 240
        SideMenuController.preferences.basic.statusBarBehavior = .hideOnMenu
        SideMenuController.preferences.basic.position = .sideBySide
        SideMenuController.preferences.basic.direction = .left
        SideMenuController.preferences.basic.enablePanGesture = true
        SideMenuController.preferences.basic.supportedOrientations = .portrait
        SideMenuController.preferences.basic.shouldRespectLanguageDirection = true
        window?.makeKeyAndVisible()
    } else {
        let story = UIStoryboard(name: "Login", bundle: nil)
        window?.rootViewController = story.instantiateInitialViewController()
        window?.makeKeyAndVisible()
    }

SideMenuController without cache

Hi,

This library is very useful for me.

This is not an issue. I want to load ViewController without cache , that means i want to load viewController each and every time from viewDidLoad when clicking on side menu.

Back button instead of menu

Hi
how i can add back button instead of menu button?!!!

i want when click to back button, come back to first page

App is crashing

My app is portrait for iPhone and landscape for iPad. It is crashing on

Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and [SideMenuSwift.SideMenuController shouldAutorotate] is returning YES'

I am using storyboard and my storyboard file is different for iPhone and iPad

Set Root view controller

Hi,
Can I set the selected view controller as Root view controller? i.e all other view controllers want to remove from the view controller stack

Problems with swipe to delete in UITableView and support in RTL

Hi,
I just downloaded the library (what was very easy, surprisingly) and I'm facing 2 problems:

  1. Swipe to delete in UITableView is not working at all because the menu is opening on swipe from everywhere on the screen (it should be only on the area that close to the menu side, for example, 20px).

  2. The menu doesn't supporting RTL languages, it's stay on right/left in any language, what makes bad UI/UX for the RTL languages' speakers (and I'm sure a little if could fix it).

Thanks,
Ido.

viewdidLoad()

want viewdidload() to be called every-time it selects a viewcontroller from sidemenu

How to pass data from sidemenucontroller to contentviewcontroller

Hi,

I have created a root ContentViewController for my main view and a NavigationViewController for the sidemenu.
I am trying to launch the screen as suggested in readme like this -

let nav = NavigationViewController.createViewController()
        window.rootViewController = SideMenuController(contentViewController: viewController, menuViewController: nav)
        
        window.makeKeyAndVisible()

where viewController is my ContentViewController and nav is my NavigationViewController

Now in my viewController I can do

@IBAction func onClickMenu(_ sender: Any) {
        menuVisible = !menuVisible
        if menuVisible {
            sideMenuController?.revealMenu()
        } else {
            sideMenuController?.hideMenu()
        }
    }

Now, how can I pass data from menu controller to my content view controller for example if I have a array list of menu items displayed in my menu controller and I want to pass the currently selected menu item to this content view controller. Is this possible ? if so can you please show me how this can be done or can you point me to a example that does the same

SelectionCell width = 240

You've set SelectionCell width as 240 in the storyboard.
I'm making an app with 100% programmatic implementation of the SideMenu.
The cell width being the normal size is pushing the menu options out of the screen unless I add 220 to left side Anchor of the icon image view.
How do set the SideMenu table cell to have the desired width with consistent view across all devices?

Service Call

Hi,
e.g., I have menu like 1,2,3,4,5.
When I select any option I got the container VC and service is Call only first time. I want service called everytime while select the option. Now, right now i have sync option if 5. So when I tap on 5 then service is called first time only. When I repeatedly tap on option 5 then No service is called.
Why?

Thanks

2 Side menus in different pages

Hello kukushi, thank you for the great work,

Is it possible to have a second side menu in another page? my app has one side menu in the main page and it opens from the left.. I want to add another side menu in the next page but it should slide from the right.. and have different content.

Possible?

Thank you

how can clear selected item highlight ?

how can clear selected item highlight ?

because of i show popup dialog in " didSelectRowAt " but still highlighted after press

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

Menu won't show if I segue to another VC

Hello,

So, I have imported this pod, tested the example and everything worked perfect.
I can set it so it shows the menu on the initial screen.

The Menu is also persistent if I choose cell 0 (which is the initial cell). Meaning if I choose that cell it will stay on my initial VC and the menu keeps appearing/

Now the problem is: If I segue from the buttons on my VC, the menu won't appear anymore, even though I have on my code sideMenuController?.cache(viewControllerGenerator: { self.storyboard?.instantiateViewController(withIdentifier: "StandardVC") }, with: "1")

Am I missing something obvious @kukushi ?
Here is a Print Screen of my storyboard, thanks :)

P.S.: the VC with the 3 big buttons (standard, isa, pension) is the initial VC
Screenshot 2019-04-15 at 11 57 45

isInitiatedFromStoryboard as a Configuration Preference

Hi! First of all, thanks for sharing your controller!

Currently, the code assumes the use of segues if the view controller was instantiated by a storyboard, which may not be necessarily true (i.e architecture that uses a storyboard for each view controller, but no segues):

private var isInitiatedFromStoryboard: Bool {
    return storyboard != nil
}

and

// Setup from the IB
if isInitiatedFromStoryboard {
    // Note that if you are using the `SideMenuController` from the IB, you must supply the default or
    // custom view controller ID in the storyboard.
   performSegue(withIdentifier: contentSegueID, sender: self)
   performSegue(withIdentifier: menuSegueID, sender: self)
}

Having the option to set this value by a configuration property or have the property declared as open
would be great!

Thanks

Is it possible to navigate to a special tab bar item?

Hello there again, im continuing using your great framework.
I have found an issue in my project. I want to move from an imageTapped in the SideMenu, but Im only able to present my startingViewController(FirstView, with his own navigationController and TabBarController as FatherViews)

Do you think it is possible? Can you give me any idea?
Thanks for your time.

captura de pantalla 2018-06-29 a las 12 56 45

Slow first time menu is revealed with subviews added

Hi all,

I just added SideMenu's cocoa pod to mySwift 4.2 iOS project. I followed the documentation to the latter.

The experience I have is the fist time I call sideMenuController.revealMenu() is that it's really slow when views have been added on the sideMenuController. It works smoothly afterwards. It tried calling this function asynchronously thinking it could work, but nothing improved. Everything works smoothly all time when the sideMenuController has little or no views added unto it.

I don't know if anyone experienced this. Any help would be appreciated.

Thanks

UISplitViewController not showing the Detail View

I have this code:
self.window = UIWindow(frame: UIScreen.main.bounds)
let splitViewController = UISplitViewController()
let navCtrl = UINavigationController(rootViewController: SecondVC())
splitViewController.viewControllers = [SideMenuController(contentViewController: navCtrl, menuViewController: ListMenuVC()), SecondChildVC()]
splitViewController.preferredDisplayMode = .allVisible
self.window!.rootViewController = splitViewController
self.window!.makeKeyAndVisible()

When the app loads, the Detail View is not showing, I have to open the Side menu first.
The only quick is to call revealMenu and hideMenu methods:

DispatchQueue.main.async {
self.sideMenuController?.revealMenu(animated: false)
self.sideMenuController?.hideMenu()
}

statusBar 不恰当隐藏

当 menu direction 为 left 时,在右边沿滑动,状态栏会隐藏,松开手后复原,当 menu direction 为 right 时,在左边沿滑动也一样。

Menu not displayed as expecting

Hello,

First, thanks for your library !

I'm encountering an issue with the menu. It is embedded in a navigation controller and contains a segmented control and a table view. The menu is width UIScreen.main.bounds.width - 44.0, but the menu seems to be 375 pixels large (the width of my iPhone screen).

What can be the reason for this problem?

Thanks for your help.

Bug When inherit UINavigationController

I try to make sideMenuController have a navigation, but when I try to swipe the menu. navigation controller being pushed down and my navigation title not showing.

basic.position = .under 时主视图变暗没有过渡动画

1.如题,我的side menu 在左边,刚向右划,主视图突然变暗,而不是逐渐变暗(提供的示例程序也是这样子),basic.position = above 和 sideBySide 则没有此问题。
2.顺便请问一下在划出side menu时能否不让主视图变暗?

3.关于已经关闭的问题 Position with .under will be full screen #36 我也同样遇到了此问题,在用代码而不用 Storyboard 创建side menu controller时会这样
a
storyBoard:
屏幕快照 2019-03-20 23 22 52

Tabbed Bar Views open Menu by a Navigation Left Item Problem

Thank you for this awesome framework.
I have just use it in a project, and here is my problem.
I'm using this hierarchy. Navigation Controller --> TabBarController --> Three TabbedBarViews.

I have the same navigation menu button for all my tabbed bars, but i have to instantiate as initial Controller my Navigation Controller.
When I try to appear the menu from my second or my third view by clicking on this button, this is showed but the backView of the menu is changed to my FirstTabController.
I don't have this issue when I swipe right to show it. I mean i can show it correctly by swipping, but not by clicking on the button.

Hope you have any idea. If you need I can send you an image for the aproximation.

setContentViewController with UITabBarController

My app is built using a UITabBarController.

Seems that the only menu item that works is whatever my default is. Any other view controller I transition to loses both it's UINavigationBar & UITabBar.

What's the best way to transition to tabs?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.