实现scrollView添加多个ViewController

用尽洪荒之力写了第一版本的scrollMenu !语言:swift

Demo下载地址:http://git.oschina.net/bense_319/CustomScrollMenu

功能如下:
1、实现了scrollview添加多个viewController,并做到滚动
2、scrollview内存优化
3、仿网易滚动栏,实现字体大小跟随视图滚动且字体发生大小变化,
4、在网易滚动栏的基础上增加了下划线,可以通过属性设置是否显示
5、内部使用frame实现自动布局,做到各个屏幕间的布局,且支持横竖屏
6、可以直接把包拖到自己的项目中,直接使用...

看效果...

 

OK,我们现在进入正题......
一、如何使用这个包包
1、自己搭建一个viewController.swift文件
2、实例化你的子viewController以及标题, 并添加到数组。( 在我的demo中,我实例化了7个ViewController)
3、设置frame
4、设置options
5、实例化QBMenuMainController
6、将实例化后的QBMenuMainController添加到自己搭建的ViewController中

上代码.... 
override func viewDidLoad() {
super.viewDidLoad()

    // 实例化子视图ViewController,以及标题
    let firstVC = QBFirstViewController()
    let secondVC = QBSecondViewController()
    let thirdVC = QBThirdViewController()
    let fourVC = QBFourthViewController()
    let fiveVC = QBFiveViewController()
    let sixVC = QBSexViewController()
    let sevenVC = QBSevenViewController()

    firstVC.title = "推荐"
    secondVC.title = "新闻"
    thirdVC.title = "科技创新"
    fourVC.title = "人物"
    fiveVC.title = "历史"
    sixVC.title = "军事"
    sevenVC.title = "国内社会"

    // 添加到数组
    let controllersArray = [firstVC,secondVC,thirdVC,fourVC,fiveVC,sixVC,sevenVC]

    // 设置options
    let options: [QBPageMenuOptions]
        = [.MeunViewHeight(44),
           .MenuViewBackgroundColor(UIColor.whiteColor()),
           .MenuItemFont(UIFont.systemFontOfSize(19)),
           .MenuItemNormalColor(UIColor.blackColor()),
           .MenuItemSpace(15.0),
           .MenuItemDefaultIndex(0),
           .MenuIsSelectionIndicator(false),
           .MenuIsRightButton(false),
           .MenuRightButtonWidth(30),
           .MenuRightButtonBackgroundColor(UIColor.lightGrayColor()),
           .AnimationDuration(0.2)]

    // 设置frame
    let rect = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height)

    // 实例化QBMenuMainController
    let menuMainVC: QBMenuMainController
        = QBMenuMainController(viewControllers: controllersArray,
                                         frame: rect,
                               pageMenuOptions: options)

    // 添加到自己的ViewController中
    self.addChildViewController(menuMainVC)
    self.view.addSubview(menuMainVC.view)
    menuMainVC.didMoveToParentViewController(self)
}

转载于:https://www.cnblogs.com/PLA-Artillery/p/5784091.html

如果您想使用SmartRefreshLayout嵌套ScrollView嵌套多个RecyclerView,您需要在外部ScrollView和内部RecyclerView之间添加一个LinearLayout,然后将每个RecyclerView添加到LinearLayout中。接下来,您可以在LinearLayout中通过设置一个NestedScrollingChild来实现嵌套滚动。 以下是代码示例: ``` <androidx.core.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <androidx.recyclerview.widget.RecyclerView android:id="@+id/recycler1" android:layout_width="match_parent" android:layout_height="wrap_content"/> <androidx.recyclerview.widget.RecyclerView android:id="@+id/recycler2" android:layout_width="match_parent" android:layout_height="wrap_content"/> <androidx.recyclerview.widget.RecyclerView android:id="@+id/recycler3" android:layout_width="match_parent" android:layout_height="wrap_content"/> </LinearLayout> </androidx.core.widget.NestedScrollView> ``` 然后在代码中,您需要在RecyclerView上设置NestedScrollingEnabled为false,以防止RecyclerView自己处理滚动事件,而是让NestedScrollView来处理。 ``` recycler1.setNestedScrollingEnabled(false); recycler2.setNestedScrollingEnabled(false); recycler3.setNestedScrollingEnabled(false); ``` 最后,您可以在NestedScrollView上设置SmartRefreshLayout的布局参数,如下所示: ``` <com.scwang.smart.refresh.layout.SmartRefreshLayout android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" app:enableLoadMore="true" app:enableRefresh="true"> <androidx.core.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="wrap_content"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <androidx.recyclerview.widget.RecyclerView android:id="@+id/recycler1" android:layout_width="match_parent" android:layout_height="wrap_content"/> <androidx.recyclerview.widget.RecyclerView android:id="@+id/recycler2" android:layout_width="match_parent" android:layout_height="wrap_content"/> <androidx.recyclerview.widget.RecyclerView android:id="@+id/recycler3" android:layout_width="match_parent" android:layout_height="wrap_content"/> </LinearLayout> </androidx.core.widget.NestedScrollView> </com.scwang.smart.refresh.layout.SmartRefreshLayout> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值