DWUploadViewController.m 17.9 KB
Newer Older
Han Ruisong's avatar
Han Ruisong committed
1
2
3
4
5
6
#import "DWUploadViewController.h"
#import "DWUploadInfoSetupViewController.h"
#import "DWUploadTableViewCell.h"
#import "MJExtension.h"
#import <MobileCoreServices/MobileCoreServices.h>
#include <AssetsLibrary/AssetsLibrary.h>
Han Ruisong's avatar
Han Ruisong committed
7
#import "DWUploadSessionManager.h"
Han Ruisong's avatar
Han Ruisong committed
8
9
10

static NSString *const uploadsArray =@"uploadsArray";

Han Ruisong's avatar
Han Ruisong committed
11
@interface DWUploadViewController () <UITableViewDataSource, UITableViewDelegate,DWUploadSessionManagerDelegate>
Han Ruisong's avatar
Han Ruisong committed
12
13
14

@property(strong, nonatomic)NSString *videoPath;

Han Ruisong's avatar
Han Ruisong committed
15
16
@property(nonatomic,assign)NSInteger index;
@property(nonatomic,strong)UIButton * totolButton;
Han Ruisong's avatar
Han Ruisong committed
17

Han Ruisong's avatar
Han Ruisong committed
18
@property(strong, nonatomic)UITableView *tableView;
Han Ruisong's avatar
Han Ruisong committed
19

Han Ruisong's avatar
Han Ruisong committed
20
@property(nonatomic,weak)DWUploadSessionManager * manager;
Han Ruisong's avatar
Han Ruisong committed
21

Han Ruisong's avatar
Han Ruisong committed
22
@property(nonatomic,strong)NSArray * uploadList;
Han Ruisong's avatar
Han Ruisong committed
23

Han Ruisong's avatar
Han Ruisong committed
24
@property(nonatomic,strong)HDReachability * reachability; //网络状态监听
Han Ruisong's avatar
Han Ruisong committed
25
26
27
28
29
30
31
32
33
34
35
36

@end

@implementation DWUploadViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    //** !! **
    //温馨提示:演示账号没有开通上传视频的权限,如需测试上传功能,请填写自己的账号信息
    
Han Ruisong's avatar
Han Ruisong committed
37
38
    self.manager = [DWUploadSessionManager manager];
    self.manager.delegate = self;
Han Ruisong's avatar
Han Ruisong committed
39
    
Han Ruisong's avatar
Han Ruisong committed
40
    self.index = 0;
Han Ruisong's avatar
Han Ruisong committed
41
42
43
    
    [self initUI];
    
Han Ruisong's avatar
Han Ruisong committed
44
45
46
    [self setUploadingList];

    //增加网络状态监听
Han Ruisong's avatar
Han Ruisong committed
47
    self.reachability = [HDReachability reachabilityForInternetConnection];
Han Ruisong's avatar
Han Ruisong committed
48
    [self.reachability startNotifier];
Han Ruisong's avatar
Han Ruisong committed
49
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkStateChange) name:kHDReachabilityChangedNotification object:nil];
Han Ruisong's avatar
Han Ruisong committed
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
}

-(void)setUploadingList
{
    NSMutableArray * array = [NSMutableArray array];
    for (DWUploadModel * uploadModel in self.manager.uploadModelList) {
        if (uploadModel.state != DWUploadStateFinish) {
            [array addObject:uploadModel];
        }
    }

    self.uploadList = array;
    [self.tableView reloadData];
    
    if (self.uploadList.count == 0) {
        self.totolButton.hidden = YES;
    }else{
        self.totolButton.hidden = NO;
    }
}

-(void)setFinishUploadList
{
    NSMutableArray * array = [NSMutableArray array];
    for (DWUploadModel * uploadModel in self.manager.uploadModelList) {
        if (uploadModel.state == DWUploadStateFinish) {
            [array addObject:uploadModel];
        }
    }
    
    self.uploadList = array;
    [self.tableView reloadData];
    
    self.totolButton.hidden = YES;
}

