GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Coding-iOS/Coding_iOS/Views/CodeBranchTagButton.m at master · coding/Coding-iOS Expand file tree/ Copy pathCodeBranchTagButton.mMore file actions 310 lines (267 loc) · 11.7 KB / Copy pathCodeBranchTagButton.mFile metadata and controls310 lines (267 loc) · 11.7 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 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 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 // // CodeBranchTagButton.m // Coding_iOS // // Created by Ease on 15/1/29. // Copyright (c) 2015年 Coding. All rights reserved. // #define kCellIdentifier_BranchTag @"UITableViewCell" #define kCodeBranchTagButton_NavHeight 44.0 #define kCodeBranchTagButton_ContentHeight (kScreen_Height/2) #define DEGREES_TO_RADIANS(angle) ((angle)/180.0 *M_PI) #import "CodeBranchTagButton.h" #import "Coding_NetAPIManager.h" #import "ODRefreshControl.h" @interface CodeBranchTagButton ()<UITableViewDataSource, UITableViewDelegate> @property (nonatomic, assign) BOOL isShowing; @property (nonatomic, assign) NSInteger segmentIndex; @property (nonatomic, strong) UIView *myTapBackgroundView, *myContentView; @property (nonatomic, strong) UITableView *myTableView; @property (strong, nonatomic) UISegmentedControl *mySegmentedControl; //@property (nonatomic, strong) ODRefreshControl *myRefreshControl; @end @implementation CodeBranchTagButton - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { _isShowing = NO; [self addTarget:self action:@selector(changeShowing) forControlEvents:UIControlEventTouchUpInside]; [self addLineUp:YES andDown:YES andColor:kColorDDD]; } return self; } - (UIView *)showingContainerView{ if (!_showingContainerView) { _showingContainerView = kKeyWindow; } return _showingContainerView; } + (instancetype)buttonWithProject:(Project *)project andTitleStr:(NSString *)titleStr{ CodeBranchTagButton *button = [[CodeBranchTagButton alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, 44.0)]; button.titleStr = titleStr; button.curProject = project; return button; } - (void)dismissShowingList{ if (self.isShowing) { [self changeShowing]; } } - (UIView *)myTapBackgroundView{ if (!_myTapBackgroundView) { _myTapBackgroundView = ({ UIView *view = [[UIView alloc] initWithFrame:kScreen_Bounds]; view.backgroundColor = [UIColor clearColor]; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(changeShowing)]; [view addGestureRecognizer:tap]; view; }); } return _myTapBackgroundView; } - (UIView *)myContentView{ if (!_myContentView) { _myContentView = ({ UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; view.backgroundColor = [UIColor whiteColor]; view; }); } return _myContentView; } - (UITableView *)myTableView{ if (!_myTableView) { _myTableView = ({ UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; tableView.backgroundColor = [UIColor whiteColor]; [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:kCellIdentifier_BranchTag]; tableView.separatorStyle = UITableViewCellSeparatorStyleNone; tableView.dataSource = self; tableView.delegate = self; tableView.estimatedRowHeight = 0; tableView.estimatedSectionHeaderHeight = 0; tableView.estimatedSectionFooterHeight = 0; tableView; }); } return _myTableView; } - (UISegmentedControl *)mySegmentedControl{ if (!_mySegmentedControl) { _mySegmentedControl = ({ UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:@[@"分支", @"标签"]]; segmentedControl.tintColor = kColorBrandBlue; [segmentedControl setTitleTextAttributes:@{ NSFontAttributeName: [UIFont systemFontOfSize:13], NSForegroundColorAttributeName: [UIColor whiteColor] } forState:UIControlStateSelected]; [segmentedControl setTitleTextAttributes:@{ NSFontAttributeName: [UIFont systemFontOfSize:13], NSForegroundColorAttributeName: kColorBrandBlue } forState:UIControlStateNormal]; [segmentedControl addTarget:self action:@selector(segmentedControlSelected:) forControlEvents:UIControlEventValueChanged]; segmentedControl; }); } return _mySegmentedControl; } - (NSArray *)dataList{ return _segmentIndex == 0? _branchList: _tagList; } #pragma mark UI - (void)loadUIElement{ self.myTapBackgroundView.backgroundColor = [UIColor colorWithWhite:0 alpha:0]; [self.myContentView addSubview:self.myTableView]; [self.myContentView addSubview:self.mySegmentedControl]; self.mySegmentedControl.frame = CGRectMake(12, (kCodeBranchTagButton_NavHeight - 30)/2, kScreen_Width - 2*12, 30); { UIView *lineV = [[UIView alloc] initWithFrame:CGRectMake(0, kCodeBranchTagButton_NavHeight, kScreen_Width, kLine_MinHeight)]; lineV.backgroundColor = kColorDDD; [self.myContentView addSubview:lineV]; } self.myContentView.frame = CGRectMake(0, 0, kScreen_Width, 0); self.myTableView.frame = CGRectMake(0, kCodeBranchTagButton_NavHeight, kScreen_Width, 0); // _myRefreshControl = [[ODRefreshControl alloc] initInScrollView:self.myTableView]; // [_myRefreshControl addTarget:self action:@selector(queryToRefresh) forControlEvents:UIControlEventValueChanged]; self.segmentIndex = 0; } - (void)changeShowing{ [kKeyWindow endEditing:YES]; if (!_myContentView) {//未载入过 [self loadUIElement]; } CGPoint origin = [self convertPoint:CGPointMake(0, CGRectGetHeight(self.bounds)) toView:self.showingContainerView]; CGFloat contentHeight = self.isShowing? 0: CGRectGetHeight(self.showingContainerView.bounds) - origin.y; if (self.isShowing) {//隐藏 self.enabled = NO; [UIView animateWithDuration:0.3 animations:^{ self.myTapBackgroundView.backgroundColor = [UIColor colorWithWhite:0 alpha:0]; self.myContentView.alpha = 0; self.myContentView.height = contentHeight; self.myTableView.height = 0; self.imageView.transform = CGAffineTransformRotate(self.imageView.transform, DEGREES_TO_RADIANS(180)); } completion:^(BOOL finished) { [self.myTapBackgroundView removeFromSuperview]; [self.myContentView removeFromSuperview]; self.enabled = YES; self.isShowing = NO; }]; }else{//显示 self.myTapBackgroundView.y = self.myContentView.y = origin.y; self.myContentView.frame = CGRectMake(0, origin.y, kScreen_Width, 0); self.myTableView.height = 0; [self.showingContainerView addSubview:self.myTapBackgroundView]; [self.showingContainerView addSubview:self.myContentView]; self.enabled = NO; [UIView animateWithDuration:0.3 animations:^{ self.myTapBackgroundView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.2]; self.myContentView.alpha = 1.0; self.myContentView.height = contentHeight; self.myTableView.height = contentHeight - kCodeBranchTagButton_NavHeight; self.imageView.transform = CGAffineTransformRotate(self.imageView.transform, DEGREES_TO_RADIANS(180)); } completion:^(BOOL finished) { self.enabled = YES; self.isShowing = YES; }]; } } - (void)segmentedControlSelected:(id)sender{ UISegmentedControl *segmentedControl = (UISegmentedControl *)sender; self.segmentIndex = segmentedControl.selectedSegmentIndex; } #pragma mark Set & Refresh - (void)setTitleStr:(NSString *)titleStr{ if (![_titleStr isEqualToString:titleStr]) { _titleStr = titleStr; [self refreshSelfUI]; } } - (void)refreshSelfUI{ self.backgroundColor = [UIColor whiteColor]; self.titleLabel.font = [UIFont systemFontOfSize:14]; [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; [self setTitleColor:[UIColor darkGrayColor] forState:UIControlStateHighlighted]; [self setTitle:_titleStr forState:UIControlStateNormal]; [self setImage:[UIImage imageNamed:@"icon_triangle"] forState:UIControlStateNormal]; CGFloat titleWidth = [_titleStr getWidthWithFont:self.titleLabel.font constrainedToSize:CGSizeMake(kScreen_Width, 30)]; self.titleEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 10); self.imageEdgeInsets = UIEdgeInsetsMake(0, titleWidth, 0, -titleWidth); } - (void)setSegmentIndex:(NSInteger)segmentIndex{ _segmentIndex = segmentIndex; if (self.mySegmentedControl.selectedSegmentIndex != _segmentIndex) { [self.mySegmentedControl setSelectedSegmentIndex:_segmentIndex]; } [self.myTableView reloadData]; if (!self.dataList) { // [self.myRefreshControl beginRefreshing]; [self.myTableView setContentOffset:CGPointMake(0, -44)]; [self queryToRefresh]; } } - (void)queryToRefresh{ if (!_curProject) { return; } __weak typeof(self) weakSelf = self; if (_segmentIndex == 0) {//branch [[Coding_NetAPIManager sharedManager] request_CodeBranchOrTagWithPath:@"list_branches" withPro:_curProject andBlock:^(id data, NSError *error) { // [weakSelf.myRefreshControl endRefreshing]; if (data) { weakSelf.branchList = data; [weakSelf.myTableView reloadData]; } }]; }else{//tag [[Coding_NetAPIManager sharedManager] request_CodeBranchOrTagWithPath:@"list_tags" withPro:_curProject andBlock:^(id data, NSError *error) { // [weakSelf.myRefreshControl endRefreshing]; if (data) { weakSelf.tagList = data; [weakSelf.myTableView reloadData]; } }]; } } #pragma mark Table M - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return [self.dataList count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_BranchTag forIndexPath:indexPath]; cell.textLabel.font = [UIFont systemFontOfSize:15]; cell.backgroundColor = [UIColor whiteColor]; CodeBranchOrTag *curBranchOrTag = [self.dataList objectAtIndex:indexPath.row]; cell.textLabel.text = curBranchOrTag.name; if ([curBranchOrTag.name isEqualToString:self.titleStr]) { cell.textLabel.textColor = kColorBrandBlue; cell.accessoryType = UITableViewCellAccessoryCheckmark; }else{ cell.textLabel.textColor = [UIColor blackColor]; cell.accessoryType = UITableViewCellAccessoryNone; } static NSInteger lineTag = 11011; if (![cell.contentView viewWithTag:lineTag]) { CGFloat lineH = kLine_MinHeight; UIView *lineV = [[UIView alloc] initWithFrame:CGRectMake(15, 44 - lineH, kScreen_Width, lineH)]; lineV.tag = lineTag; lineV.backgroundColor = kColorDDD; [cell.contentView addSubview:lineV]; } return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 44; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ [tableView deselectRowAtIndexPath:indexPath animated:YES]; CodeBranchOrTag *curBranchOrTag = [self.dataList objectAtIndex:indexPath.row]; self.titleStr = curBranchOrTag.name; [self.myTableView reloadData]; if (_selectedBranchTagBlock) { _selectedBranchTagBlock(curBranchOrTag.name); } [self changeShowing]; } @end |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |