| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- //
- // popMenuView.m
- // popViewDemo
- //
- // Created by GG on 2019/1/15.
- // Copyright © 2019年 Haishenghai intelligence network technology. All rights reserved.
- //
- #import "popMenuView.h"
- #define LeftView 10.0f
- #define TopToView 10.0f
- @interface popMenuView()<UITableViewDataSource,UITableViewDelegate>
- @property (nonatomic,copy) NSArray *selectData;
- @property (nonatomic,copy) void(^action)(NSInteger index);
- @property (nonatomic,copy) NSArray * imagesData;
- @end
- popMenuView * backgroundView;
- UITableView * tableView;
- @implementation popMenuView
- - (instancetype)initWithFrame:(CGRect)frame{
- if (self = [super initWithFrame:frame]) {
-
- }
- return self;
- }
- +(void)addPopTableViewSelectWithFrame:(CGRect)frame selectData:(NSArray *)select images:(NSArray *)leftImage action:(void (^)(NSInteger))action animation:(BOOL)animaton{
- if (backgroundView != nil) {
- [popMenuView hiden];
- }
- UIWindow *win = [[[UIApplication sharedApplication] windows] firstObject];
-
- backgroundView = [[popMenuView alloc] initWithFrame:win.bounds];
- backgroundView.action = action;
- backgroundView.imagesData = leftImage ;
- backgroundView.selectData = select;
- backgroundView.backgroundColor = [UIColor colorWithHue:0
- saturation:0
- brightness:0 alpha:0.1];
- [win addSubview:backgroundView];
-
- // TAB
- tableView = [[UITableView alloc] initWithFrame:CGRectMake( [UIScreen mainScreen].bounds.size.width - 80 , 70.0 - 20.0 * select.count , frame.size.width, 40 * select.count) style:0];
- tableView.dataSource = backgroundView;
- // tableView.transform = CGAffineTransformMakeScale(0.5, 0.5);
- tableView.delegate = backgroundView;
- tableView.layer.cornerRadius = 10.0f;
- // 定点
- tableView.layer.anchorPoint = CGPointMake(1.0, 0);
- tableView.transform =CGAffineTransformMakeScale(0.0001, 0.0001);
-
- tableView.rowHeight = 40;
- [win addSubview:tableView];
-
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapBackgroundClick)];
- [backgroundView addGestureRecognizer:tap];
- backgroundView.action = action;
- backgroundView.selectData = select;
- // tableView.layer.anchorPoint = CGPointMake(100, 64);
-
-
- if (animaton == YES) {
- backgroundView.alpha = 0;
- // tableView.frame = CGRectMake([UIScreen mainScreen].bounds.size.width - 80, 70, frame.size.width, 40 * selectData.count);
- [UIView animateWithDuration:0.3 animations:^{
- backgroundView.alpha = 0.5;
- tableView.transform = CGAffineTransformMakeScale(1.0, 1.0);
-
- }];
- }
-
- }
- +(void)tapBackgroundClick{
- [popMenuView hiden];
- }
- + (void)hiden
- {
- if (backgroundView != nil) {
-
- [UIView animateWithDuration:0.3 animations:^{
- // UIWindow * win = [[[UIApplication sharedApplication] windows] firstObject];
- // tableView.frame = CGRectMake(win.bounds.size.width - 35 , 64, 0, 0);
- tableView.transform = CGAffineTransformMakeScale(0.000001, 0.0001);
- } completion:^(BOOL finished) {
- [backgroundView removeFromSuperview];
- [tableView removeFromSuperview];
- tableView = nil;
- backgroundView = nil;
- }];
- }
-
- }
- //tableviewDatasource
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return _selectData.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *Identifier = @"PellTableViewSelectIdentifier";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Identifier];
- if (cell == nil) {
- cell = [[UITableViewCell alloc] initWithStyle:0 reuseIdentifier:Identifier];
- }
- cell.imageView.image = [UIImage imageNamed:self.imagesData[indexPath.row]];
- cell.textLabel.text = _selectData[indexPath.row];
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if (self.action) {
- self.action(indexPath.row);
- }
- [popMenuView hiden];
- }
- //绘制三角形
- - (void)drawRect:(CGRect)rect {
- // Drawing code
- // 设置背景色
- [[UIColor whiteColor] set];
- //拿到当前视图准备好的画板
-
- CGContextRef context = UIGraphicsGetCurrentContext();
-
- //利用path进行绘制三角形
-
- CGContextBeginPath(context);//标记
- CGFloat location = [UIScreen mainScreen].bounds.size.width;
- CGContextMoveToPoint(context,
- location - LeftView - 10, 70);//设置起点
-
- CGContextAddLineToPoint(context,
- location - 2*LeftView - 10 , 60);
-
- CGContextAddLineToPoint(context,
- location - TopToView * 3 - 10, 70);
-
- CGContextClosePath(context);//路径结束标志,不写默认封闭
-
- [[UIColor whiteColor] setFill]; //设置填充色
-
- [[UIColor whiteColor] setStroke]; //设置边框颜色
-
- CGContextDrawPath(context,
- kCGPathFillStroke);//绘制路径path
-
- }
- @end
|