-(void)suspendOrResumeUploadWithNetwork:(BOOL)reachable
{
    if (reachable) {
        //网络恢复
        for (DWUploadModel * uploadModel in self.manager.uploadModelList) {
            if (uploadModel.state == DWUploadStatePause) {
                if ([uploadModel.otherInfo objectForKey:@"NetworkFailure"] && [[uploadModel.otherInfo objectForKey:@"NetworkFailure"] boolValue]) {
                    [self.manager resumeWithUploadModel:uploadModel];
                    NSMutableDictionary * otherInfo = [uploadModel.otherInfo mutableCopy];
                    [otherInfo removeObjectForKey:@"NetworkFailure"];
                    uploadModel.otherInfo = otherInfo;
                }
            }
        }
    }else{
        //网络故障
        for (DWUploadModel * uploadModel in self.manager.uploadModelList) {
            if (uploadModel.state == DWUploadStateUploading) {
                [self.manager suspendWithUploadModel:uploadModel];
                NSMutableDictionary * otherInfo = [uploadModel.otherInfo mutableCopy];
                [otherInfo setValue:@YES forKey:@"NetworkFailure"];
                uploadModel.otherInfo = otherInfo;
            }
        }
    }
Han Ruisong's avatar
Han Ruisong committed
111
112
}

Han Ruisong's avatar
Han Ruisong committed
113
-(void)dealloc
Han Ruisong's avatar
Han Ruisong committed
114
{
Han Ruisong's avatar
Han Ruisong committed
115
    [self.reachability stopNotifier];
Han Ruisong's avatar
Han Ruisong committed
116
    [[NSNotificationCenter defaultCenter] removeObserver:self name:kHDReachabilityChangedNotification object:nil];
Han Ruisong's avatar
Han Ruisong committed
117
    NSLog(@"DWUploadViewController dealloc");
Han Ruisong's avatar
Han Ruisong committed
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

#pragma mark - action
- (void)addButtonAction
{
    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"选择"
                                        delegate:self
                               cancelButtonTitle:nil
                          destructiveButtonTitle:@"取消"
                               otherButtonTitles:@"从相册选择", nil];
Han Ruisong's avatar
Han Ruisong committed
133
    sheet.actionSheetStyle = UIActionSheetStyleAutomatic;
Han Ruisong's avatar
Han Ruisong committed
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
    [sheet showInView:self.view];
}

-(void)selectButtonAction:(UIButton *)button
{
    if (button.selected) {
        return;
    }
    
    button.selected = !button.selected;
    UIView * lineView = [button viewWithTag:button.tag + 100];
    lineView.hidden = NO;
    
    UIButton * frontButton = (UIButton *)[self.view viewWithTag:100 + self.index];
    frontButton.selected = NO;
    UIView * frontLineView = [frontButton viewWithTag:frontButton.tag + 100];
    frontLineView.hidden = YES;
    
    self.index = button.tag - 100;
    
    if (self.index == 0) {
        
        [_tableView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(@(-70));
        }];
        
Han Ruisong's avatar
Han Ruisong committed
160
161
        [self setUploadingList];

Han Ruisong's avatar
Han Ruisong committed
162
163
164
165
166
167
    }else{
        
        [_tableView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(@0);
        }];
        
Han Ruisong's avatar
Han Ruisong committed
168
        [self setFinishUploadList];
Han Ruisong's avatar
Han Ruisong committed
169
170
171
172
173
174
    }
    
}

