iOS Developer

轻量级弹出视图控件

2017-08-29  本文已影响120人  黑炭长

最近做了一个需求是点击按钮弹出下拉选项框,在这里记录一下封装过程,使用简单,只需

ws.managerObject = [[XFKFSUtilitiPopSelectItemsView alloc] initWithSelectArr:ws.selectTitleArray];
ws.managerObject.delegate = ws;
[ws.managerObject presenFromeSelectView:sender];

然后实现

- (void)selectWithIndext:(NSInteger)index{

    //do something
}

- (void)curentViewDidDismiss{

    self.managerObject = nil;
    
}

效果图

屏幕快照 2017-08-29 下午5.51.16.png

在这里把头文件展示出来

@protocol CWCUtilitiPopSelectItemsViewSelectDelegate <NSObject>

@optional
/**
 选择item的回调

 @param index 标记位
 */
- (void)selectWithIndext:(NSInteger)index;

/**
 视图移除后的回调
 */
- (void)curentViewDidDismiss;
@end

typedef NS_ENUM(NSInteger, CWCPopType)
{
    CWCType_Left,
    CWCType_Right,

};

@interface CWCUtilitiPopSelectItemsView : NSObject

/**
 初始化

 @param selectArr 可选数组

 @return 实例
 */
- (instancetype)initWithSelectArr:(NSMutableArray *)selectArr;

/**
 显示视图

 @param selectView 目标视图
 */
- (void)presenFromeSelectView:(UIView *)selectView;

/**
 移除视图
 */
- (void)dismissAction;

/**
 *  代理
 */
@property (nonatomic, weak) id <CWCUtilitiPopSelectItemsViewSelectDelegate> delegate;
/**
 *  视图底图
 */
@property (nonatomic, strong) UIView *managerView;
/**
 *  弹出原始位置
 */
@property (nonatomic, assign) CWCPopType popType;

效果

2017-08-29 17_29_46.gif

Demo地址https://github.com/wenchang1989/CWCPopSelectItemView

上一篇 下一篇

猜你喜欢

热点阅读