LCMenuView简介

简介

筛选功能在慧驾项目中用的比较多,所以抽取出来,以便简化代码,便于维护

类与方法说明

LCMenuView
菜单标题相关,与此次迭代UI相同,以后根据UI的变更进行修改,提供方法和属性如下:
<pre><code>

  • (id)initWithFrame:(CGRect)frame //
    segmentWidths:(NSArray *)widths // 每个segment的宽度,类型NSNumber
    segmentTitles:(NSArray *)titles // 标题,类型NSString
    popups:(NSArray *)popups // 弹出菜单,类型LCMenuPopupView
    parentView:(UIView *)parent; // menu的parentView

  • (void)setSegmentTitle:(NSString *)title index:(NSInteger)index; // 设置标题

  • (NSString *)segmentTitleAtIndex:(NSInteger)index; // 标题

  • (BOOL)showPopup:(BOOL)show index:(NSInteger)index animate:(BOOL)animate; // 显示或隐藏菜单

  • (void)hideAllPopup:(BOOL)animate; //隐藏所有菜单

@property (nonatomic, weak, readonly) UIView *parent;
@property (nonatomic, strong, readonly) UIView *maskView;

@property (nonatomic, assign, readonly) NSInteger popedIndex; // 当前显示菜单index
</code></pre>

LCMenuPopupView
弹出菜单相关,主要封装了菜单的弹出收起动画,提供方法和属性如下:
<pre><code>
// 初始化方法 arrowBtmCenterX是箭头X轴位置

  • (id)initWithFrame:(CGRect)frame
    ContentView:(UIView *)contentView
    arrowPosition:(CGFloat)arrowBtmCenterX;

@property (nonatomic, strong, readwrite) UIView *contentView;

@property (nonatomic, assign, readonly) CGFloat arrowBtmCenterX;

// 显示或隐藏内容
@property (nonatomic, assign, getter=isShow) BOOL show;

  • (void)show:(BOOL)show animate:(BOOL)animate;
    </code></pre>

使用方法

创建UIView子类,封装弹出菜单的内容,本次封装的是LCMenuContentView
<pre><code>
LCMenuContentView *t0 = [[LCMenuContentView alloc] initWithFrame:CGRectMake(0, 0, 320, 40 * arrayPopInfoMile.count) titles:arrayPopInfoMile selectRow:0];
t0.shopPopViewDelegate = self;
LCMenuPopupView *p0 = [[LCMenuPopupView alloc] initWithFrame:CGRectMake(0, 0, 320, 40 * arrayPopInfoMile.count) ContentView:t0 arrowPosition:53];

NSInteger index = -1;
index = [arrayPopInfoKind indexOfObject:self.stringTitle];
LCMenuContentView *t1 = [[LCMenuContentView alloc] initWithFrame:CGRectMake(0, 0, 320, 40 * arrayPopInfoKind.count) titles:arrayPopInfoKind selectRow:index];
t1.shopPopViewDelegate = self;
LCMenuPopupView *p1 = [[LCMenuPopupView alloc] initWithFrame:CGRectMake(0, 0, 320, 40 * arrayPopInfoKind.count) ContentView:t1 arrowPosition:160];


LCMenuContentView *t2 = [[LCMenuContentView alloc] initWithFrame:CGRectMake(0, 0, 320, 40 * arrayPopInfoComment.count) titles:arrayPopInfoComment selectRow:-1];
t2.shopPopViewDelegate = self;
LCMenuPopupView *p2 = [[LCMenuPopupView alloc] initWithFrame:CGRectMake(0, 0, 320, 40 * arrayPopInfoComment.count) ContentView:t2 arrowPosition:320 - 53];

LCMenuView *view = [[LCMenuView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)
                                       segmentWidths:@[@(106), @(108), @(106)]
                                       segmentTitles:@[arrayPopInfoMile[0], self.stringTitle, @"智能"]
                                              popups:@[p0, p1, p2]
                                          parentView:self.view];
[self.view addSubview:view];

</code></pre>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 14,190评论 4 61
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 174,922评论 25 709
  • 1.scrub Surgeons began to scrub their hands and arms with...
    Mr_Oldman阅读 994评论 0 0
  • 文|南有南风 -1- “姐,我不想当备胎了。”裹着棉袄的楠姐刚把伞放一边,还没来得及坐下,我便吐出这句话。 “挺好...
    南有南风阅读 10,407评论 184 178
  • 从刚开始对部门的感受,跟现在的感受都会不一样。 因为,很多事情经过岁月的磨蚀都会发生变化。人和人之间的感情也是一样...
    大静不静阅读 10,851评论 0 1