// // DRTimeLineShareView.m // YouHuiProject // // Created by 小花 on 2019/1/7. // Copyright © 2019年 kuxuan. All rights reserved. // #import "DRTimeLineShareView.h" @interface DRTimeLineShareView () { UIView *_alphaView; UIView *_bgView; } @end @implementation DRTimeLineShareView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.userInteractionEnabled = YES; self.backgroundColor = [UIColor clearColor]; self.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height); _alphaView = [[UIView alloc] initWithFrame:self.bounds]; _alphaView.backgroundColor = [UIColor blackColor]; _alphaView.alpha = 0.0; [self addSubview:_alphaView]; [self sendSubviewToBack:_alphaView]; [_alphaView setAutoresizingMask:UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleHeight]; [self setAutoresizingMask:UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleHeight]; self.autoresizesSubviews = YES ; _alphaView.autoresizesSubviews = YES ; //取消 UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tappedCancel)]; [_alphaView addGestureRecognizer:tapGesture]; UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, self.height, self.width, 174)]; _bgView = bgView; bgView.backgroundColor = [UIColor whiteColor]; [self addSubview:bgView]; NSArray *titles = @[@"分享朋友圈",@"分享给好友",@"保存图片"]; NSArray *icons = @[@"wx_section",@"wx_wechat",@"save_img"]; CGFloat width = SCREEN_WIDTH/3; for (int i = 0; i < titles.count; i++) { UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(width*i, 0, width, 125)]; [button setTitle:titles[i] forState:UIControlStateNormal]; button.titleLabel.font = [UIFont systemFontOfSize:13]; [button setImage:[UIImage imageNamed:icons[i]] forState:UIControlStateNormal]; [button setButtonImageTitleStyle:ButtonImageTitleStyleTop padding:10]; [bgView addSubview:button]; [button setTitleColor:[UIColor YHColorWithHex:0x414141] forState:UIControlStateNormal]; button.tag = 1000+i; [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside]; } UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 125, self.width, 1)]; line.backgroundColor = [UIColor YHColorWithHex:0xE5E4E6]; [bgView addSubview:line]; UIButton *cancel = [[UIButton alloc] initWithFrame:CGRectMake(0, 125, self.width, 48)]; [cancel setTitle:@"取消" forState:UIControlStateNormal]; [cancel addTarget:self action:@selector(tappedCancel) forControlEvents:UIControlEventTouchUpInside]; cancel.titleLabel.font = [UIFont systemFontOfSize:15]; [cancel setTitleColor:[UIColor YHColorWithHex:0x9B9B9B] forState:UIControlStateNormal]; [bgView addSubview:cancel]; } return self; } - (void)buttonClick:(UIButton *)sender { NSInteger index = sender.tag - 1000; if (self.delegate && [self.delegate respondsToSelector:@selector(timelineShareViewDidSeledtedIndex:model:indexPath:)]) { [self.delegate timelineShareViewDidSeledtedIndex:index model:self.model indexPath:self.indexPath]; } } -(void)showInView:(UIView *)view { [view addSubview:self]; [UIView animateWithDuration:0.25 animations:^{ _alphaView.alpha = 0.5; [_bgView setFrame:CGRectMake(0, self.height-_bgView.height, self.width, _bgView.height)]; }]; } -(void)tappedCancel { [UIView animateWithDuration:0.25 animations:^{ _alphaView.alpha = 0; [_bgView setFrame:CGRectMake(0, self.height, self.width, _bgView.height)]; } completion:^(BOOL finished) { [self removeFromSuperview]; }]; } @end