手记

QLPageViewController,翻页滚动,类头条滑动,适合做新闻媒体或者订单类的页面

mport "QLPageView.h"

初始化

NSArray *vcs = @[[[TestViewController1 alloc] init],

                    [[TestViewController2 alloc] init],

                    [[TestViewController3 alloc] init],

                    [[TestViewController4 alloc] init],

                    [[TestViewController5 alloc] init],

                    [[TestViewController6 alloc] init]];    NSArray *titles = @[@"第一页", @"第二页", @"3", @"第4444444444页", @"第5页", @"第六页"];    CGFloat y = KIsiPhoneX ? 88 : 64;    //同样的页面跟换数据源的话,直接循环

    QLPageView *toolView = [[QLPageView alloc] initWithFrame:CGRectMake(0, y, self.view.bounds.size.width, self.view.bounds.size.height - y) viewControllers:vcs titles:titles];

    toolView.mDelegate = self;    //下面这几个属性自由选择是赋值

    toolView.itemNormalColor = [UIColor blackColor];

    toolView.itemSelectedColor = [UIColor redColor];

    toolView.hideShadow = NO;

    toolView.selectedIndex = 3;    //这一句必须写

    [toolView showInViewController:self];

遵循代理并实现代理

#pragma mark - QLPageViewDelegate- (void)selectedPageOfIndex:(NSInteger)index{    NSLog(@"selected  %ld", index);

}

效果图

image

不需要居中的话只需要把这里注释掉


image

写的时候分析附图,纠正一下,既然viewWillAppear每次执行,那么肯定比在
scrollowView上面横向加多个viewController这种一次性全部加载的性能要好很多!




作者:墨柒_js
链接:https://www.jianshu.com/p/7b23c068200a


0人推荐
随时随地看视频
慕课网APP