指引列表弹框


产品要求这样的界面,效果的时候,采用UIBezierPath 绘图上下文的方式进行





@interface LCPopView :UIView<UITableViewDataSource,UITableViewDelegate>


@property (nonatomic,strong) UITableView *tableView;

@property (nonatomic,strong) NSArray *titleArray;//列表信息

@property (nonatomic,assign) CGPoint showPoint;  //指针指向


@property (nonatomic,strong) UIButton *handerView;


-(void)show;

-(void)dismiss;

-(void)dismiss:(BOOL)animated;


-(instancetype)initWithFrame:(CGRect)frame WithShowPoint:(CGPoint) point;


@property (nonatomic,copy) void (^selectRowAtIndex)(NSInteger index);


@end



//

//  LCPopView.m

//  LCPopover

//

//  Created by 王伟志 on 16/2/23.

//  Copyright (c) 2016 王伟志. All rights reserved.

//


#import "LCPopView.h"


#define TITLE_FONT [UIFont systemFontOfSize:16]

#define kArrowHeight 10.f

#define SPACE 2.f

#define TOP_SPACE 16.f

#define ROW_HEIGHT 40.f

#define kArrowCurvature 6.f


#define RGB(r, g, b)    [UIColor colorWithRed:(r)/255.f green:(g)/255.f blue:(b)/255.f alpha:1.f]


@interface LCPopView ()




@end



@implementation LCPopView


-(UITableView *)tableView

{

   if (_tableView !=nil) {

       return _tableView;

    }

    

   CGRect rect = self.frame;

    rect.origin.x =SPACE;

    rect.origin.y =SPACE;

    rect.size.width =0;

    rect.size.height =0;

    

    self.tableView = [[UITableViewalloc] initWithFrame:rectstyle:UITableViewStylePlain];

    _tableView.delegate =self;

    _tableView.dataSource =self;

    _tableView.alwaysBounceHorizontal =NO;

    _tableView.alwaysBounceVertical =NO;

    _tableView.showsHorizontalScrollIndicator =NO;

    _tableView.showsVerticalScrollIndicator =NO;

    _tableView.scrollEnabled =NO;

    _tableView.backgroundColor = [UIColorclearColor];

    

    return_tableView;

}


-(instancetype)initWithFrame:(CGRect)frame

{

   self = [superinitWithFrame:frame];

   if (self) {

        self.backgroundColor = [UIColorclearColor];

    }

    return self;

}


-(instancetype)initWithFrame:(CGRect)frame WithShowPoint:(CGPoint)point

{

   self = [superinitWithFrame:frame];

   if (self) {

        self.backgroundColor = [UIColorclearColor];

       self.showPoint = point;

    }

    return self;

}


-(void)drawRect:(CGRect)rect

{

    //设置弹框大小.tableView也设置

    CGRect frame =CGRectZero;

    

    frame.size.height = [self.titleArraycount] * ROW_HEIGHT +SPACE * 2  +kArrowHeight;

    

   for (NSString *titlein self.titleArray)

    {

        //计算字体的宽度

        CGFloat width =  [titlesizeWithAttributes:@{NSFontAttributeName:[UIFontsystemFontOfSize:19]}].width;

       NSLog(@"%f",width);

        frame.size.width =MAX(width, frame.size.width) +9;

    }

    

    frame =CGRectMake(_showPoint.x - frame.size.width,0, frame.size.width, frame.size.height);

    

   self.tableView.frame =CGRectMake(_showPoint.x - frame.size.width +kArrowHeight + SPACE,self.tableView.frame.origin.y +TOP_SPACE, frame.size.width, frame.size.height);

    

    [selfdrawRoundedRectPath:frame];

    [selfaddSubview:self.tableView];

}


