需求:多页面切换
网上有很多框架都号称最牛X,但有些居然用scrollView去写我也是醉了,还辣么多star …… 看到这里我就不能忍了,
而且,很多框架定制化都太高了,我现在也遇到了这个问题,之前顶部按钮上面只有按钮,但这次每个item右上角都有可能出现小红点 。。。
就一个这需求我需要改动很多,所以这次写的时候我开发了所有实现UI的方法,以下是实现逻辑
普通的控制器,内包含了 PageViewController,创建此控制器必须要实现 EnumPageControllerDelegate 协议中的两个方法,
用来注册顶部item,因为前面我也提到,框架要确保item样式可自定义创建的
EnumPageController 提供了三种类型的top栏,TopBlind、TopNaviBar、TopSashWindow,其中 TopNaviBar 放在 naviBar
中,作为titleView展示给客户,TopBlind和TopSashWindow的区别在于,如果传入的控制器中有ScrolleView或者TableView的话TopSashWindow类型
将会使得TopSegmentEnumView跟随用户手滑隐藏或显示,注意:选择TopSashWindow的前提是,控制器中的tableview或scrolleView是通过添加自动
约束添加的,FastConstraints 类将很好的帮助添加约束
EnumPageController的顶部栏,内部含有 collectionView,item
这个类是专门给各位客官打的样,可以直接用,也可以自己建一个符合自身需求的顶部样式,作为代理传入PageViewController中,运行起来
TopEnumCollectionCell 是我默认实现的顶部cell样式,TopSegmentConfigModel可以更改关于顶部item间距
以及item显示title等参数的对象
pod 'PageSegment'
NSMutableArray <UIViewController *>*controllers = [NSMutableArray array];
for (NSUInteger i = 0; i < 3; i ++) {
UIViewController *controller = [[UIViewController alloc] init];
controller.title = [NSString stringWithFormat:@"第%ld个",(long)i+1];
controller.view.backgroundColor = randomColor;
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 50, 100, 30)];
label.text = controller.title;
[controller.view addSubview:label];
[controllers addObject:controller];
}
// 2.实现 EnumPageController init方法且传入实现了 EnumPageControllerDelegate 的对象
// 提供默认 PageSwitchAgent 对象,陛下可以观察 PageSwitchAgent 中实现的方式自定义对象传入也可 ^_^
EnumPageController *controller = [[EnumPageController alloc] initWithControllers:controllers autoStyle:[[PageSwitchAgent alloc] init] showTopViewType:TopSashWindow];
[self.navigationController pushViewController:controller animated:YES];