forked from coding/Coding-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectTasksView.m
More file actions
executable file
·124 lines (112 loc) · 4.74 KB
/
ProjectTasksView.m
File metadata and controls
executable file
·124 lines (112 loc) · 4.74 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
//
// ProjectTasksView.m
// Coding_iOS
//
// Created by 王 原闯 on 14-8-16.
// Copyright (c) 2014年 Coding. All rights reserved.
//
#import "ProjectTasksView.h"
#import "Coding_NetAPIManager.h"
#import "XTSegmentControl.h"
#import "iCarousel.h"
@interface ProjectTasksView ()<iCarouselDataSource, iCarouselDelegate>
@property (nonatomic, strong) Project *myProject;
@property (nonatomic , copy) ProjectTaskBlock block;
@property (strong, nonatomic) NSMutableDictionary *myProTksDict;
@property (strong, nonatomic) NSMutableArray *myMemberList;
@property (strong, nonatomic) XTSegmentControl *mySegmentControl;
@property (strong, nonatomic) iCarousel *myCarousel;
@end
@implementation ProjectTasksView
- (id)initWithFrame:(CGRect)frame project:(Project *)project block:(ProjectTaskBlock)block defaultIndex:(NSInteger)index{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
_myProject = project;
_block = block;
_myProTksDict = [[NSMutableDictionary alloc] initWithCapacity:1];
_myMemberList = [[NSMutableArray alloc] initWithObjects:[ProjectMember member_All], nil];
//添加myCarousel
self.myCarousel = ({
iCarousel *icarousel = [[iCarousel alloc] initWithFrame:frame];
icarousel.dataSource = self;
icarousel.delegate = self;
icarousel.decelerationRate = 1.0;
icarousel.scrollSpeed = 1.0;
icarousel.type = iCarouselTypeLinear;
icarousel.pagingEnabled = YES;
icarousel.clipsToBounds = YES;
icarousel.bounceDistance = 0.2;
[self addSubview:icarousel];
[icarousel mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self).insets(UIEdgeInsetsMake(kMySegmentControlIcon_Height, 0, 0, 0));
}];
icarousel;
});
__weak typeof(self) weakSelf = self;
[[Coding_NetAPIManager sharedManager] request_ProjectMembersHaveTasks_WithObj:_myProject andBlock:^(NSArray *data, NSError *error) {
if (data) {
[weakSelf.myMemberList addObjectsFromArray:data];
//添加滑块
CGRect segmentFrame = CGRectMake(0, 0, kScreen_Width, kMySegmentControlIcon_Height);
__weak typeof(_myCarousel) weakCarousel = weakSelf.myCarousel;
weakSelf.mySegmentControl = [[XTSegmentControl alloc] initWithFrame:segmentFrame Items:weakSelf.myMemberList selectedBlock:^(NSInteger index) {
[weakCarousel scrollToItemAtIndex:index animated:NO];
}];
[weakSelf addSubview:self.mySegmentControl];
[weakSelf.myCarousel reloadData];
}else{
// 添加一个重新加载的按钮
}
}];
}
return self;
}
- (void)refreshToQueryData{
UIView *currentItemView = self.myCarousel.currentItemView;
if ([currentItemView isKindOfClass:[ProjectTaskListView class]]) {
ProjectTaskListView *listView = (ProjectTaskListView *)currentItemView;
[listView refreshToQueryData];
}
}
- (ProjectMember *)selectedMember{
ProjectMember *curMember = [_myMemberList objectAtIndex:_myCarousel.currentItemIndex];
return curMember;
}
#pragma mark iCarousel M
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel{
return [_myMemberList count];
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view{
ProjectMember *curMember = [_myMemberList objectAtIndex:index];
Tasks *curTasks = [_myProTksDict objectForKey:curMember.user_id];
if (!curTasks) {
curTasks = [Tasks tasksWithPro:_myProject owner:curMember.user queryType:TaskQueryTypeAll];
[_myProTksDict setObject:curTasks forKey:curMember.user_id];
}
ProjectTaskListView *listView = (ProjectTaskListView *)view;
if (listView) {
[listView setTasks:curTasks];
}else{
listView = [[ProjectTaskListView alloc] initWithFrame:carousel.bounds tasks:curTasks block:_block tabBarHeight:0];
}
[listView setSubScrollsToTop:(index == carousel.currentItemIndex)];
return listView;
}
- (void)carouselDidScroll:(iCarousel *)carousel{
if (_mySegmentControl) {
float offset = carousel.scrollOffset;
if (offset > 0) {
[_mySegmentControl moveIndexWithProgress:offset];
}
}
}
- (void)carouselCurrentItemIndexDidChange:(iCarousel *)carousel{
if (_mySegmentControl) {
_mySegmentControl.currentIndex = carousel.currentItemIndex;
}
[carousel.visibleItemViews enumerateObjectsUsingBlock:^(UIView *obj, NSUInteger idx, BOOL *stop) {
[obj setSubScrollsToTop:(obj == carousel.currentItemView)];
}];
}
@end