-(void)totolButtonButton
{
Han Ruisong's avatar
Han Ruisong committed
175
    if (self.uploadList.count == 0) {
Han Ruisong's avatar
Han Ruisong committed
176
177
178
        return;
    }
    self.totolButton.selected = !self.totolButton.selected;
Han Ruisong's avatar
Han Ruisong committed
179

Han Ruisong's avatar
Han Ruisong committed
180
    if (self.totolButton.selected) {
Han Ruisong's avatar
Han Ruisong committed
181
182
183
184
        //暂停
        for (DWUploadModel * uploadModel in self.uploadList) {
            if (uploadModel.state == DWUploadStateUploading) {
                [self.manager suspendWithUploadModel:uploadModel];
Han Ruisong's avatar
Han Ruisong committed
185
186
187
            }
        }
    }else{
Han Ruisong's avatar
Han Ruisong committed
188
189
190
191
        //开始
        for (DWUploadModel * uploadModel in self.uploadList) {
            if (uploadModel.state == DWUploadStatePause || uploadModel.state == DWUploadStateNone) {
                [self.manager resumeWithUploadModel:uploadModel];
Han Ruisong's avatar
Han Ruisong committed
192
193
194
195
            }
        }
    }
    
Han Ruisong's avatar
Han Ruisong committed
196
197
198
199
200
    [self setUploadingList];
}

-(void)networkStateChange
{
Han Ruisong's avatar
Han Ruisong committed
201
    HDNetworkStatus status = [self.reachability currentReachabilityStatus];
Han Ruisong's avatar
Han Ruisong committed
202
    switch (status) {
Han Ruisong's avatar
Han Ruisong committed
203
        case HDNotReachable:{
Han Ruisong's avatar
Han Ruisong committed
204
205
206
207
            //暂无网络
            [self suspendOrResumeUploadWithNetwork:NO];
            break;
        }
Han Ruisong's avatar
Han Ruisong committed
208
        case HDReachableViaWiFi:{
Han Ruisong's avatar
Han Ruisong committed
209
210
211
            [self suspendOrResumeUploadWithNetwork:YES];
            break;
        }
Han Ruisong's avatar
Han Ruisong committed
212
        case HDReachableViaWWAN:{
Han Ruisong's avatar
Han Ruisong committed
213
214
215
216
217
218
            [self suspendOrResumeUploadWithNetwork:YES];
            break;
        }
        default:
            break;
    }
Han Ruisong's avatar
Han Ruisong committed
219
220
221
222
223
}

#pragma mark - UIActionSheetDelegate
-(void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
Han Ruisong's avatar
Han Ruisong committed
224
    if (buttonIndex <= 0) {
Han Ruisong's avatar
Han Ruisong committed
225
226
227
        return;
    }
    
Han Ruisong's avatar
Han Ruisong committed
228
229
    [self dismissViewControllerAnimated:YES completion:nil];
        
Han Ruisong's avatar
Han Ruisong committed
230
231
    DWVideoCompressController *imagePicker = [[DWVideoCompressController alloc] initWithQuality: DWUIImagePickerControllerQualityTypeMedium andSourceType:DWUIImagePickerControllerSourceTypePhotoLibrary andMediaType:DWUIImagePickerControllerMediaTypeMovie];
    imagePicker.delegate = self;
Han Ruisong's avatar
Han Ruisong committed
232
    [self presentViewController:imagePicker animated:YES completion:nil];
Han Ruisong's avatar
Han Ruisong committed
233
234
235
236
237
238
239
240
241
242
}

#pragma mark - UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
    if (![mediaType isEqualToString:(NSString *)kUTTypeMovie]) {
        [@"请选择视频文件" showAlert];
        return;
    }
Han Ruisong's avatar
Han Ruisong committed
243

Han Ruisong's avatar
Han Ruisong committed
244
    NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
Han Ruisong's avatar
Han Ruisong committed
245
246
247
248
249
250
251
252
253
254
    //注意!获取到上传路径之后,请务必调用moveToLocalWithVideoPath:方法获取SDK所需的视频url,否则可能会出现上传失败,找不到视频文件等情况。
    self.videoPath = [self.manager moveToLocalWithVideoPath:[videoURL path]];
    
    if (!self.videoPath) {
        [@"上传视频保存失败,请重试" showAlert];
        [picker dismissViewControllerAnimated:NO completion:nil];
        return;
    }
    
    NSLog(@"imagePickerController videoPath:%@",self.videoPath);
