美文网首页
iOS 侧拉菜单 DCSidebar

iOS 侧拉菜单 DCSidebar

作者: ldclll | 来源:发表于2017-05-31 10:24 被阅读491次

写了一个项目中经常会用到的侧拉菜单,使用方法很简单,把自定义的view初始化传入即可。

override func viewDidLoad() {
        super.viewDidLoad()
        
        menuTableview.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
        
        //自定义view
        let view = UIView(frame: CGRect.init(x: 0, y: 0, width: 250.0, height: UIScreen.main.bounds.height))
        view.backgroundColor = UIColor.blue
        view.addSubview(menuTableview)
        
        //创建侧拉菜单
        sidebar = DCSidebar(sideView: view)
        //设置动画的开始和结束时间
        sidebar?.showAnimationsTime = 0.2
        sidebar?.hideAnimationsTime = 0.2
    }
    @IBAction func showButtonTouchUpInside(_ sender: Any) {
        //显示侧拉菜单
        sidebar?.show()
    }
    
    @IBAction func screenEdgePanGesture(_ sender: UIScreenEdgePanGestureRecognizer) {
        if sender.state == .ended {
            sidebar?.show()
        }
    }

效果图

点击收起 拖出菜单 拖动的动画效果

项目地址:https://github.com/ldclll/DCSidebar.git

相关文章

网友评论

      本文标题:iOS 侧拉菜单 DCSidebar

      本文链接:https://www.haomeiwen.com/subject/fcbdfxtx.html