简介
筛选功能在慧驾项目中用的比较多,所以抽取出来,以便简化代码,便于维护
类与方法说明
LCMenuView
菜单标题相关,与此次迭代UI相同,以后根据UI的变更进行修改,提供方法和属性如下:
- (id)initWithFrame:(CGRect)frame //
segmentWidths:(NSArray *)widths // 每个segment的宽度,类型NSNumber
segmentTitles:(NSArray *)titles // 标题,类型NSString
popups:(NSArray *)popups // 弹出菜单,类型LCMenuPopupView
parentView:(UIView *)parent; // menu的parentView
# 简介
筛选功能在慧驾项目中用的比较多,所以抽取出来,以便简化代码,便于维护
# 类与方法说明
LCMenuView
菜单标题相关,与此次迭代UI相同,以后根据UI的变更进行修改,提供方法和属性如下:
- (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
LCMenuPopupView
弹出菜单相关,主要封装了菜单的弹出收起动画,提供方法和属性如下:
// 初始化方法 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;
使用方法
创建UIView子类,封装弹出菜单的内容,本次封装的是LCMenuContentView
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];