轻量级弹出视图控件

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

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

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

推荐阅读更多精彩内容