RightViewController.m 7.41 KB
Newer Older
曹云霄's avatar
曹云霄 committed
1 2 3 4 5 6 7 8 9
//
//  RightViewController.m
//  Lighting
//
//  Created by 曹云霄 on 16/4/28.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "RightViewController.h"
曹云霄's avatar
曹云霄 committed
10
#import "AppDelegate.h"
11 12
#import "RightControlSectionView.h"
#import "RightControlTableViewCell.h"
13 14 15 16 17





曹云霄's avatar
曹云霄 committed
18 19
@interface RightViewController ()<UITableViewDataSource,UITableViewDelegate>

20 21 22 23 24 25 26 27 28 29 30 31

@property (weak, nonatomic) IBOutlet UITableView *rightTableview;

/**
 *  section数据源
 */
@property (nonatomic,strong) NSArray *dataArray;

/**
 *  客户管理下级菜单
 */
@property (nonatomic,strong) NSArray *subSectionArray;
32 33

/**
34
 *  控制section 闭合开启
35
 */
36
@property (nonatomic,strong) NSMutableArray *sectionClosedArray;
37 38 39 40

/**
 *  图片数组
 */
曹云霄's avatar
曹云霄 committed
41
@property (nonatomic,strong) NSArray *imageArray;
曹云霄's avatar
曹云霄 committed
42

43
/**
44
 *  指示线
45
 */
46 47
@property (nonatomic,strong) UIView *lineView;

曹云霄's avatar
曹云霄 committed
48 49 50 51 52

@end

@implementation RightViewController

曹云霄's avatar
曹云霄 committed
53 54 55 56 57 58 59 60 61
/**
 *  初始化数据源
 *
 *  @return NSArray
 */
- (NSArray *)dataArray
{
    if (_dataArray == nil) {
        
曹云霄's avatar
曹云霄 committed
62
        _dataArray = @[@"体验中心",@"场景库",@"产品库",@"客户管理",@"学习中心",@"关于"];
曹云霄's avatar
曹云霄 committed
63 64 65 66
    }
    return _dataArray;
}

67 68 69
- (NSArray *)subSectionArray
{
    if (!_subSectionArray) {
曹云霄's avatar
曹云霄 committed
70
        _subSectionArray = @[@"",@"",@"",@[@"所有客户",@"客户订单"],@"",@""];
71 72 73
    }
    return _subSectionArray;
}
曹云霄's avatar
曹云霄 committed
74

75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
- (NSMutableArray *)sectionClosedArray
{
    if (!_sectionClosedArray) {
        _sectionClosedArray = [NSMutableArray array];
        //** @0表示闭合,@1表示开启 */
        for (int i=0; i<self.dataArray.count; i++) {
            [_sectionClosedArray addObject:@0];
        }
    }
    return _sectionClosedArray;
}

- (UIView *)lineView
{
    if (!_lineView) {
        _lineView = [[UIView alloc]init];
        _lineView.backgroundColor = kMainBlueColor;
        [self.rightTableview addSubview:_lineView];
    }
    return _lineView;
}
曹云霄's avatar
曹云霄 committed
96 97 98 99 100 101 102 103

/**
 *  图片
 */
- (NSArray *)imageArray
{
    if (_imageArray == nil) {
        
104
        _imageArray = [NSArray arrayWithObjects:@"tiyan",@"changjing",@"chanping",@"kehu",@"Learningcenter",@"guanyu", nil];
曹云霄's avatar
曹云霄 committed
105 106 107 108
    }
    return _imageArray;
}

曹云霄's avatar
曹云霄 committed
109 110 111
- (void)viewDidLoad {
    [super viewDidLoad];
    
曹云霄's avatar
曹云霄 committed
112 113 114 115 116 117 118 119
    [self uiConfigAction];
}

#pragma mark -布局
- (void)uiConfigAction
{
    self.rightTableview.delegate = self;
    self.rightTableview.dataSource = self;
120
    self.rightTableview.tableFooterView = [UIView new];
曹云霄's avatar
曹云霄 committed
121 122
    [self.rightTableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"rightcell"];
    [self createHeaderview];
123
    [self.rightTableview registerClass:[RightControlSectionView class] forHeaderFooterViewReuseIdentifier:@"RightControlSectionView"];
曹云霄's avatar
曹云霄 committed
124 125 126 127 128
}

#pragma mark -头部视图
- (void)createHeaderview
{
129
    UIView *navigationView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, RightWidth, NavigationHeight)];
勾芒's avatar
勾芒 committed
130
    //阴影
131 132 133 134 135 136
    navigationView.layer.shadowColor = [UIColor blackColor].CGColor;
    navigationView.layer.shadowRadius = 4;
    navigationView.layer.shadowOpacity = 0.5;
    navigationView.layer.shadowOffset = CGSizeMake(0,0);
    navigationView.backgroundColor = kMainBlueColor;
    UILabel *label = [[UILabel alloc] initWithFrame:navigationView.frame];
137
    label.text = @"功能菜单";
