美文网首页
人人可实现的滑动菜单二

人人可实现的滑动菜单二

作者: 小曼blog | 来源:发表于2018-12-19 12:02 被阅读23次

上一篇文章中,是把滑动菜单封装成一个View,当成一个View来使用。这一节中,我们把滑动菜单封装成ViewController来使用。支持的样式也更多了。

一、概述

sdk名称: ScrollMenusViewController
地址:https://github.com/weiman152/ScrollMenusViewController
支持cocoa pods导入:

pod ScrollMenusViewController
二、效果截图

1.支持类型总览


a1.png

2.各个类型预览


a4.png a5.png a6.png a7.png a9.gif a10.gif a11.gif a13.gif
三、实现思路
image.png
四、使用示例

创建:

let width = view.bounds.size.width / 3.0
        let titles = ["诗", "西游记", "离骚", "水浒传", "红楼梦", "悲惨世界", "巴黎圣母院", "红与黑"]
        let scrollVC = ScrollMenuViewController.instance(
            type: .fixWidth(width: width),
            titleType: .text(titles: titles),
            superVC: self,
            frame: CGRect(x: 0,
                          y: 84,
                          width: view.bounds.size.width,
                          height: view.bounds.size.height - 84)
        )
        view.addSubview(scrollVC.view)
        scrollVC.dataSource = self

添加自定义VC:

extension FixWidthTextViewController: ScrollMenuViewControllerDataSource {
    
    func menu(viewController: UIViewController, index: Int) {
        var vc = UIViewController()
        switch index % 3 {
        case 0:
            vc = ChildListViewController.instance(index: index)
        case 1:
            vc = ChildImageViewController.instance(index: index)
        case 2:
            vc = ChildTextViewController.instance(index: index)
        default: break
        }
        
        viewController.addChildViewController(vc)
        viewController.view.addSubview(vc.view)
        vc.view.frame = viewController.view.bounds
    }
}

希望大家多多提意见。

祝:开心,幸福

相关文章

网友评论

      本文标题:人人可实现的滑动菜单二

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