iOS Segment+页面滑动

作者: Luy7788 | 来源:发表于2016-06-28 02:56 被阅读1340次

Segment+页面滑动

Demo:
github: https://github.com/Luy7788/LySegmentMenu
重新修改了样式:

旧版Demo:

github: https://github.com/Super-lying/LyScrollMenu
code4app下载地址: http://code4app.com/thread-9069-1-1.html

使用方法

/**
 *  初始化方法1
 *  在屏幕内最多显示的标题个数默认为5个
 *
 *  @param frame
 *  @param viewArr      scrollView上要添加的view数组   -> @[VC1.view,VC2.view,VC3.view,VC4.view,VC5.view]
 *  @param titleArr     标题数组    -> @[@"标题1",@"标题2",@"标题3",@"标题4",@"标题5"],
 *  
 */
-(instancetype)initWithFrame:(CGRect)frame ControllerViewArray:(NSArray *)viewArr TitleArray:(NSArray *)titleArr;

/**
 *  初始化方法2
 *  可设置最多显示的标题个数
 *
 *  @param frame
 *  @param viewArr      scrollView上要添加的view数组   -> @[VC1.view,VC2.view,VC3.view,VC4.view,VC5.view]
 *  @param titleArr     标题数组    -> @[@"标题1",@"标题2",@"标题3",@"标题4",@"标题5"]
 *  @param maxNum       在屏幕内最多显示的标题个数
 *
 */
-(instancetype)initWithFrame:(CGRect)frame ControllerViewArray:(NSArray *)viewArr TitleArray:(NSArray *)titleArr MaxShowTitleNum:(NSInteger)maxNum;


/**
 *  代理方法
 *
 *  @param currentView 当前的UIview
 *  @param index       当前view的索引
 */
- (void)LyScrollMenuCurrentView:(UIView *)currentView didSelectItemWithIndex:(NSInteger)index;

简单的例子:直接将多个view和标题添加给LyScrollMenu:

    UIViewController *VC1 = [[UIViewController alloc]init];
    [VC1.view setBackgroundColor:[UIColor redColor]];
    UIViewController *VC2 = [[UIViewController alloc]init];
    [VC2.view setBackgroundColor:[UIColor blueColor]];
    UIViewController *VC3 = [[UIViewController alloc]init];
    [VC3.view setBackgroundColor:[UIColor grayColor]];
    UIViewController *VC4 = [[UIViewController alloc]init];
    [VC4.view setBackgroundColor:[UIColor greenColor]];
    UIViewController *VC5 = [[UIViewController alloc]init];
    [VC5.view setBackgroundColor:[UIColor purpleColor]];
    UIViewController *VC6 = [[UIViewController alloc]init];
    [VC6.view setBackgroundColor:[UIColor lightGrayColor]];
    UIViewController *VC7 = [[UIViewController alloc]init];
    [VC7.view setBackgroundColor:[UIColor yellowColor]];

    CGRect Rect = CGRectMake(0, 20, kSCREEN_WIDTH, kSCREEN_HEIGHT);

    LyScrollMenu *LyMenu = [[LyScrollMenu alloc]initWithFrame:Rect
                                          ControllerViewArray:@[VC1.view,VC2.view,VC3.view,VC4.view,VC5.view,VC6.view,VC7.view]
                                                   TitleArray:@[@"标题1",@"标题2",@"标题3",@"标题4",@"标题5",@"标题6",@"标题7"]
                                              MaxShowTitleNum:5];
    LyMenu.delegate = self;
    [self.view addSubview:LyMenu];

实现的效果


ScreenFlow3.gif

相关文章

网友评论

  • 宇轩Simid:index+1 >= self.maxShowNum/2+1 && index+1 <= self.titleCount - (self.maxShowNum/2+0)
    这句是 changeSelectItemWithIndex: 方法中的,我一直想不明白你这个条件判断是什么意思,以至于我写的东西出现了bug,罪魁祸首就是进入了这个条件,走了scrollRectToVisible:animated: 这个方法,导致HeaderToolScrollBar 直接滚动到该区域,上面的Bar 不见了,很是痛苦,找了一下午终于确定是这个自己滚动方法 的问题。我查阅了任何资料都没人发现这个bug,不过我发现了。你可以这样写个demo: window.rootVC = TabBarVC,TabBarVC -> Navigation -> tablviewController. 你照这个结构做完,然后把你的LysegmentMenu add到上面,记住,需要传三个view和三个title,当你点击第二的时候,奇迹就会发生。因为不知道你 if 里条件的逻辑,所以我没办法修改,暂时只能把他注释掉了。希望您能给出解答。QQ:466270590.谢谢!!!🙏

本文标题:iOS Segment+页面滑动

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