- (void)drawRoundedRectPath:(CGRect)frame {


    

   float yMin = CGRectGetMinY(frame) +TOP_SPACE;


   CGPoint arrowPoint = CGPointMake(self.showPoint.x,0);

    

    //绘制弹框

   UIBezierPath * path = [UIBezierPathbezierPathWithRoundedRect:CGRectMake(frame.origin.x +TOP_SPACE, frame.origin.y +TOP_SPACE, frame.size.width, frame.size.height)cornerRadius:10];

    

    //贝塞尔曲线

    [pathmoveToPoint:CGPointMake(self.showPoint.x -kArrowHeight, yMin)];//左上角

    [pathaddCurveToPoint:arrowPoint

                  controlPoint1:CGPointMake(arrowPoint.x -kArrowHeight + kArrowCurvature,TOP_SPACE)

                  controlPoint2:arrowPoint];//actual arrow point

    

    [pathaddCurveToPoint:CGPointMake(arrowPoint.x +kArrowHeight, TOP_SPACE)

                  controlPoint1:arrowPoint

                  controlPoint2:CGPointMake(arrowPoint.x +kArrowHeight - kArrowCurvature,TOP_SPACE)];

    

    

    // 设置填充颜色

   UIColor *fillColor = [UIColorwhiteColor];

    [fillColorset];

    [pathfill];

    

    // 设置画笔颜色

   UIColor *strokeColor = [UIColorwhiteColor];

    [strokeColorset];

    

    //根据我们设置的各个点连线

    [pathstroke];

}


#pragma MARK - 整个屏幕添加动画

-(void)show

{

    self.handerView = [UIButtonbuttonWithType:UIButtonTypeCustom];

    [_handerViewsetFrame:[UIScreenmainScreen].bounds];

    [_handerViewsetBackgroundColor:[UIColorclearColor]];

    [_handerViewaddTarget:selfaction:@selector(dismiss)forControlEvents:UIControlEventTouchUpInside];

    [_handerView addSubview:self];

    UIWindow *window = [UIApplicationsharedApplication].keyWindow;

    

    [windowaddSubview:_handerView];

    

    

   self.alpha =0.f;

    self.transform =CGAffineTransformMakeScale(0.1f,0.1f);

    [UIViewanimateWithDuration:0.2fdelay:0.foptions:UIViewAnimationOptionCurveEaseInOutanimations:^{

        self.transform =CGAffineTransformMakeScale(1.05f,1.05f);

       self.alpha =1.f;

    }completion:^(BOOL finished) {

        [UIViewanimateWithDuration:0.08fdelay:0.foptions:UIViewAnimationOptionCurveEaseInOutanimations:^{

            self.transform =CGAffineTransformIdentity;

        }completion:nil];

    }];

}


-(void)dismiss

{

    [selfdismiss:YES];

}


-(void)dismiss:(BOOL)animate

{

   if (!animate) {

        [_handerViewremoveFromSuperview];

       return;

    }

    

    [UIViewanimateWithDuration:0.3fanimations:^{

        self.transform =CGAffineTransformMakeScale(0.1f,0.1f);

       self.alpha =0.f;

    }completion:^(BOOL finished) {

        [_handerViewremoveFromSuperview];

    }];

    

}


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

    [selfdismiss];

}


#pragma mark - UITableView DataSource

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

   return 1;

}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return [_titleArraycount];

}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

   static NSString *identifier =@"cell";

   UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

   if (cell == nil) {

        cell = [[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:identifier];

    }

    

    cell.backgroundColor = [UIColorclearColor];

//    cell.backgroundView = [[UIView alloc] init];

//    cell.backgroundView.backgroundColor = RGB(255, 255, 255);

    

    cell.textLabel.font = [UIFontfontWithName:@"FZLTXHJW--GB1-0"size:16];

    cell.textLabel.text = [_titleArrayobjectAtIndex:indexPath.row];

    

    if ([[UIDevicecurrentDevice].systemVersionfloatValue] >= 7.0) {

        cell.separatorInset =UIEdgeInsetsMake(0,0, 0, 0);

    }

    

   return cell;

}


#pragma mark - UITableView Delegate


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    [tableView deselectRowAtIndexPath:indexPathanimated:NO];

    if (self.selectRowAtIndex) {

       self.selectRowAtIndex(indexPath.row);

    }

    [selfdismiss:YES];

}



@end



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值