123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- //
- // DrawerView.m
- // smartRhino
- //
- // Created by tederen on 2019/10/21.
- // Copyright © 2019 tederen. All rights reserved.
- //
- #import "DrawerView.h"
- #import "DrawerCell.h"
- #define Xrang [ UIScreen mainScreen ].bounds.size.width/375 //屏幕宽比例
- #define Yrang [ UIScreen mainScreen ].bounds.size.height/667//屏幕高比例
- @interface DrawerView () <UITableViewDataSource, UITableViewDelegate,UIGestureRecognizerDelegate> {
- NSArray *_imageNameArr;
- NSArray *_drawerNameArr;
- }
- @property (nonatomic, strong) UIView *leftBgView;
- @property (nonatomic, strong) UILabel *drawerTitleLab;
- @property (nonatomic, strong) UIView *blueView;
- @property (nonatomic, strong) TDTableView *tableView;
- @end
- @implementation DrawerView
- TDShareInstance_implementation(DrawerView)
- - (instancetype)init{
- self = [super init];
- if (self) {
- self = [[DrawerView alloc]initWithFrame:CGRectMake(0, 0,kGXScreenWidth,kGXScreenHeigh - kStatusBarHeight)];
- [[UIApplication sharedApplication].keyWindow addSubview:self];
- }
- return self;
-
- }
- - (instancetype)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.65];
- [self addSubview:self.leftBgView];
- [self.leftBgView addSubview:self.drawerTitleLab];
- [self.leftBgView addSubview:self.blueView];
- [self.leftBgView addSubview:self.tableView];
-
- CGSize titleSize = [_drawerTitleLab sizeThatFits:CGSizeZero];
- _drawerTitleLab.frame = CGRectMake(32, kNavigationHeight, 275*Xrang - 64, titleSize.height);
- _blueView.frame = CGRectMake(32, kNavigationHeight+titleSize.height+4, 275*Xrang - 64, 3.f);
- _blueView.layer.cornerRadius = 1.5;
- _blueView.layer.masksToBounds = YES;
- _tableView.frame = CGRectMake(0,kNavigationHeight+titleSize.height+4 + 3 + 20, 275*Xrang, kGXScreenHeigh-kNavigationHeight+titleSize.height+4 + 3 + 20);
-
- UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(removeFromSuperview)];
- [self addGestureRecognizer:tapGesture];
- tapGesture.delegate = self;
- [self reloadDrawerData];
- [self.tableView reloadData];
- }
- return self;
- }
- - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
- {
- // 若为UITableViewCellContentView(即点击了tableViewCell),
- if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"]) {
- // cell 不需要响应 父视图的手势,保证didselect 可以正常
- return NO;
- }
- //默认都需要响应
- return YES;
- }
- - (void)reloadDrawerData {
- self.drawerTitleLab.text = [NSString stringWithFormat:@"%@,您好",[AppUserModel sharedAppUserModel].Nick];
- _imageNameArr = @[@[@"bar_home_off", @"bar_work_off", @"bar_chat_off", @"bar_my_off"], @[@"draw_letter", @"draw_notice", @"draw_collect",@"draw_note", @"draw_set"]];
- _drawerNameArr = @[@[@"首页", @"工作", @"信源", @"我的"],@[ @"站内信", @"通知", @"收藏",@"笔记", @"设置"]];
- }
- #pragma mark - UITableViewDataSource && UITableViewDelegate
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return _imageNameArr.count;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return [(NSArray*)_imageNameArr[section] count];
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- return 54.f;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- NSString *cellIdentifier = NSStringFromSelector(_cmd);
- DrawerCell *cell = (DrawerCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
- if (!cell) {
- cell = [[DrawerCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
- }
- [cell loadCellDataWithTitle:_drawerNameArr[indexPath.section][indexPath.row] imageName:_imageNameArr[indexPath.section][indexPath.row]];
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
- if (self.SelectDrawerBlock) {
- self.SelectDrawerBlock(indexPath);
- }
- [self removeFromSuperview];
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
- return 0.0;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
- return 1;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
- if (section == 0) {
- return [[UIView alloc]initWithFrame:CGRectZero];
- }
- UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0,tableView.width,1)];
- view.backgroundColor = UIColorHex(E1E1E1);
- return view;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
- return [[UIView alloc]initWithFrame:CGRectZero];
- }
- #pragma mark - setter
- - (UIView *)leftBgView {
- if (!_leftBgView) {
- _leftBgView = [UIView new];
- _leftBgView.frame = CGRectMake(0, 0, 275*Xrang, kGXScreenHeigh);
- _leftBgView.backgroundColor = [UIColor whiteColor];
- }
- return _leftBgView;
- }
- - (UILabel *)drawerTitleLab {
- if (!_drawerTitleLab) {
- _drawerTitleLab = [UILabel new];
- _drawerTitleLab.textColor = UIColorHex(232323);
- _drawerTitleLab.font = [UIFont systemFontOfSize:18.f];
- }
- return _drawerTitleLab;
- }
- - (UIView *)blueView {
- if (!_blueView) {
- _blueView = [UIView new];
- _blueView.backgroundColor = UIColorHex(336CF9);
- }
- return _blueView;
- }
- - (TDTableView *)tableView {
- if (!_tableView) {
- _tableView = [[TDTableView alloc] init];
- _tableView.dataSource = self;
- _tableView.delegate = self;
- }
- return _tableView;
- }
- @end
|