-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForecastList.m
More file actions
228 lines (193 loc) · 10.7 KB
/
ForecastList.m
File metadata and controls
228 lines (193 loc) · 10.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
//
// ForecastList.m
// study
//
// Created by 邹应天 on 15/8/16.
// Copyright (c) 2015年 邹应天. All rights reserved.
//
#import "ForecastList.h"
#import "ForeDataLoad.h"
#import "TableViewCell.h"
#import "NSString+weatherIcon.h"
#import "TransitionBack.h"
@class ForeDataLoad;
@interface ForecastList ()
@property TransitionBack *Animator;
@end
@implementation ForecastList
-(void)viewWillAppear:(BOOL)animated{
self.navigationController.navigationBar.frame=CGRectMake(0,0, self.view.bounds.size.width, 100);
self.navigationController.navigationBar.alpha=0.6;
}
- (void)viewDidLoad {
[super viewDidLoad];
//整个表视图的大致 frame
self.tableList=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
//NSLog(@"%f",self.tableList.contentOffset.y);
self.tableList.delegate=self;
self.tableList.dataSource=self;
[self.tableList setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
// 设置navigationItem式样
self.navigationItem.hidesBackButton=YES;
self.navigationController.delegate=self;
UILabel *cityTitle=[[UILabel alloc]init];
cityTitle.textColor=[UIColor blackColor];
cityTitle.alpha=1;
[cityTitle setFont:[UIFont fontWithName:@"Lato-Light" size:40]];
cityTitle.text=@"Wuhan";
//cityTitle.textColor=[UIColor purpleColor];
cityTitle.frame=CGRectMake(100, 30, 400, 70);
[self.navigationController.navigationBar addSubview:cityTitle];
[self.view addSubview:self.tableList];
ForeDataLoad *foreDataLoad=[[ForeDataLoad alloc]init];
self.data=foreDataLoad;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"cell";
TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
//无可复用队列的cell可使用时需要创建新的cell!!
if (cell==nil) {
cell=[[TableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
NSString *weathertype=[[NSString alloc]init];
NSString *weekday=[[NSString alloc]init];
//md完全不按网上标准正则匹配的来,^[0-9]*$,[0-9]*,\s[0-9]*没一个可以用。匹配能力太屎了吧这也!!!!!
//NSString *marchtemp=@"^[0-9]+&";
NSString *marchtemp=@"^[0-9]";
NSString *weatherText=[[NSString alloc]initWithString:[self.data.forelist2 objectForKey:@"high"]];
NSRegularExpression *regular= [NSRegularExpression regularExpressionWithPattern:marchtemp options:NSRegularExpressionCaseInsensitive error:nil];
NSTextCheckingResult *result = [regular firstMatchInString:weatherText options:0 range:NSMakeRange(0, [weatherText length])];
// NSRange range = [weatherText rangeOfString:marchtemp options:NSRegularExpressionSearch];
// NSLog(@"%@",text);
// NSRange range=[a rangeOfString:marchtemp options:NSRegularExpressionSearch];
// NSLog(@"%@",NSStringFromRange(range));
// NSLog(@"Range is: %@", [[self.data.forelist2 objectForKey:@"high"] substringWithRange:range]);
[cell.partern setFont:[UIFont fontWithName:KFontName size:60]];
[cell.weekday setFont:[UIFont fontWithName:@"Lato-Thin" size:40]];
switch (indexPath.row) {
case 0:{
//cell.label1.text=[self.data.forelist1 objectForKey:@"type"];
cell.partern.text=[weathertype transToIcon:[self.data.forelist1 objectForKey:@"type"]];
NSRange rangeh1=[[self.data.forelist1 objectForKey:@"high"] rangeOfString:marchtemp options:NSRegularExpressionSearch];
cell.high.text=[[self.data.forelist1 objectForKey:@"high"] substringWithRange:rangeh1];
NSRange rangel1=[[self.data.forelist1 objectForKey:@"low"] rangeOfString:marchtemp options:NSRegularExpressionSearch];
cell.low.text=[[self.data.forelist1 objectForKey:@"low"] substringWithRange:rangel1];
cell.weekday.text=[weekday transToName:[self.data.forelist1 objectForKey:@"date"]];
cell.weekday.transform=CGAffineTransformMakeTranslation(15, 0);
[UIView animateWithDuration:1 delay:1 options:UIViewAnimationOptionCurveEaseOut animations:^{
cell.weekday.transform=CGAffineTransformMakeTranslation(0, 0);
} completion:^(BOOL finished) {
//NSLog(@"done");
}];}
break;
case 1:
{
cell.partern.text=[weathertype transToIcon:[self.data.forelist2 objectForKey:@"type"]];
NSRange rangeh2=[[self.data.forelist2 objectForKey:@"high"] rangeOfString:marchtemp options:NSRegularExpressionSearch];
cell.high.text=[[self.data.forelist2 objectForKey:@"high"] substringWithRange:rangeh2];
NSRange rangel2=[[self.data.forelist2 objectForKey:@"low"] rangeOfString:marchtemp options:NSRegularExpressionSearch];
cell.low.text=[[self.data.forelist2 objectForKey:@"low"] substringWithRange:rangel2];
cell.weekday.text=[weekday transToName:[self.data.forelist2 objectForKey:@"date"]];
cell.weekday.transform=CGAffineTransformMakeTranslation(15, 0);
[UIView animateWithDuration:1 delay:1.3 options:UIViewAnimationOptionCurveEaseOut animations:^{
cell.weekday.transform=CGAffineTransformMakeTranslation(0, 0);
} completion:^(BOOL finished) {
}];
}
break;
case 2:
{
//cell.label1.text=[self.data.forelist3 objectForKey:@"type"];
cell.partern.text=[weathertype transToIcon:[self.data.forelist3 objectForKey:@"type"]];
NSRange rangeh3=[[self.data.forelist3 objectForKey:@"high"] rangeOfString:marchtemp options:NSRegularExpressionSearch];
cell.high.text=[[self.data.forelist3 objectForKey:@"high"] substringWithRange:rangeh3];
NSRange rangel3=[[self.data.forelist3 objectForKey:@"low"] rangeOfString:marchtemp options:NSRegularExpressionSearch];
cell.low.text=[[self.data.forelist3 objectForKey:@"low"] substringWithRange:rangel3];
cell.weekday.text=[weekday transToName:[self.data.forelist3 objectForKey:@"date"]];
cell.weekday.transform=CGAffineTransformMakeTranslation(15, 0);
[UIView animateWithDuration:1 delay:1.6 options:UIViewAnimationOptionCurveEaseOut animations:^{
cell.weekday.transform=CGAffineTransformMakeTranslation(0, 0);
} completion:^(BOOL finished) {
// NSLog(@"done");
}];
}
break;
case 3:
{
cell.partern.text=[weathertype transToIcon:[self.data.forelist4 objectForKey:@"type"]];
NSRange rangeh4=[[self.data.forelist4 objectForKey:@"high"] rangeOfString:marchtemp options:NSRegularExpressionSearch];
cell.high.text=[[self.data.forelist4 objectForKey:@"high"] substringWithRange:rangeh4];
NSRange rangel4=[[self.data.forelist4 objectForKey:@"low"] rangeOfString:marchtemp options:NSRegularExpressionSearch];
cell.low.text=[[self.data.forelist4 objectForKey:@"low"] substringWithRange:rangel4];
cell.weekday.text=[weekday transToName:[self.data.forelist4 objectForKey:@"date"]];
cell.weekday.transform=CGAffineTransformMakeTranslation(15, 0);
[UIView animateWithDuration:1 delay:1.9 options:UIViewAnimationOptionCurveEaseOut animations:^{
cell.weekday.transform=CGAffineTransformMakeTranslation(0, 0);
} completion:^(BOOL finished) {
//NSLog(@"done");
}];
}
break;
case 4:
{
cell.partern.text=[weathertype transToIcon:[self.data.forelist5 objectForKey:@"type"]];
NSRange rangeh5=[[self.data.forelist5 objectForKey:@"high"] rangeOfString:marchtemp options:NSRegularExpressionSearch];
cell.high.text=[[self.data.forelist5 objectForKey:@"high"] substringWithRange:rangeh5];
NSRange rangel5=[[self.data.forelist5 objectForKey:@"low"] rangeOfString:marchtemp options:NSRegularExpressionSearch];
cell.low.text=[[self.data.forelist5 objectForKey:@"low"] substringWithRange:rangel5];
cell.weekday.text=[weekday transToName:[self.data.forelist5 objectForKey:@"date"]];
cell.weekday.transform=CGAffineTransformMakeTranslation(15, 0);
[UIView animateWithDuration:1 delay:2.2 options:UIViewAnimationOptionCurveEaseOut animations:^{
cell.weekday.transform=CGAffineTransformMakeTranslation(0, 0);
} completion:^(BOOL finished) {
// NSLog(@"done");
}];
}
break;
default:
break;
}
if ([cell.weekday.text isEqualToString:@"Sun"]) {
cell.weekday.textColor=[UIColor redColor];
}
}
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 9;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{ //NSLog(@"4");
return 80;
}
//无需再设置滑动代理,直接由tableview偏移判断来设定。
-(void)popToWeather{
[self.navigationController setNavigationBarHidden:YES animated:YES];
[self.navigationController popViewControllerAnimated:YES];
}
//tableView继承自scrollerView,不用写scroller的delegate,直接用
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
if (scrollView.contentOffset.y<-180){
NSLog(@"%f",scrollView.contentOffset.y);
[self popToWeather];
}
}
#pragma mark - UINavigationControllerDelegate iOS7新增的2个方法
// 动画特效
- (id<UIViewControllerAnimatedTransitioning>) navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC
{
if (operation == UINavigationControllerOperationPop) {
NSLog(@"touchtwo");
self.Animator = [[TransitionBack alloc]init];
return self.Animator;
//return nil;
}else{
return nil;
}
}
@end