在点.h文件声明
#import <UIKit/UIKit.h>
typedef void(^chooseUploadPopViewSubmitBlock)(NSInteger index);
@interface chooseUploadPopView : UIView
@property (nonatomic, copy) chooseUploadPopViewSubmitBlock chooseUploadPopViewSubmitBlock;
- (void)show;
- (void)hide;
@end
在.m文件去实现
#import "ZXXE_chooseUploadPopView.h"
#import "IdentityScanPopView.h"
#import "CustomButton.h"
#define kConventionCellImageW 32
@interface chooseUploadPopView ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, weak) UIView *contentView;
@property (nonatomic, weak) UILabel *lbInfotitle;
@property (nonatomic, weak) UIImageView *centerimagV;
@property (nonatomic, weak) UIButton *submitBtn;
@property(nonatomic,assign) NSInteger textSize;
@property(nonatomic,assign) CGFloat contentHight;
@property (nonatomic, strong) UITableView *tableView ;
@property (nonatomic, strong) NSArray *dataArr ;
@end
@implementation chooseUploadPopView
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
self.textSize = 12;
self.contentHight = 180;
self.dataArr = [NSArray arrayWithObjects:@"拍摄",@"从相册中选择",@"取消", nil];
[self setUpView];
}
return self;
}
- (void)setUpView
{
self.backgroundColor = [UIColor clearColor];
self.frame = CGRectMake(0, 0, SCREEN_W, SCREEN_H);
UIView *backGdView = [[UIView alloc] init];
backGdView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.7];
backGdView.frame = self.bounds;
[self addSubview:backGdView];
UIView *contentView = [[UIView alloc] init];
contentView.backgroundColor = [UIColor clearColor];
contentView.frame = CGRectMake(0, SCREEN_H, SCREEN_W, self.contentHight);
[self addSubview:contentView];
self.contentView = contentView;
UIView *toptView = [[UIView alloc] init];
toptView.backgroundColor = [UIColor clearColor];
toptView.frame = CGRectMake(0, 0, SCREEN_W,SCREEN_H - self.contentHight);
[self addSubview:toptView];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick:)];
[toptView addGestureRecognizer:tap];
self.tableView = [[UITableView alloc]initWithFrame:self.frame style:UITableViewStylePlain];
[self.contentView addSubview:self.tableView];
self.tableView.dataSource = self;
self.tableView.delegate = self;
self.tableView.rowHeight = 60;
self.tableView.layer.cornerRadius = 20;
self.tableView.layer.masksToBounds = YES;
self.tableView.scrollEnabled = NO;
self.tableView.separatorStyle = UITableViewCellEditingStyleNone;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.dataArr.count;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
}
cell.textLabel.text = self.dataArr[indexPath.row];
cell.textLabel.textAlignment = NSTextAlignmentCenter ;
cell.textLabel.textColor = [UIColor colorWithHexString:@"#181719"];
cell.textLabel.font = [UIFont fontWithName:PingFangSC_Regular size:16];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UIView * linview = [[UIView alloc ]initWithFrame:CGRectMake(0, 59.5, self.width, 0.5)];
linview.backgroundColor = [UIColor colorWithHexString:@"#EEEEEE"];
[cell.contentView addSubview:linview];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//indexPath 该参数中 存着 分区号 和 行号
NSInteger sectionNum = indexPath.section;
NSInteger rowNum = indexPath.row;
[self selectCellnClick:rowNum];
}
#pragma mark -点击事件
- (void)tapClick:(UIGestureRecognizer *)ges
{
[self hide];
}
- (void)show
{
self.frame = CGRectMake(0, 0, SCREEN_W, SCREEN_H);
self.contentView.frame = CGRectMake(0, SCREEN_H, SCREEN_W, self.contentHight);
[[UIApplication sharedApplication].keyWindow addSubview:self];
[UIView animateWithDuration:0.3 animations:^{
self.contentView.frame = CGRectMake(0, SCREEN_H - self.contentHight, SCREEN_W, self.contentHight);
} completion:^(BOOL finished) {
}];
}
- (void)hide
{
if (self.superview) {
[UIView animateWithDuration:0.3 animations:^{
self.contentView.frame = CGRectMake(0, SCREEN_H, SCREEN_W, self.contentHight);
} completion:^(BOOL finished) {
[self removeFromSuperview];
}];
}
}
#pragma mark -点击事件
- (void)closeBtnClick
{
[self hide];
}
- (void)selectCellnClick:(NSInteger ) index
{
[self hide];
if (self.chooseUploadPopViewSubmitBlock) {
self.chooseUploadPopViewSubmitBlock(index);
}
}
@end
调用方式:
导入头文件
#import "ZXXE_chooseUploadPopView.h"
chooseUploadPopView *popV = [[chooseUploadPopView alloc] init];
__weak typeof(self)weakSelf = self;
popV.chooseUploadPopViewSubmitBlock = ^(NSInteger index) {
if (index==0)
{
//调用
}
else if(index==1)
{
//调用
}
else
{
}
};
[popV show];