Han Ruisong's avatar
Han Ruisong committed
255
256
257
258
259
260
261
    
    // 跳转到 设置视频标题、标签、简介等信息界面。
    DWUploadInfoSetupViewController *viewController = [[DWUploadInfoSetupViewController alloc] init];
    
    //开始上传
    WeakSelf(self);
    [viewController didBackBlock:^(BOOL isCancel, NSString *userId, NSString *apiKey, NSString *videoTitle, NSString *videoTag, NSString *videoDescription) {
Han Ruisong's avatar
Han Ruisong committed
262
     
Han Ruisong's avatar
Han Ruisong committed
263
        if (!isCancel) {
Han Ruisong's avatar
Han Ruisong committed
264
            DWUploadModel * uploadModel = [DWUploadSessionManager createUploadModelWithUserId:userId Apikey:apiKey VideoTitle:videoTitle VideoDescription:videoDescription VideoTag:videoTag VideoPath:weakself.videoPath CategoryId:nil NotifyURL:nil];
Han Ruisong's avatar
Han Ruisong committed
265

Han Ruisong's avatar
Han Ruisong committed
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
            UIImage * image = [DWTools getThumbnailImage:self.videoPath time:0];
            if (image) {
                uploadModel.otherInfo = @{@"image":UIImagePNGRepresentation(image)};
            }
            
            //添加视频水印,根据自己需求调用即可。
//            [self.manager insertWaterMarkWithUploadModel:uploadModel Text:@"测试水印" Corner:@0 OffsetX:@5 OffsetY:@5 FontFamily:@0 FontSize:@20 FontColor:@"FF00FF" FontAlpha:@100];
            
            //开始上传
            [self.manager startWithUploadModel:uploadModel];
            
            if (self.index == 0) {
                [self setUploadingList];
            }else{
                [self setFinishUploadList];
            }
Han Ruisong's avatar
Han Ruisong committed
282
        }
Han Ruisong's avatar
Han Ruisong committed
283
    
Han Ruisong's avatar
Han Ruisong committed
284
285
286
287
288
289
290
291
292
293
294
    }];
    
    [self.navigationController pushViewController:viewController animated:NO];
    [picker dismissViewControllerAnimated:NO completion:nil];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
	[self dismissViewControllerAnimated:NO completion:nil];
}

Han Ruisong's avatar
Han Ruisong committed
295
296
297
#pragma mark - DWUploadSessionManagerDelegate
//开始上传
-(void)uploadSessionManagerBeginWithUploadModel:(DWUploadModel *)uploadModel
Han Ruisong's avatar
Han Ruisong committed
298
{
Han Ruisong's avatar
Han Ruisong committed
299
    NSLog(@"uploadSessionManagerBeginWithUploadModel videoId:%@",uploadModel.videoId);
Han Ruisong's avatar
Han Ruisong committed
300
301
}

Han Ruisong's avatar
Han Ruisong committed
302
303
//更新上传状态
-(void)uploadSessionManagerUploadModel:(DWUploadModel *)uploadModel WithState:(DWUploadState)state
Han Ruisong's avatar
Han Ruisong committed
304
{
Han Ruisong's avatar
Han Ruisong committed
305
306
307
308
309
310
311
312
    NSLog(@"uploadSessionManagerUploadModel state:%ld",state);
    if (state == DWUploadStateFinish) {
        //完成
        if (self.index == 0) {
            [self setUploadingList];
        }else{
            [self setFinishUploadList];
        }
Han Ruisong's avatar
Han Ruisong committed
313
    }else{
Han Ruisong's avatar
Han Ruisong committed
314
315
316
        NSInteger row = [self.uploadList indexOfObject:uploadModel];
        DWUploadTableViewCell * cell = (DWUploadTableViewCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:0]];
        cell.uploadModel = uploadModel;
Han Ruisong's avatar
Han Ruisong committed
317
318
319
    }
}

