如何将侧边栏幻灯片菜单添加到现有应用程序(无故事板)

时间:2022-03-12 15:28:43

Does anyone know how I can implement a sidebar slide menu in an exiting app (without using storyboard)?

有谁知道如何在现有应用程序中实现侧边栏幻灯片菜单(不使用故事板)?

I have found SWRevealViewController, but all instructions are for a new app and an app with storyboards. I can't find any instructions for implementing it in an existing app, nor instructions for implementing it without storyboards.

我找到了SWRevealViewController,但所有说明都适用于新应用和带故事板的应用。我找不到在现有应用程序中实现它的任何说明,也没有在没有故事板的情况下实现它的说明。

I have a UINavigationControler with a rootViewController which is a tableViewController, but now I want to add a sidebar menu to the app.

我有一个带有rootViewController的UINavigationControler,它是一个tableViewController,但现在我想在应用程序中添加一个侧边栏菜单。

4 个解决方案

#1


You can use InteractiveSideMenu library. There are menuViewController and contentViewControllers members of class MenuContainerViewController that that can be instantiated from code.

您可以使用InteractiveSideMenu库。 MenuContainerViewController类的menuViewController和contentViewControllers成员可以从代码中实例化。

Here is an example:

这是一个例子:

class HostViewController: MenuContainerViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        self.menuViewController = YourMenuViewController()        
        self.contentViewControllers = [YourContentViewController()]

        self.selectContentViewController(contentViewControllers.first!)
    }
}

#2


Please find link below , you will find plenty of uicontrols here that enables you to implement sidemenu programmatically.

请在下面找到链接,您可以在这里找到大量的uicontrol,使您能够以编程方式实现sidemenu。

https://www.cocoacontrols.com/search?utf8=%E2%9C%93&q=side+menu

#3


you are going in right way, you need to push on SWRevealViewController class from your login button and hide uinavigaiton back button by this code.

你正在以正确的方式前进,你需要从登录按钮推送SWRevealViewController类并通过此代码隐藏uinavigaiton后退按钮。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {self.navigationController.navigationBar.hidden = YES; }

#4


Try it in Swift 3. Hope it help.

在Swift中尝试3.希望它有所帮助。

            let frontViewController = NavigationController() // UINavigationController
            let rearViewController  = MenuController() // display slide menu

            let revealController = SWRevealViewController(rearViewController: rearViewController, frontViewController: frontViewController)

            revealController?.toggleAnimationType = SWRevealToggleAnimationType.easeOut
            revealController?.toggleAnimationDuration = 0.30
            viewControllers = [revealController!]

            UIApplication.shared.keyWindow?.rootViewController = revealController

#1


You can use InteractiveSideMenu library. There are menuViewController and contentViewControllers members of class MenuContainerViewController that that can be instantiated from code.

您可以使用InteractiveSideMenu库。 MenuContainerViewController类的menuViewController和contentViewControllers成员可以从代码中实例化。

Here is an example:

这是一个例子:

class HostViewController: MenuContainerViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        self.menuViewController = YourMenuViewController()        
        self.contentViewControllers = [YourContentViewController()]

        self.selectContentViewController(contentViewControllers.first!)
    }
}

#2


Please find link below , you will find plenty of uicontrols here that enables you to implement sidemenu programmatically.

请在下面找到链接,您可以在这里找到大量的uicontrol,使您能够以编程方式实现sidemenu。

https://www.cocoacontrols.com/search?utf8=%E2%9C%93&q=side+menu

#3


you are going in right way, you need to push on SWRevealViewController class from your login button and hide uinavigaiton back button by this code.

你正在以正确的方式前进,你需要从登录按钮推送SWRevealViewController类并通过此代码隐藏uinavigaiton后退按钮。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {self.navigationController.navigationBar.hidden = YES; }

#4


Try it in Swift 3. Hope it help.

在Swift中尝试3.希望它有所帮助。

            let frontViewController = NavigationController() // UINavigationController
            let rearViewController  = MenuController() // display slide menu

            let revealController = SWRevealViewController(rearViewController: rearViewController, frontViewController: frontViewController)

            revealController?.toggleAnimationType = SWRevealToggleAnimationType.easeOut
            revealController?.toggleAnimationDuration = 0.30
            viewControllers = [revealController!]

            UIApplication.shared.keyWindow?.rootViewController = revealController