forked from lovesunstar/STBasic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSTSortOperation.m
More file actions
61 lines (54 loc) · 2.01 KB
/
STSortOperation.m
File metadata and controls
61 lines (54 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//
// STSortOperation.m
// STBasic
//
// Created by SunJiangting on 13-11-2.
// Copyright (c) 2013年 SunJiangting. All rights reserved.
//
#import "STSortOperation.h"
#import "STSortView.h"
@interface STSortOperation()
@property (atomic, assign) BOOL complete;
@end
@implementation STSortOperation
- (instancetype) init {
self = [super init];
if (self) {
id duration = [[NSUserDefaults standardUserDefaults] valueForKey:@"STMoveAnimationDuration"];
self.duration = [duration doubleValue];
}
return self;
}
- (void) main {
void (^completion)(BOOL finished) = ^(BOOL finished) {
self.complete = YES;
};
dispatch_async(dispatch_get_main_queue(), ^{
switch (_operationType) {
case STSortOperationTypeMoveBaseline1:
[self.sortView moveBaseline1ToIndex:_index1 duration:self.duration completion:completion];
break;
case STSortOperationTypeMoveBaseline2:
[self.sortView moveBaseline2ToIndex:_index2 duration:self.duration completion:completion];
break;
case STSortOperationTypeCacheUpElement:
[self.sortView moveElementToCacheAtIndex:_index1 duration:self.duration completion:completion];
break;
case STSortOperationTypeCacheDownElement:
[self.sortView removeElementFromCacheWithDuration:self.duration completion:completion];
break;
case STSortOperationTypeMoveElement:
[self.sortView moveElementAtIndex:_index1 toIndex:_index2 duration:self.duration completion:completion];
break;
case STSortOperationTypeExchangeElement:
[self.sortView exchangeElementAtIndex:_index1 withElementAtIndex:_index2 duration:self.duration completion:completion];
break;
default:
break;
}
});
while (!_complete) {
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate distantFuture]];
}
}
@end