适用于 iOS 的像 Google Material Design 一样的抽屉

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31930585/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 07:12:49  来源:igfitidea点击:

Drawer like Google material design for iOS

iosmaterial-designnavigation-drawerdrawertoggle

提问by lalala

I'd like to implement navigation drawer like Uber into iOS(swift). I'm going to achieve it by using a library, called KYDrawerController. https://github.com/ykyouhei/KYDrawerController

我想在iOS(swift)中实现像Uber这样的导航抽屉。我将通过使用一个名为 KYDrawerController 的库来实现它。https://github.com/ykyouhei/KYDrawerController

However, it cannot provide toggle button, only slide action. Thought I'd like to to implement toggle button that shows the navigation drawer,I have no idea how to add such a function to the library. If you know how to add the function to the library, or how to achieve my purpose the other way(such as to use the other libraries), please tell me. Thank you for your kindness.

但是,它不能提供切换按钮,只能提供滑动操作。以为我想实现显示导航抽屉的切换按钮,我不知道如何将这样的功能添加到库中。如果您知道如何将函数添加到库中,或者如何以其他方式实现我的目的(例如使用其他库),请告诉我。谢谢你的好意。

Uber1Uber2

优步1优步2

回答by Kyouhei Yamaguchi

Using KYDrawerControllerit can be implemented as follows:

使用KYDrawerController可以实现如下:

class MainViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        view.backgroundColor = UIColor.whiteColor()
        title = "MainViewController"
        navigationItem.leftBarButtonItem = UIBarButtonItem(
            title: "Open",
            style: UIBarButtonItemStyle.Plain,
            target: self,
            action: "didTapOpenButton:"
        )
    }

    func didTapOpenButton(sender: UIBarButtonItem) {
        if let drawerController = navigationController?.parentViewController as? KYDrawerController {
            drawerController.setDrawerState(.Opened, animated: true)
        }
    }
}

https://github.com/ykyouhei/KYDrawerController/tree/master/Example/Code

https://github.com/ykyouhei/KYDrawerController/tree/master/Example/Code