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
8
#import "DWUploadSessionManager.h"
#import "Reachability.h"
Han Ruisong's avatar
Han Ruisong committed
9
10
11

static NSString *const uploadsArray =@"uploadsArray";

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

@property(strong, nonatomic)NSString *videoPath;

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

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

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

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

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

@end

@implementation DWUploadViewController

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

    //增加网络状态监听
    self.reachability = [Reachability reachabilityForInternetConnection];
    [self.reachability startNotifier];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkStateChange) name:kReachabilityChangedNotification object:nil];
}

-(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
112
113
}

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

- (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
134
    sheet.actionSheetStyle = UIActionSheetStyleAutomatic;
Han Ruisong's avatar
Han Ruisong committed
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
160
    [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
161
162
        [self setUploadingList];

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

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

Han Ruisong's avatar
Han Ruisong committed
181
    if (self.totolButton.selected) {
Han Ruisong's avatar
Han Ruisong committed
182
183
184
185
        //暂停
        for (DWUploadModel * uploadModel in self.uploadList) {
            if (uploadModel.state == DWUploadStateUploading) {
                [self.manager suspendWithUploadModel:uploadModel];
Han Ruisong's avatar
Han Ruisong committed
186
187
188
            }
        }
    }else{
Han Ruisong's avatar
Han Ruisong committed
189
190
191
192
        //开始
        for (DWUploadModel * uploadModel in self.uploadList) {
            if (uploadModel.state == DWUploadStatePause || uploadModel.state == DWUploadStateNone) {
                [self.manager resumeWithUploadModel:uploadModel];
Han Ruisong's avatar
Han Ruisong committed
193
194
195
196
            }
        }
    }
    
Han Ruisong's avatar
Han Ruisong committed
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
    [self setUploadingList];
}

-(void)networkStateChange
{
    NetworkStatus status = [self.reachability currentReachabilityStatus];
    switch (status) {
        case NotReachable:{
            //暂无网络
            [self suspendOrResumeUploadWithNetwork:NO];
            break;
        }
        case ReachableViaWiFi:{
            [self suspendOrResumeUploadWithNetwork:YES];
            break;
        }
        case ReachableViaWWAN:{
            [self suspendOrResumeUploadWithNetwork:YES];
            break;
        }
        default:
            break;
    }
Han Ruisong's avatar
Han Ruisong committed
220
221
222
223
224
}

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

#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
244

Han Ruisong's avatar
Han Ruisong committed
245
    NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
Han Ruisong's avatar
Han Ruisong committed
246
247
248
249
250
251
252
253
254
255
    //注意!获取到上传路径之后,请务必调用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
256
257
258
259
260
261
262
    
    // 跳转到 设置视频标题、标签、简介等信息界面。
    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
263
     
Han Ruisong's avatar
Han Ruisong committed
264
        if (!isCancel) {
Han Ruisong's avatar
Han Ruisong committed
265
            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
266

Han Ruisong's avatar
Han Ruisong committed
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
            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
283
        }
Han Ruisong's avatar
Han Ruisong committed
284
    
Han Ruisong's avatar
Han Ruisong committed
285
286
287
288
289
290
291
292
293
294
295
    }];
    
    [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
296
297
298
#pragma mark - DWUploadSessionManagerDelegate
//开始上传
-(void)uploadSessionManagerBeginWithUploadModel:(DWUploadModel *)uploadModel
Han Ruisong's avatar
Han Ruisong committed
299
{
Han Ruisong's avatar
Han Ruisong committed
300
    NSLog(@"uploadSessionManagerBeginWithUploadModel videoId:%@",uploadModel.videoId);
Han Ruisong's avatar
Han Ruisong committed
301
302
}

Han Ruisong's avatar
Han Ruisong committed
303
304
//更新上传状态
-(void)uploadSessionManagerUploadModel:(DWUploadModel *)uploadModel WithState:(DWUploadState)state
Han Ruisong's avatar
Han Ruisong committed
305
{
Han Ruisong's avatar
Han Ruisong committed
306
307
308
309
310
311
312
313
    NSLog(@"uploadSessionManagerUploadModel state:%ld",state);
    if (state == DWUploadStateFinish) {
        //完成
        if (self.index == 0) {
            [self setUploadingList];
        }else{
            [self setFinishUploadList];
        }
Han Ruisong's avatar
Han Ruisong committed
314
    }else{
Han Ruisong's avatar
Han Ruisong committed
315
316
317
        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
318
319
320
    }
}

Han Ruisong's avatar
Han Ruisong committed
321
322
//更新上传进度
-(void)uploadSessionManagerUploadModel:(DWUploadModel *)uploadModel totalBytesSent:(int64_t)totalBytesSent WithExpectedToSend:(int64_t)expectedToSend
Han Ruisong's avatar
Han Ruisong committed
323
{
Han Ruisong's avatar
Han Ruisong committed
324
325
326
327
    @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
328
    }
Han Ruisong's avatar
Han Ruisong committed
329
    
Han Ruisong's avatar
Han Ruisong committed
330
//    NSLog(@"上传进度 totalBytesSent:%lld  expectedToSend:%lld progress:%lf",totalBytesSent,expectedToSend,uploadModel.progress);
Han Ruisong's avatar
Han Ruisong committed
331
332
}

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

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

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

- (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
362
    cell.uploadModel = [self.uploadList objectAtIndex:indexPath.row];
Han Ruisong's avatar
Han Ruisong committed
363
364
365
366
367
368
369
370

    return cell;
}

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

Han Ruisong's avatar
Han Ruisong committed
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
397
    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
398
399
            break;
    }
Han Ruisong's avatar
Han Ruisong committed
400

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

- (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
410
411
412
413
414
415
416
    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
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
471
    }
}

#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
472
473

    self.tableView.backgroundColor = self.view.backgroundColor;
Han Ruisong's avatar
Han Ruisong committed
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
504
    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