Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
256 lines (207 loc) · 7.87 KB

File metadata and controls

256 lines (207 loc) · 7.87 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
125
126
127
128
129
130
131
132
133
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
//
// CSMyTopicVC.m
// Coding_iOS
//
// Created by pan Shiyu on 15/7/15.
// Copyright (c) 2015年 Coding. All rights reserved.
//
#import "CSMyTopicVC.h"
#import "Login.h"
#import "Coding_NetAPIManager.h"
#import "CSTopiclistView.h"
#import "CSTopicDetailVC.h"
@interface CSMyTopicVC ()
@property (strong, nonatomic) XTSegmentControl *mySegmentControl;
@property (strong, nonatomic) iCarousel *myCarousel;
@property (assign, nonatomic) NSInteger oldSelectedIndex;
@end
@implementation CSMyTopicVC
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
if([self isMe]) {
self.segmentItems = @[@"我关注的", @"我参与的"];
self.title = @"我的话题";
}else {
self.segmentItems = @[@"Ta关注的", @"Ta参与的"];
self.title = @"Ta的话题";
}
_oldSelectedIndex = 0;
//添加myCarousel
_myCarousel = ({
iCarousel *icarousel = [[iCarousel alloc] init];
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.view addSubview:icarousel];
[icarousel mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(kMySegmentControl_Height, 0, 0, 0));
}];
icarousel;
});
//添加滑块
__weak typeof(_myCarousel) weakCarousel = _myCarousel;
_mySegmentControl = [[XTSegmentControl alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, kMySegmentControl_Height) Items:_segmentItems selectedBlock:^(NSInteger index) {
if (index == _oldSelectedIndex) {
return;
}
[weakCarousel scrollToItemAtIndex:index animated:NO];
}];
[self.view addSubview:_mySegmentControl];
_myCarousel.scrollEnabled = YES;
}
- (BOOL)isMe{
if(!_curUser) {
_curUser = [Login curLoginUser];
}
return [_curUser.global_key isEqualToString:[Login curLoginUser].global_key];
}
#pragma mark iCarousel M
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel{
return _segmentItems.count;
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view{
CSTopiclistView *listView = (CSTopiclistView *)view;
if (listView) {
}else{
__weak CSMyTopicVC *weakSelf = self;
CSMyTopicsType type = (index == 0 ? CSMyTopicsTypeWatched : CSMyTopicsTypeJoined);
listView = [[CSTopiclistView alloc] initWithFrame:carousel.bounds globalKey:_curUser.global_key type:type block:^(NSDictionary *topic) {
[weakSelf goToTopic:topic];
}];
listView.isMe = [self isMe];
}
[listView setSubScrollsToTop:(index == carousel.currentItemIndex)];
return listView;
}
- (Projects *)projectsWithIndex:(NSUInteger)index{
return [Projects projectsWithType:index andUser:nil];
}
- (void)carouselDidScroll:(iCarousel *)carousel{
[self.view endEditing:YES];
if (_mySegmentControl) {
float offset = carousel.scrollOffset;
if (offset > 0) {
[_mySegmentControl moveIndexWithProgress:offset];
}
}
}
- (void)carouselCurrentItemIndexDidChange:(iCarousel *)carousel
{
if (_mySegmentControl) {
_mySegmentControl.currentIndex = carousel.currentItemIndex;
}
if (_oldSelectedIndex != carousel.currentItemIndex) {
_oldSelectedIndex = carousel.currentItemIndex;
CSTopiclistView *curView = (CSTopiclistView *)carousel.currentItemView;
[curView refreshToQueryData];
}
[carousel.visibleItemViews enumerateObjectsUsingBlock:^(UIView *obj, NSUInteger idx, BOOL *stop) {
[obj setSubScrollsToTop:(obj == carousel.currentItemView)];
}];
}
#pragma mark -
- (void)goToTopic:(NSDictionary*)topic{
CSTopicDetailVC *vc = [[CSTopicDetailVC alloc] init];
vc.topicID = [topic[@"id"] intValue];
[self.navigationController pushViewController:vc animated:YES];
}
@end
@interface CSMyTopicView ()<iCarouselDataSource, iCarouselDelegate>
@property (strong, nonatomic) XTSegmentControl *mySegmentControl;
@property (strong, nonatomic) iCarousel *myCarousel;
@property (assign, nonatomic) NSInteger oldSelectedIndex;
@property (strong, nonatomic) NSArray *segmentItems;
@end
@implementation CSMyTopicView
- (id)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
self.backgroundColor = [UIColor whiteColor];
self.segmentItems = @[@"我关注的", @"我参与的"];
_oldSelectedIndex = 0;
//添加myCarousel
_myCarousel = ({
iCarousel *icarousel = [[iCarousel alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, 44)];
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;
icarousel.disableGesture = YES;
[self addSubview:icarousel];
[icarousel mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self).insets(UIEdgeInsetsMake(kMySegmentControl_Height, 0, 0, 0));
}];
icarousel;
});
//添加滑块
__weak typeof(_myCarousel) weakCarousel = _myCarousel;
_mySegmentControl = [[XTSegmentControl alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, kMySegmentControl_Height) Items:_segmentItems selectedBlock:^(NSInteger index) {
if (index == _oldSelectedIndex) {
return;
}
[weakCarousel scrollToItemAtIndex:index animated:NO];
}];
[self addSubview:_mySegmentControl];
_myCarousel.scrollEnabled = NO;
return self;
}
#pragma mark iCarousel M
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel{
return _segmentItems.count;
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view{
CSTopiclistView *listView = (CSTopiclistView *)view;
if (listView) {
}else{
__weak CSMyTopicView *weakSelf = self;
CSMyTopicsType type = (index == 0 ? CSMyTopicsTypeWatched : CSMyTopicsTypeJoined);
listView = [[CSTopiclistView alloc] initWithFrame:carousel.bounds globalKey:[Login curLoginUser].global_key type:type block:^(NSDictionary *topic) {
[weakSelf goToTopic:topic];
}];
listView.isMe = YES;
}
[listView setSubScrollsToTop:(index == carousel.currentItemIndex)];
return listView;
}
- (Projects *)projectsWithIndex:(NSUInteger)index{
return [Projects projectsWithType:index andUser:nil];
}
- (void)carouselDidScroll:(iCarousel *)carousel{
[self endEditing:YES];
if (_mySegmentControl) {
float offset = carousel.scrollOffset;
if (offset > 0) {
[_mySegmentControl moveIndexWithProgress:offset];
}
}
}
- (void)carouselCurrentItemIndexDidChange:(iCarousel *)carousel
{
if (_mySegmentControl) {
_mySegmentControl.currentIndex = carousel.currentItemIndex;
}
if (_oldSelectedIndex != carousel.currentItemIndex) {
_oldSelectedIndex = carousel.currentItemIndex;
CSTopiclistView *curView = (CSTopiclistView *)carousel.currentItemView;
[curView refreshToQueryData];
}
[carousel.visibleItemViews enumerateObjectsUsingBlock:^(UIView *obj, NSUInteger idx, BOOL *stop) {
[obj setSubScrollsToTop:(obj == carousel.currentItemView)];
}];
}
#pragma mark -
- (void)goToTopic:(NSDictionary*)topic{
CSTopicDetailVC *vc = [[CSTopicDetailVC alloc] init];
vc.topicID = [topic[@"id"] intValue];
[self.parentVC.navigationController pushViewController:vc animated:YES];
}
@end
Morty Proxy This is a proxified and sanitized view of the page, visit original site.