相关链接:
1.贝塞尔曲线在 iOS 端的绘图实践
2.iOS UIBezierPath(贝塞尔曲线)
3.iOS中的贝塞尔曲线(UIBezierPath)
【4.iOS NSValue 和 CGPoint 相互转换】
先上效果图片:
代码:
@interface GWCW_ClubWeatherCell () <UIScrollViewDelegate, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
/** 闭合时:50 */
@property (nonatomic, strong) UIView *smallBackView;
@property (nonatomic, strong) UILabel *dateL;
@property (nonatomic, strong) UILabel *timeL;
@property (nonatomic, strong) UIImageView *dayImg; // 白天
@property (nonatomic, strong) UIImageView *nightImg;// 夜晚
@property (nonatomic, strong) UILabel *dayTempL; // 白天温度
@property (nonatomic, strong) UILabel *nightTempL;// 夜晚温度
@property (nonatomic, strong) UIView *tempView; // 温度条
@property (nonatomic, strong) UIImageView *isOPenImg; // 展开闭合图标
/** 展开时:330 */
@property (nonatomic, strong) UIView *bigBackView;
@property (nonatomic, strong) UILabel *big_TimeL; // 时间
@property (nonatomic, strong) UILabel *big_tempL; // 温度: 19°/15°
@property (nonatomic, strong) UIImageView *big_weatherImg;// 天气图片
@property (nonatomic, strong) UILabel *big_weatherTextL;// 天气描述
@property (nonatomic, strong) UILabel *big_winpL; // 风力级别
@property (nonatomic, strong) UIImageView *big_isOPenImg; // 展开闭合图标
@property (nonatomic, strong) UIImageView *big_dayImg;
@property (nonatomic, strong) UIImageView *big_nightImg;
@property (nonatomic, strong) UILabel *big_dayTimeL; // 日出时间
@property (nonatomic, strong) UILabel *big_noghtTimeL;// 日落时间
// 太阳️曲线
//@property (nonatomic, strong) UIView *big_toSunsetBackView; // 曲线背景:99 x 28
//@property (nonatomic, strong) UIImageView *big_toSunsetImg;
@property (nonatomic, strong) GWCW_ClubWeatherSunriseView *big_toSunsetBackView;
/** 展开时:折线图 */
@property (nonatomic, strong) UIView *chartBackView; // 背景view
@property (nonatomic, strong) UIScrollView *chartContentScrollView;
@property (nonatomic, strong) UIView *chartContentView; // 折线图的view
@property (nonatomic, strong) CALayer *chartContentView_Backlayer; // self.chartContentView.layer
@property (nonatomic, strong) CAShapeLayer *chartLayer; // 添加一个父layer
@property (nonatomic, strong) CAShapeLayer *tempLayer; // 添加一个父layer
@property (nonatomic, strong) UICollectionView *collectionView;
// 滑动进度条
@property (nonatomic, strong) UIView *progressBackView;
@property (nonatomic, strong) UIView *progressView;
@end
@implementation GWCW_ClubWeatherCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.backgroundColor = [UIColor clearColor];
[self setupUI];
}
return self;
}
- (void)prepareForReuse {
[super prepareForReuse];
self.dateL.text = nil;
self.timeL.text = nil;
self.dayImg.image = nil;
self.nightImg.image = nil;
self.dayTempL.text = nil;
self.nightTempL.text = nil;
self.tempView.hidden = YES;
self.isOPenImg.image = nil;
// 展开
self.bigBackView.hidden = YES;
self.big_TimeL.text = nil;
self.big_tempL.text = nil;
self.big_weatherImg.image = nil;
self.big_weatherTextL.text = nil;
self.big_winpL.text = nil;
self.big_isOPenImg.image = nil;
self.big_dayImg.image = nil;
self.big_nightImg.image = nil;
self.big_dayTimeL.text = nil;
self.big_noghtTimeL.text = nil;
self.big_toSunsetBackView.hidden = YES;
[self.chartLayer removeFromSuperlayer];
[self.tempLayer removeFromSuperlayer];
self.collectionView.hidden = YES;
self.progressBackView.hidden = YES;
self.progressView.hidden = YES;
}
- (void)setDailyModel:(GWCW_ClubWeather_DailyWeatherModel *)dailyModel {
_dailyModel = dailyModel;
if (_dailyModel.isOpen) { /** 展开 内容 */
self.smallBackView.hidden = YES;
self.bigBackView.hidden = NO;
self.big_toSunsetBackView.hidden = NO;
if (self.indexCell == 0) {
self.big_TimeL.text = [NSString stringWithFormat:@"今天 %@", _dailyModel.date];
} else if (self.indexCell == 1) {
self.big_TimeL.text = [NSString stringWithFormat:@"明天 %@", _dailyModel.date];
} else {
self.big_TimeL.text = [NSString stringWithFormat:@"%@ %@", _dailyModel.week, _dailyModel.date];
}
self.big_tempL.text = _dailyModel.temp;
[self.big_weatherImg sd_setImageWithURL:[NSURL URLWithString:_dailyModel.dayUrl] placeholderImage:[UIImage imageNamed:@""]];
self.big_weatherTextL.text = _dailyModel.weatherText;
self.big_winpL.text = _dailyModel.wind;
if (_dailyModel.isOpen) {
self.big_isOPenImg.image = [UIImage imageNamed:@"new_weatherCell_收起_icon"];
} else {
self.big_isOPenImg.image = [UIImage imageNamed:@"new_weatherCell_展开_icon"];
}
self.big_dayImg.image = [UIImage imageNamed:@"new_weather_Black日出_icon"];
self.big_nightImg.image = [UIImage imageNamed:@"new_weather_Black日落_icon"];
self.big_dayTimeL.text = _dailyModel.sunrise;
self.big_noghtTimeL.text = _dailyModel.sunset;
// 太阳️曲线
[self.big_toSunsetBackView sendSunset:_dailyModel.toSunset];
/** 1、创建父layer */
_chartLayer = [[CAShapeLayer alloc] init];
_chartLayer.strokeColor = [UIColor clearColor].CGColor;
UIBezierPath *bezierPath = [UIBezierPath
bezierPathWithRoundedRect:CGRectMake(0, 0, self.chartContentScrollView.contentSize.width, [UIScreen mainScreen].bounds.size.width/375*58)
byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
cornerRadii:CGSizeMake([UIScreen mainScreen].bounds.size.width/375*0, [UIScreen mainScreen].bounds.size.width/375*0)];
_chartLayer.lineWidth = [UIScreen mainScreen].bounds.size.width/375*0.01;
// 颜色
_chartLayer.strokeColor = [UIColor clearColor].CGColor;
// 背景填充色
_chartLayer.fillColor = [UIColor clearColor].CGColor;
_chartLayer.path = [bezierPath CGPath];
[self.chartContentView.layer addSublayer:self.chartLayer];
/** 天气贝塞尔曲线 */
UIBezierPath *weatherPath = [UIBezierPath bezierPath];
/// 先找到最大温度和最低温度,在这个范围内设置温度的最大范围:
CGFloat maxTemp = 0;
CGFloat minTemp = 0;
for (int j = 0; j < self.hourlyModels.count; j++) {
GWCW_ClubWeather_HourlyWeatherModel *hourModel = self.hourlyModels[j];
CGFloat i_temp = [hourModel.temp floatValue];
// NSLog(@"一天的温度 %.2f ", i_temp);
if (j == 0) {
maxTemp = i_temp;
minTemp = i_temp;
}
if (maxTemp > i_temp) {
maxTemp = maxTemp;
} else {
maxTemp = i_temp;
}
if (minTemp > i_temp) {
minTemp = i_temp;
} else {
minTemp = minTemp;
}
}
// 温度之差 的 温度范围:温度三种情况都是这个减法获取温度的范围
CGFloat maxTempRange = maxTemp - minTemp;
NSMutableArray *circleArray = [NSMutableArray arrayWithCapacity:0];
// 设置path的 起始点 和 其他点
for (int i = 0; i < self.hourlyModels.count; i++) {
GWCW_ClubWeather_HourlyWeatherModel *hourModel = self.hourlyModels[i];
// CGFloat temp = fabsl(hourModel.temp);
CGFloat temp = [hourModel.temp floatValue];
// CGFloat myPointY = [UIScreen mainScreen].bounds.size.width/375* 0.58*temp;
// NSLog(@"一天的温度 %.2f ", temp);
// 温度折线图,最高温60摄氏度,最低温-40 度℃,(temp - minTemp) = 当前的温度,减去最小的温度,载乘以等份
if (i == 0) {
[weatherPath moveToPoint:CGPointMake([UIScreen mainScreen].bounds.size.width/375*(25), [UIScreen mainScreen].bounds.size.width/375*(58 - 8 - 40/maxTempRange * (temp - minTemp)))];
// 端点位置CGPoint
CGPoint circlePoint = CGPointMake([UIScreen mainScreen].bounds.size.width/375*(25), [UIScreen mainScreen].bounds.size.width/375*(58 - 8 - 40/maxTempRange * (temp - minTemp)));
NSValue* circleValue = [NSValue valueWithCGPoint:circlePoint];
[circleArray addObject:circleValue];
/**
/// 因为CGPoint不是对象,所以不能存到数组,需要转成NSValue
// CGPoint 转 NSValue
NSValue* value = [NSValue valueWithCGPoint:CGPointMake(10, 50)];
// NSValue 转 CGPoint
CGPoint pt = [value CGPointValue];
*/
} else {
[weatherPath addLineToPoint:CGPointMake([UIScreen mainScreen].bounds.size.width/375*(25+ (57.9*i)), [UIScreen mainScreen].bounds.size.width/375*(58 - 8 - 40/maxTempRange * (temp - minTemp)))];
// 端点位置CGPoint
CGPoint circlePoint = CGPointMake([UIScreen mainScreen].bounds.size.width/375*(25+ (57.9*i)), [UIScreen mainScreen].bounds.size.width/375*(58 - 8 - 40/maxTempRange * (temp - minTemp)));
NSValue* circleValue = [NSValue valueWithCGPoint:circlePoint];
[circleArray addObject:circleValue];
}
}
_tempLayer = [CAShapeLayer layer];
// 线宽
self.tempLayer.lineWidth = [UIScreen mainScreen].bounds.size.width/375*2;
// 线条的颜色
self.tempLayer.strokeColor = RGBA(135, 190, 241, 1).CGColor;
// 背景填充色
self.tempLayer.fillColor = [UIColor clearColor].CGColor;
// 将UIBezierPath类转换成CGPath,类似于UIColor的CGColor
// [weatherPath closePath];// 起始点和终点,连接起来。(可以先添加”起始点“和”终点“的y轴为0,加上这句之后,范围内的填充颜色。)
self.tempLayer.path = [weatherPath CGPath];
[self.chartLayer addSublayer:self.tempLayer]; // 这行代码之前,将执行[self.tempLayer removeFromSuperlayer];,再执行这行代码
/** 折线图中的小圆点 + 虚线*/
for (NSValue *circleValue in circleArray) {
/** 折线图中的小圆点 */
CGPoint circlePoint = [circleValue CGPointValue];
CAShapeLayer *circleLayer = [CAShapeLayer layer];
// 线宽
circleLayer.lineWidth = [UIScreen mainScreen].bounds.size.width/375*1; // 10 - 6 = 4
circleLayer.lineCap = kCALineCapRound; // 端点样式
circleLayer.lineJoin = kCALineCapRound; // 终点处理
// 线条的颜色
circleLayer.strokeColor = RGBA(135, 190, 241, 1).CGColor;
// 背景填充色
circleLayer.fillColor = [UIColor whiteColor].CGColor;
// 设置线宽、线间距(虚线)
// [circleLayer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:2], [NSNumber numberWithInt:2], nil]];
// 设置半径
CGFloat circleRadius = [UIScreen mainScreen].bounds.size.width/375*3;
// 初始化一个路径:创建圆弧 ,startAngle:起始点,endAngle:终止点,clockwise:顺时针方向 ,M_PI == π:3.1415926
// bezierPathWithArcCenter 中心点,下面就让addSublayer了,那么就设置self.bezierBackImg.layer的 中心点就好了,宽/2,高/2
UIBezierPath *circlePath = [UIBezierPath bezierPathWithArcCenter:circlePoint radius:circleRadius startAngle:(0*M_PI) endAngle:(2*M_PI) clockwise:YES]; // 终止点(60%几率时):(2*0.6 - 0.25)*M_PI,clockwise 顺时针 YES, 逆时针 NO
// 将UIBezierPath类转换成CGPath,类似于UIColor的CGColor
circleLayer.path = [circlePath CGPath];
[self.chartLayer addSublayer:circleLayer]; // 这行代码之前,将执行[self.tempLayer
/** 虚线的 path */
UIBezierPath *linePath = [UIBezierPath bezierPath];
// 起始点
CGPoint lineStartPoint = CGPointMake(circlePoint.x, circlePoint.y + [UIScreen mainScreen].bounds.size.width/375*5);
[linePath moveToPoint:lineStartPoint];
// 末端
CGPoint lineEndPoint = CGPointMake(circlePoint.x, [UIScreen mainScreen].bounds.size.width/375*(58 - 4));
[linePath addLineToPoint:lineEndPoint];
/** 渐变色条,在上面添加虚线CAShapeLayer */
CAGradientLayer *gradient = [CAGradientLayer layer];
// 写成固定的大小(和self.backView的frame一样)
gradient.frame = CGRectMake(lineEndPoint.x-[UIScreen mainScreen].bounds.size.width/375*0.5, lineStartPoint.y, [UIScreen mainScreen].bounds.size.width/375*1, lineEndPoint.y - lineStartPoint.y);
gradient.colors = [NSArray arrayWithObjects:
(id)[UIColor colorWithRed:2/255.0 green:91/255.0 blue:172/255.0 alpha:0.7].CGColor,
(id)[UIColor colorWithRed:2/255.0 green:91/255.0 blue:172/255.0 alpha:0.19].CGColor,
nil];
gradient.startPoint = CGPointMake(0.5, 0);
gradient.endPoint = CGPointMake(0.5, 1);
gradient.masksToBounds = YES;
gradient.cornerRadius = [UIScreen mainScreen].bounds.size.width/375*1;
[self.chartLayer addSublayer:gradient];
/** 虚线*/
CAShapeLayer *lineLayer = [CAShapeLayer layer];
// 线宽
lineLayer.lineWidth = [UIScreen mainScreen].bounds.size.width/375*2;
// 线条的颜色
lineLayer.strokeColor = RGBA(248, 247, 245, 1).CGColor;
// 背景填充色
lineLayer.fillColor = [UIColor clearColor].CGColor;
// 设置线宽、线间距(虚线)
[lineLayer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:2], [NSNumber numberWithInt:2], nil]];
// 将UIBezierPath类转换成CGPath,类似于UIColor的CGColor
lineLayer.path = [linePath CGPath];
[self.chartLayer addSublayer:lineLayer]; // 这行代码之前,将执行[self.tempLayer
}
self.collectionView.hidden = NO;
[self refreshCollectionView];
self.progressBackView.hidden = NO;
self.progressView.hidden = NO;
/// 贝塞尔曲线
// CAShapeLayer *backLineLayer = [CAShapeLayer layer];
// // 线宽
// backLineLayer.lineWidth = [UIScreen mainScreen].bounds.size.width/375*1; // 10 - 6 = 4
// backLineLayer.lineCap = kCALineCapRound; // 端点样式
// backLineLayer.lineJoin = kCALineCapRound; // 终点处理
// // 线条的颜色
// backLineLayer.strokeColor = RGBA(221, 221, 221, 1).CGColor;
// // 背景填充色
// backLineLayer.fillColor = [UIColor clearColor].CGColor;
// // 设置线宽、线间距(虚线)
// [backLineLayer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:2], [NSNumber numberWithInt:2], nil]];
//
// // 设置半径
// CGFloat backRadius = [UIScreen mainScreen].bounds.size.width/375*132/2;
//
// // 初始化一个路径:创建圆弧 ,startAngle:起始点,endAngle:终止点,clockwise:顺时针方向 ,M_PI == π:3.1415926
// // bezierPathWithArcCenter 中心点,下面就让addSublayer了,那么就设置self.bezierBackImg.layer的 中心点就好了,宽/2,高/2
// UIBezierPath *backPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake([UIScreen mainScreen].bounds.size.width/375*99/2, [UIScreen mainScreen].bounds.size.width/375*132/2+7) radius:backRadius startAngle:(1.25*M_PI) endAngle:(1.75*M_PI) clockwise:YES]; // 终止点(60%几率时):(2*0.6 - 0.25)*M_PI,clockwise 顺时针 YES, 逆时针 NO
//
// // 将UIBezierPath类转换成CGPath,类似于UIColor的CGColor
// backLineLayer.path = [backPath CGPath];
// [self.big_toSunsetBackView.layer addSublayer:backLineLayer];
//
//
// /// 贝塞尔曲线(进度)
// CAShapeLayer *progressLineLayer = [CAShapeLayer layer];
// // 线宽
// progressLineLayer.lineWidth = [UIScreen mainScreen].bounds.size.width/375*2; // 10 - 6 = 4
// progressLineLayer.lineCap = kCALineCapRound; // 端点样式
// progressLineLayer.lineJoin = kCALineCapRound; // 终点处理
// // 线条的颜色
// progressLineLayer.strokeColor = RGBA(255, 196, 15, 1).CGColor;
// // 背景填充色
// progressLineLayer.fillColor = [UIColor clearColor].CGColor;
// // 设置线宽、线间距(虚线)
//// [progressLineLayer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:2], [NSNumber numberWithInt:2], nil]];
// // 设置半径
// CGFloat progressRadius = [UIScreen mainScreen].bounds.size.width/375*132/2;
//
// // 初始化一个路径:创建圆弧 ,startAngle:起始点,endAngle:终止点,clockwise:顺时针方向 ,M_PI == π:3.1415926
// // bezierPathWithArcCenter 中心点,下面就让addSublayer了,那么就设置self.bezierBackImg.layer的 中心点就好了,宽/2,高/2
// UIBezierPath *progressPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake([UIScreen mainScreen].bounds.size.width/375*99/2, [UIScreen mainScreen].bounds.size.width/375*132/2+7) radius:progressRadius startAngle:(1.25*M_PI) endAngle:((1.25 + 0.5*_dailyModel.toSunset)*M_PI) clockwise:YES]; // 终止点(60%几率时):(2*0.6 - 0.25)*M_PI,clockwise 顺时针 YES, 逆时针 NO
//
// // 将UIBezierPath类转换成CGPath,类似于UIColor的CGColor
// progressLineLayer.path = [progressPath CGPath];
// [self.big_toSunsetBackView.layer addSublayer:progressLineLayer];
//
//
//
// self.big_toSunsetBackView.layer.masksToBounds = YES;
//
//// self.big_toSunsetBackView.backgroundColor = [UIColor redColor];
//
// self.big_toSunsetImg.image = [UIImage imageNamed:@"club_sun"];
//
// CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
// // 设置动画的路径 为黄色进度条
// animation.path = progressLineLayer.path;
// animation.duration = 1;
// animation.repeatCount = 1;
// animation.removedOnCompletion = NO;
// animation.fillMode = kCAFillModeForwards;
// [self.big_toSunsetImg.layer addAnimation:animation forKey:nil];
} else { /** 闭合 内容 */
self.smallBackView.hidden = NO;
self.bigBackView.hidden = YES;
self.tempView.hidden = NO;
if (self.indexCell == 0) {
self.dateL.text = @"今天";
} else if (self.indexCell == 1) {
self.dateL.text = @"明天";
} else {
self.dateL.text = _dailyModel.week;
}
self.timeL.text = _dailyModel.date;
[self.dayImg sd_setImageWithURL:[NSURL URLWithString:_dailyModel.dayUrl] placeholderImage:[UIImage imageNamed:@""]];
[self.nightImg sd_setImageWithURL:[NSURL URLWithString:_dailyModel.nightUrl] placeholderImage:[UIImage imageNamed:@""]];
NSString *temp = _dailyModel.temp;
NSArray *tempArr = [temp componentsSeparatedByString:@"/"];
if (tempArr.count >= 2) {
self.dayTempL.text = [NSString stringWithFormat:@"%@", tempArr[0]];
self.nightTempL.text = [NSString stringWithFormat:@"%@", tempArr[1]];
} else {
self.dayTempL.text = @"";
self.nightTempL.text = @"";
}
if (_dailyModel.isOpen) {
self.isOPenImg.image = [UIImage imageNamed:@"new_weatherCell_收起_icon"];
} else {
self.isOPenImg.image = [UIImage imageNamed:@"new_weatherCell_展开_icon"];
}
CAGradientLayer *gradient = [CAGradientLayer layer];
// 写成固定的大小(和self.tempView的frame一样)
gradient.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width/375*75, [UIScreen mainScreen].bounds.size.width/375*4);
gradient.colors = [NSArray arrayWithObjects:
(id)[UIColor colorWithRed:255/255.0 green:196/255.0 blue:15/255.0 alpha:1.0].CGColor,
(id)[UIColor colorWithRed:139/255.0 green:192/255.0 blue:246/255.0 alpha:1.0].CGColor,
nil];
gradient.startPoint = CGPointMake(0, 0.49);
gradient.endPoint = CGPointMake(1, 0.49);
gradient.masksToBounds = YES;
gradient.cornerRadius = [UIScreen mainScreen].bounds.size.width/375*4/2;
[self.tempView.layer addSublayer:gradient];
}
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView == self.chartContentScrollView) {
if (self.chartContentScrollView.contentOffset.x <= 0) {
self.progressView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width/375*18, [UIScreen mainScreen].bounds.size.width/375*3);
} else if (self.chartContentScrollView.contentOffset.x >= [UIScreen mainScreen].bounds.size.width/375*(50*24 + 8*23 - 310)) {
self.progressView.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/375*(136-18), 0, [UIScreen mainScreen].bounds.size.width/375*18, [UIScreen mainScreen].bounds.size.width/375*3);
} else {
// NSLog(@" self.chartContentScrollView.contentOffset.x = %f", self.chartContentScrollView.contentOffset.x);
CGFloat contentOffsetX = ([UIScreen mainScreen].bounds.size.width/375*(136-18)) * self.chartContentScrollView.contentOffset.x / ([UIScreen mainScreen].bounds.size.width/375*(50*24 + 8*23 - 310));
// NSLog(@" contentOffsetX = %f ", contentOffsetX);
self.progressView.frame = CGRectMake(contentOffsetX, 0, [UIScreen mainScreen].bounds.size.width/375*18, [UIScreen mainScreen].bounds.size.width/375*3);
}
}
}
- (void)setupUI {
/** 闭合 内容 */
_smallBackView = [[UIView alloc] init];
_smallBackView.backgroundColor = [UIColor whiteColor];
self.smallBackView.layer.cornerRadius = [UIScreen mainScreen].bounds.size.width/375*12;
self.smallBackView.layer.shadowColor = RGBA(0, 0, 0, 0.05).CGColor;
self.smallBackView.layer.shadowOffset = CGSizeMake(0, 5);
self.smallBackView.layer.shadowRadius = [UIScreen mainScreen].bounds.size.width/375*6;
self.smallBackView.layer.shadowOpacity = 1;
[self.contentView addSubview:self.smallBackView];
[self.smallBackView makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.mas_top).offset([UIScreen mainScreen].bounds.size.width/375*5);
make.left.mas_equalTo(self.mas_left).offset([UIScreen mainScreen].bounds.size.width/375*20);
make.right.mas_equalTo(self.mas_right).offset(-[UIScreen mainScreen].bounds.size.width/375*20);
make.bottom.mas_equalTo(self.mas_bottom).offset(-[UIScreen mainScreen].bounds.size.width/375*10);
}];
_dateL = [[UILabel alloc] init];
_dateL.textColor = RGBA(9, 9, 9, 1);
_dateL.textAlignment = NSTextAlignmentLeft;
_dateL.font = [UIFont systemFontOfSize:[UIScreen mainScreen].bounds.size.width/375*15 weight:UIFontWeightRegular];
[self.smallBackView addSubview:self.dateL];
[self.dateL makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.smallBackView.mas_top).offset([UIScreen mainScreen].bounds.size.width/375*10);
make.left.mas_equalTo(self.smallBackView.mas_left).offset([UIScreen mainScreen].bounds.size.width/375*15);
}];
_timeL = [[UILabel alloc] init];
_timeL.textColor = RGBA(153, 153, 153, 1);
_timeL.textAlignment = NSTextAlignmentLeft;
_timeL.font = [UIFont systemFontOfSize:[UIScreen mainScreen].bounds.size.width/375*10 weight:UIFontWeightRegular];
[self.smallBackView addSubview:self.timeL];
[self.timeL makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(self.smallBackView.mas_bottom).offset(-[UIScreen mainScreen].bounds.size.width/375*9.5);
make.left.mas_equalTo(self.smallBackView.mas_left).offset([UIScreen mainScreen].bounds.size.width/375*15);
}];
_tempView = [[UIView alloc] init];
self.tempView.layer.masksToBounds = YES;
self.tempView.layer.cornerRadius = [UIScreen mainScreen].bounds.size.width/375*4/2;
[self addSubview:self.tempView];
[self.tempView makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self);
make.left.mas_equalTo(self.smallBackView.left).offset([UIScreen mainScreen].bounds.size.width/375*152);
make.width.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*75);
make.height.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*4);
}];
_dayImg = [[UIImageView alloc] init];
[self.smallBackView addSubview:self.dayImg];
[self.dayImg makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.smallBackView);
make.right.mas_equalTo(self.tempView.mas_left).offset(-[UIScreen mainScreen].bounds.size.width/375*45);
make.width.height.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*23);
}];
_nightImg = [[UIImageView alloc] init];
[self.smallBackView addSubview:self.nightImg];
[self.nightImg makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.smallBackView);
make.left.mas_equalTo(self.tempView.mas_right).offset([UIScreen mainScreen].bounds.size.width/375*45);
make.width.height.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*23);
}];
_dayTempL = [[UILabel alloc] init];
_dayTempL.textColor = RGBA(64, 64, 64, 1);
_dayTempL.textAlignment = NSTextAlignmentRight;
_dayTempL.font = [UIFont systemFontOfSize:[UIScreen mainScreen].bounds.size.width/375*16 weight:UIFontWeightMedium];
[self.smallBackView addSubview:self.dayTempL];
[self.dayTempL makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.smallBackView);
make.right.mas_equalTo(self.tempView.mas_left).offset(-[UIScreen mainScreen].bounds.size.width/375*10);
}];
_nightTempL = [[UILabel alloc] init];
_nightTempL.textColor = RGBA(64, 64, 64, 1);
_nightTempL.textAlignment = NSTextAlignmentRight;
_nightTempL.font = [UIFont systemFontOfSize:[UIScreen mainScreen].bounds.size.width/375*16 weight:UIFontWeightMedium];
[self.smallBackView addSubview:self.nightTempL];
[self.nightTempL makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.smallBackView);
make.left.mas_equalTo(self.tempView.mas_right).offset([UIScreen mainScreen].bounds.size.width/375*10);
}];
_isOPenImg = [[UIImageView alloc] init];
[self.smallBackView addSubview:self.isOPenImg];
[self.isOPenImg makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.smallBackView);
make.right.mas_equalTo(self.smallBackView.mas_right).offset(-[UIScreen mainScreen].bounds.size.width/375*6);
make.width.height.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*25);
}];
/** 展开 内容 */
_bigBackView = [[UIView alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width/375*20, [UIScreen mainScreen].bounds.size.width/375*5, [UIScreen mainScreen].bounds.size.width/375*335, [UIScreen mainScreen].bounds.size.width/375*330)];
_bigBackView.backgroundColor = [UIColor whiteColor];
self.bigBackView.layer.cornerRadius = [UIScreen mainScreen].bounds.size.width/375*12;
self.bigBackView.layer.shadowColor = RGBA(0, 0, 0, 0.05).CGColor;
self.bigBackView.layer.shadowOffset = CGSizeMake(0, 5);
self.bigBackView.layer.shadowRadius = [UIScreen mainScreen].bounds.size.width/375*6;
self.bigBackView.layer.shadowOpacity = 1;
[self.contentView addSubview:self.bigBackView];
_big_TimeL = [[UILabel alloc] init];
_big_TimeL.textColor = RGBA(99, 102, 106, 1);
_big_TimeL.textAlignment = NSTextAlignmentLeft;
_big_TimeL.font = [UIFont systemFontOfSize:[UIScreen mainScreen].bounds.size.width/375*15 weight:UIFontWeightRegular];
[self.bigBackView addSubview:self.big_TimeL];
[self.big_TimeL makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.bigBackView.mas_top).offset([UIScreen mainScreen].bounds.size.width/375*20);
make.left.mas_equalTo(self.bigBackView.mas_left).offset([UIScreen mainScreen].bounds.size.width/375*15);
}];
_big_tempL = [[UILabel alloc] init];
_big_tempL.textColor = RGBA(64, 64, 64, 1);
_big_tempL.textAlignment = NSTextAlignmentLeft;
_big_tempL.font = [UIFont systemFontOfSize:[UIScreen mainScreen].bounds.size.width/375*20 weight:UIFontWeightMedium];
[self.bigBackView addSubview:self.big_tempL];
[self.big_tempL makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.big_TimeL.mas_bottom).offset([UIScreen mainScreen].bounds.size.width/375*20);
make.left.mas_equalTo(self.bigBackView.mas_left).offset([UIScreen mainScreen].bounds.size.width/375*15);
}];
_big_weatherImg = [[UIImageView alloc] init];
[self.bigBackView addSubview:self.big_weatherImg];
[self.big_weatherImg makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.big_tempL.mas_bottom).offset([UIScreen mainScreen].bounds.size.width/375*10);
make.left.mas_equalTo(self.bigBackView.mas_left).offset([UIScreen mainScreen].bounds.size.width/375*15);
make.width.height.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*19);
}];
_big_weatherTextL = [[UILabel alloc] init];
_big_weatherTextL.textColor = RGBA(105, 104, 108, 1);
_big_weatherTextL.textAlignment = NSTextAlignmentLeft;
_big_weatherTextL.font = [UIFont systemFontOfSize:[UIScreen mainScreen].bounds.size.width/375*13 weight:UIFontWeightRegular];
[self.bigBackView addSubview:self.big_weatherTextL];
[self.big_weatherTextL makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.big_weatherImg);
make.left.mas_equalTo(self.big_weatherImg.mas_right).offset([UIScreen mainScreen].bounds.size.width/375*4);
}];
_big_winpL = [[UILabel alloc] init];
_big_winpL.textColor = RGBA(105, 104, 108, 1);
_big_winpL.textAlignment = NSTextAlignmentLeft;
_big_winpL.font = [UIFont systemFontOfSize:[UIScreen mainScreen].bounds.size.width/375*13 weight:UIFontWeightRegular];
[self.bigBackView addSubview:self.big_winpL];
[self.big_winpL makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.big_weatherImg);
make.left.mas_equalTo(self.big_weatherTextL.mas_right).offset([UIScreen mainScreen].bounds.size.width/375*16);
}];
_big_isOPenImg = [[UIImageView alloc] init];
[self.bigBackView addSubview:self.big_isOPenImg];
[self.big_isOPenImg makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.bigBackView.mas_top).offset([UIScreen mainScreen].bounds.size.width/375*22);
make.right.mas_equalTo(self.bigBackView.mas_right).offset(-[UIScreen mainScreen].bounds.size.width/375*6);
make.width.height.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*25);
}];
_big_dayImg = [[UIImageView alloc] init];
[self.bigBackView addSubview:self.big_dayImg];
[self.big_dayImg makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.big_weatherImg);
make.right.mas_equalTo(self.bigBackView.mas_right).offset(-[UIScreen mainScreen].bounds.size.width/375*134);
make.width.height.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*14);
}];
_big_nightImg = [[UIImageView alloc] init];
[self.bigBackView addSubview:self.big_nightImg];
[self.big_nightImg makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.big_weatherImg);
make.right.mas_equalTo(self.bigBackView.mas_right).offset(-[UIScreen mainScreen].bounds.size.width/375*55);
make.width.height.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*14);
}];
_big_dayTimeL = [[UILabel alloc] init];
_big_dayTimeL.textColor = RGBA(105, 104, 108, 1);
_big_dayTimeL.textAlignment = NSTextAlignmentLeft;
_big_dayTimeL.font = [UIFont systemFontOfSize:[UIScreen mainScreen].bounds.size.width/375*13 weight:UIFontWeightRegular];
[self.bigBackView addSubview:self.big_dayTimeL];
[self.big_dayTimeL makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.big_weatherImg);
make.left.mas_equalTo(self.big_dayImg.mas_right).offset([UIScreen mainScreen].bounds.size.width/375*6);
}];
_big_noghtTimeL = [[UILabel alloc] init];
_big_noghtTimeL.textColor = RGBA(105, 104, 108, 1);
_big_noghtTimeL.textAlignment = NSTextAlignmentLeft;
_big_noghtTimeL.font = [UIFont systemFontOfSize:[UIScreen mainScreen].bounds.size.width/375*13 weight:UIFontWeightRegular];
[self.bigBackView addSubview:self.big_noghtTimeL];
[self.big_noghtTimeL makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.big_weatherImg);
make.left.mas_equalTo(self.big_nightImg.mas_right).offset([UIScreen mainScreen].bounds.size.width/375*6);
}];
_big_toSunsetBackView = [[GWCW_ClubWeatherSunriseView alloc] init];
_big_toSunsetBackView.userInteractionEnabled = NO;
[self.bigBackView addSubview:self.big_toSunsetBackView];
[self.big_toSunsetBackView makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(self.big_dayImg.mas_top).offset(-[UIScreen mainScreen].bounds.size.width/375*5);
make.right.mas_equalTo(self.bigBackView.mas_right).offset(-[UIScreen mainScreen].bounds.size.width/375*(23-5));
make.width.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*(99 + 20 +20 + 20));
make.height.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*50);
}];
self.bigBackView.hidden = YES;
/** 展开时:折线图 */
_chartBackView = [[UIView alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width/375*12.5, [UIScreen mainScreen].bounds.size.width/375*115, [UIScreen mainScreen].bounds.size.width/375*(375-20-20-12.5-12.5), [UIScreen mainScreen].bounds.size.width/375*194)];
self.chartBackView.backgroundColor = RGBA(248, 247, 245, 1);
self.chartBackView.layer.masksToBounds = YES;
self.chartBackView.layer.cornerRadius = [UIScreen mainScreen].bounds.size.width/375*5;
[self.bigBackView addSubview:self.chartBackView];
// [self.chartBackView makeConstraints:^(MASConstraintMaker *make) {
// make.top.mas_equalTo(self.bigBackView.mas_top).offset([UIScreen mainScreen].bounds.size.width/375*115);
// make.left.mas_equalTo(self.bigBackView.mas_left).offset([UIScreen mainScreen].bounds.size.width/375*13)
// make.right.mas_equalTo(self.bigBackView.mas_right).offset(-[UIScreen mainScreen].bounds.size.width/375*13);
// make.height.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*194);
// }];
_chartContentScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width/375*(310), [UIScreen mainScreen].bounds.size.width/375*194)];
self.chartContentScrollView.backgroundColor = [UIColor clearColor];
self.chartContentScrollView.delegate = self;
self.chartContentScrollView.showsHorizontalScrollIndicator = NO;
self.chartContentScrollView.scrollEnabled = YES;
[self.chartBackView addSubview:self.chartContentScrollView];
if (!self.chartContentScrollView.contentSize.width) {
self.chartContentScrollView.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width/375*(50*24 + 8*23), self.chartContentScrollView.frame.size.height);
}
_chartContentView = [[UIView alloc] initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.width/375*(63+23), self.chartContentScrollView.contentSize.width, [UIScreen mainScreen].bounds.size.width/375*58)];
[self.chartContentScrollView addSubview:self.chartContentView];
self.chartContentView.backgroundColor = RGBA(248, 247, 245, 1);
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
layout.sectionHeadersPinToVisibleBounds = NO;
layout.sectionFootersPinToVisibleBounds = NO;
UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.chartContentScrollView.contentSize.width, self.chartContentScrollView.frame.size.height) collectionViewLayout:layout];
// collectionView.backgroundColor = [UIColor clearColor];
collectionView.backgroundColor = RGBA(176, 100, 200, 0.3);
collectionView.delegate = self;
collectionView.dataSource = self;
collectionView.showsVerticalScrollIndicator = NO;
collectionView.scrollEnabled = NO;
[self.chartContentScrollView addSubview:collectionView];
// [collectionView makeConstraints:^(MASConstraintMaker *make) {
// //make.edges.equalTo(self);
// make.top.bottom.equalTo(self);
// make.left.mas_equalTo(self.mas_left).offset([UIScreen mainScreen].bounds.size.width/375*15);
// make.right.mas_equalTo(self.mas_right).offset(-[UIScreen mainScreen].bounds.size.width/375*14);
// }];
[collectionView registerClass:[GWCW_ClubWeatherChildCell class] forCellWithReuseIdentifier:NSStringFromClass([GWCW_ClubWeatherChildCell class])];
self.collectionView = collectionView;
_progressBackView = [[UIView alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width/375*(335-136)/2, [UIScreen mainScreen].bounds.size.width/375*317, [UIScreen mainScreen].bounds.size.width/375*136, [UIScreen mainScreen].bounds.size.width/375*3)];
_progressBackView.backgroundColor = RGBA(248, 247, 245, 1);
self.progressBackView.layer.masksToBounds = YES;
self.progressBackView.layer.cornerRadius = [UIScreen mainScreen].bounds.size.width/375*3/2;
[self.bigBackView addSubview:self.progressBackView];
_progressView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width/375*18, [UIScreen mainScreen].bounds.size.width/375*3)];
self.progressView.backgroundColor = RGBA(255, 196, 15, 1);
self.progressView.layer.masksToBounds = YES;
self.progressView.layer.cornerRadius = [UIScreen mainScreen].bounds.size.width/375*3/2;
[self.progressBackView addSubview:self.progressView];
self.progressBackView.hidden = YES;
self.progressView.hidden = YES;
}
- (void)refreshCollectionView {
[self.collectionView reloadData];
}
#pragma mark -- -- < UICollectionViewDelegate, UICollectionViewDataSource >
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.hourlyModels.count;
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake([UIScreen mainScreen].bounds.size.width/375*50, [UIScreen mainScreen].bounds.size.width/375*193);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
// 水平上下
return [UIScreen mainScreen].bounds.size.width/375*7.9; // 8
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
// 垂直左右
return [UIScreen mainScreen].bounds.size.width/375*1;
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
// section 边界
return UIEdgeInsetsMake([UIScreen mainScreen].bounds.size.width/375*0, [UIScreen mainScreen].bounds.size.width/375*0, [UIScreen mainScreen].bounds.size.width/375*0, [UIScreen mainScreen].bounds.size.width/375*0);
}
- (nonnull __kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
GWCW_ClubWeatherChildCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([GWCW_ClubWeatherChildCell class]) forIndexPath:indexPath];
if (self.hourlyModels.count) {
cell.hourlyModel = self.hourlyModels[indexPath.row];
}
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
GWCW_ClubWeatherChildCell *cell = (GWCW_ClubWeatherChildCell *)[collectionView cellForItemAtIndexPath:indexPath];
}
@end