Han Ruisong's avatar
Han Ruisong committed
320
321
//更新上传进度
-(void)uploadSessionManagerUploadModel:(DWUploadModel *)uploadModel totalBytesSent:(int64_t)totalBytesSent WithExpectedToSend:(int64_t)expectedToSend
Han Ruisong's avatar
Han Ruisong committed
322
{
Han Ruisong's avatar
Han Ruisong committed
323
324
325
326
    @autoreleasepool {
        NSInteger row = [self.uploadList indexOfObject:uploadModel];
        DWUploadTableViewCell * cell = (DWUploadTableViewCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:0]];
        [cell updateCellTotalBytesSent:totalBytesSent WithExpectedToSend:expectedToSend];
Han Ruisong's avatar
Han Ruisong committed
327
    }
Han Ruisong's avatar
Han Ruisong committed
328
    
Han Ruisong's avatar
Han Ruisong committed
329
//    NSLog(@"上传进度 totalBytesSent:%lld  expectedToSend:%lld progress:%lf",totalBytesSent,expectedToSend,uploadModel.progress);
Han Ruisong's avatar
Han Ruisong committed
330
331
}

Han Ruisong's avatar
Han Ruisong committed
332
333
//上传失败回调
-(void)uploadSessionManagerUploadModel:(DWUploadModel *)uploadModel WithError:(NSError *)error
Han Ruisong's avatar
Han Ruisong committed
334
{
Han Ruisong's avatar
Han Ruisong committed
335
336
337
338
339
    [error.localizedDescription showAlert];
    if (self.index == 0) {
        [self setUploadingList];
    }else{
        [self setFinishUploadList];
Han Ruisong's avatar
Han Ruisong committed
340
341
342
    }
}

Han Ruisong's avatar
Han Ruisong committed
343
-(void)uploadBackgroundSessionCompletion
Han Ruisong's avatar
Han Ruisong committed
344
{
Han Ruisong's avatar
Han Ruisong committed
345
    NSLog(@"uploadBackgroundSessionCompletion");
Han Ruisong's avatar
Han Ruisong committed
346
347
348
349
350
}

#pragma mark - UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
Han Ruisong's avatar
Han Ruisong committed
351
    return self.uploadList.count;