勾芒's avatar
勾芒 committed
138
    label.font = [UIFont boldSystemFontOfSize:20];
139
    [label setTextColor:[UIColor whiteColor]];
140
    [navigationView addSubview:label];
勾芒's avatar
勾芒 committed
141
    label.textAlignment = NSTextAlignmentCenter;
142 143 144 145
    [self.navigationController.navigationBar addSubview:navigationView];
    //headerView
    UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, RightWidth, 30)];
    self.rightTableview.tableHeaderView = headerView;
曹云霄's avatar
曹云霄 committed
146 147
}

勾芒's avatar
勾芒 committed
148

曹云霄's avatar
曹云霄 committed
149 150
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
151
    RightControlTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RightControlTableViewCell" forIndexPath:indexPath];
曹云霄's avatar
曹云霄 committed
152
    cell.sectionTitle.text = self.subSectionArray[indexPath.section][indexPath.row];
153 154
    return cell;
    
曹云霄's avatar
曹云霄 committed
155 156 157 158
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
159
    BOOL controlClose = [self.sectionClosedArray[section] boolValue];
曹云霄's avatar
曹云霄 committed
160 161 162
    if (section == 3 || section == 4) {
        NSArray *subArray = self.subSectionArray[section];
        return controlClose?subArray.count:0;
163 164
    }
    return 0;
曹云霄's avatar
曹云霄 committed
165
}
曹云霄's avatar
曹云霄 committed
166

曹云霄's avatar
曹云霄 committed
167 168
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
169 170 171
    RightControlTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    CGPoint point = [cell convertPoint:cell.sectionTitle.mj_origin toView:self.rightTableview];
    [self addInstructionsLine:point.y];
曹云霄's avatar
曹云霄 committed
172
    [self closeSidebarAndPassEvents:self.subSectionArray[indexPath.section][indexPath.row]];
曹云霄's avatar
曹云霄 committed
173 174
}

曹云霄's avatar
曹云霄 committed
175 176 177 178
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}
曹云霄's avatar
曹云霄 committed
179

180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    RightControlSectionView *sectionView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"RightControlSectionView"];
    sectionView.sectionTitle.text = [self.dataArray objectAtIndex_opple:section];
    sectionView.sectionImageView.image = TCImage(self.imageArray[section]);
    sectionView.tag = section;
    [sectionView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(sectionClickAction:)]];
    return sectionView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 60;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.dataArray.count;
}
曹云霄's avatar
曹云霄 committed
204

205 206
#pragma mark - section Click
- (void)sectionClickAction:(UITapGestureRecognizer *)sender
曹云霄's avatar
曹云霄 committed
207
{
208
    NSInteger index = sender.view.tag;
曹云霄's avatar
曹云霄 committed
209
    if (index == 3 ) {
210 211 212
        BOOL controlClose = [self.sectionClosedArray[index] boolValue];
        self.sectionClosedArray[index] = controlClose?@0:@1;
        [self.rightTableview reloadSections:[NSIndexSet indexSetWithIndex:index] withRowAnimation:UITableViewRowAnimationFade];
曹云霄's avatar
曹云霄 committed
213
    }else{
214
        self.sectionClosedArray[3] = @0;
曹云霄's avatar
曹云霄 committed
215 216 217
        NSMutableIndexSet *indexSet = [[NSMutableIndexSet alloc]init];
        [indexSet addIndex:3];
        [self.rightTableview reloadSections:indexSet withRowAnimation:UITableViewRowAnimationFade];
218
       [self closeSidebarAndPassEvents:self.dataArray[index]];
曹云霄's avatar
曹云霄 committed
219
    }
220 221 222
    RightControlSectionView *sectionView = (RightControlSectionView *)sender.view;
    CGPoint point = [sender.view convertPoint:sectionView.sectionImageView.mj_origin toView:self.rightTableview];
    [self addInstructionsLine:point.y];
曹云霄's avatar
曹云霄 committed
223 224
}

225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
#pragma mark - 收起侧边栏并传递事件
- (void)closeSidebarAndPassEvents:(NSString *)name
{
    //收起右侧控制器
    [SHARED_APPDELEGATE.mmdrawer toggleDrawerSide:MMDrawerSideRight animated:YES completion:nil];
    if ([self.delegate respondsToSelector:@selector(SelectedControllerWithIndex:)]) {
        [self.delegate SelectedControllerWithIndex:name];
    }
}

#pragma mark - 添加指示线
- (void)addInstructionsLine:(CGFloat)offsetY
{
    WS(weakSelf);
    [UIView animateWithDuration:0.5 delay:0.1f usingSpringWithDamping:0.5f initialSpringVelocity:0.5f options:UIViewAnimationOptionCurveEaseInOut animations:^{
        weakSelf.lineView.frame = CGRectMake(0, offsetY, 10, 25);
    } completion:nil];
}
曹云霄's avatar
曹云霄 committed
243

曹云霄's avatar
曹云霄 committed
244 245 246 247 248 249 250
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end