Han Ruisong's avatar
Han Ruisong committed
352
353
354
355
356
357
358
359
360
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    DWUploadTableViewCell * cell = (DWUploadTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[DWUploadTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    
Han Ruisong's avatar
Han Ruisong committed
361
    cell.uploadModel = [self.uploadList objectAtIndex:indexPath.row];
Han Ruisong's avatar
Han Ruisong committed
362
363
364
365
366
367
368
369

    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

Han Ruisong's avatar
Han Ruisong committed
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
    DWUploadModel * uploadModel = [self.uploadList objectAtIndex:indexPath.row];
    switch (uploadModel.state) {
        case DWUploadStateUploading:
            [self.manager suspendWithUploadModel:uploadModel];
            break;
        case DWUploadStateReadying:
            [self.manager suspendWithUploadModel:uploadModel];
            break;
        case DWUploadStatePause:
            [self.manager resumeWithUploadModel:uploadModel];
            if ([uploadModel.otherInfo objectForKey:@"NetworkFailure"] && [[uploadModel.otherInfo objectForKey:@"NetworkFailure"] boolValue]) {
                //判断是否是因为网络故障原因造成的暂停
                NSMutableDictionary * otherInfo = [uploadModel.otherInfo mutableCopy];
                [otherInfo removeObjectForKey:@"NetworkFailure"];
                uploadModel.otherInfo = otherInfo;
            }
            break;
        case DWUploadStateNone:
            [@"请调用startWithUploadModel:方法" showAlert];
            break;
        case DWUploadStateFail:
            [@"上传失败,请重试" showAlert];
            break;
        case DWUploadStateFinish:
            [@"上传已完成" showAlert];
            break;
        default:
Han Ruisong's avatar
Han Ruisong committed
397
398
            break;
    }
Han Ruisong's avatar
Han Ruisong committed
399

Han Ruisong's avatar
Han Ruisong committed
400
401
402
403
404
405
406
407
408
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
Han Ruisong's avatar
Han Ruisong committed
409
410
411
412
413
414
415
    DWUploadModel * uploadModel = [self.uploadList objectAtIndex:indexPath.row];
    [self.manager deleteWithUploadModel:uploadModel];
    
    if (self.index == 0) {
        [self setUploadingList];
    }else{
        [self setFinishUploadList];
Han Ruisong's avatar
Han Ruisong committed
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
    }
}

#pragma mark - init
-(void)initUI
{
    self.title = @"上传管理";
    
    UIButton * addButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [addButton setImage:[UIImage imageNamed:@"icon_upload.png"] forState:UIControlStateNormal];
    addButton.frame = CGRectMake(0, 0, 40, 40);
    [addButton addTarget:self action:@selector(addButtonAction) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * addItem = [[UIBarButtonItem alloc]initWithCustomView:addButton];
    self.navigationItem.rightBarButtonItem = addItem;
    
    NSArray * titles = @[@"上传中",@"已完成"];
    for (int i = 0; i < titles.count; i++) {
        UIButton * selectButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [selectButton setTitle:[titles objectAtIndex:i] forState:UIControlStateNormal];
        [selectButton setTitleColor:TitleColor_102 forState:UIControlStateNormal];
        [selectButton setTitleColor:[UIColor colorWithRed:255/255.0 green:146/255.0 blue:10/255.0 alpha:1.0] forState:UIControlStateSelected];
        selectButton.titleLabel.font = TitleFont(14);
        selectButton.titleLabel.textAlignment = NSTextAlignmentCenter;
        selectButton.tag = 100 + i;
        [selectButton addTarget:self action:@selector(selectButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:selectButton];
        [selectButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@(ScreenWidth / 2.0 * i));
            make.top.equalTo(@0);
            make.width.equalTo(@(ScreenWidth / 2.0));
            make.height.equalTo(@39);
        }];
        
        UIView * lineView = [[UIView alloc]init];
        lineView.backgroundColor = [UIColor colorWithRed:255/255.0 green:146/255.0 blue:10/255.0 alpha:1.0];
        lineView.tag = 200 + i;
        lineView.hidden = YES;
        [selectButton addSubview:lineView];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(@0);
            make.height.equalTo(@2);
            make.width.equalTo(@30);
            make.centerX.equalTo(selectButton);
        }];
        
        if (self.index == i) {
            selectButton.selected = YES;
            lineView.hidden = NO;
        }
    }
    
    self.tableView = [[UITableView alloc]init];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.rowHeight = 87;
Han Ruisong's avatar
Han Ruisong committed
471
472

    self.tableView.backgroundColor = self.view.backgroundColor;
Han Ruisong's avatar
Han Ruisong committed
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(@0);
        make.top.equalTo(@39);
        make.bottom.equalTo(@(-115));
    }];
    
    self.totolButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.totolButton setTitle:@"全部暂停" forState:UIControlStateNormal];
    [self.totolButton setTitle:@"全部开始" forState:UIControlStateSelected];
    [self.totolButton setTitleColor:[UIColor colorWithRed:255/255.0 green:146/255.0 blue:10/255.0 alpha:1.0] forState:UIControlStateNormal];
    self.totolButton.titleLabel.font = TitleFont(15);
    self.totolButton.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.totolButton.layer.borderWidth = 1;
    self.totolButton.layer.borderColor = [UIColor colorWithRed:255/255.0 green:146/255.0 blue:10/255.0 alpha:1.0].CGColor;
    self.totolButton.layer.cornerRadius = 20;
    [self.totolButton addTarget:self action:@selector(totolButtonButton) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.totolButton];
    [_totolButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.width.equalTo(@145);
        make.height.equalTo(@40);
        make.top.equalTo(self.tableView.mas_bottom).offset(15);
    }];
    
    self.totolButton.hidden = NO;
}


@end