Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
hapiii committed Aug 9, 2019
1 parent 03d9116 commit 4665b01
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 87 deletions.
6 changes: 0 additions & 6 deletions Example/HPThemeKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
6003F5BC195388D20070C39A /* Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6003F5BB195388D20070C39A /* Tests.m */; };
B5FC8FEC22FD5584000E7B32 /* QFLineView.m in Sources */ = {isa = PBXBuildFile; fileRef = B5FC8FE622FD5581000E7B32 /* QFLineView.m */; };
B5FC8FED22FD5584000E7B32 /* QFLineModel.m in Sources */ = {isa = PBXBuildFile; fileRef = B5FC8FE822FD5582000E7B32 /* QFLineModel.m */; };
B5FC8FEE22FD5584000E7B32 /* QFLineRowView.m in Sources */ = {isa = PBXBuildFile; fileRef = B5FC8FE922FD5583000E7B32 /* QFLineRowView.m */; };
B5FC8FF122FD55F2000E7B32 /* HPLineController.m in Sources */ = {isa = PBXBuildFile; fileRef = B5FC8FF022FD55F2000E7B32 /* HPLineController.m */; };
BFB480A221FE9B74003DF07B /* HPCardsController.m in Sources */ = {isa = PBXBuildFile; fileRef = BFB4809921FE9B74003DF07B /* HPCardsController.m */; };
BFB480A321FE9B74003DF07B /* HPUserController.m in Sources */ = {isa = PBXBuildFile; fileRef = BFB4809B21FE9B74003DF07B /* HPUserController.m */; };
Expand Down Expand Up @@ -74,9 +73,7 @@
B5FC8FE622FD5581000E7B32 /* QFLineView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QFLineView.m; sourceTree = "<group>"; };
B5FC8FE722FD5582000E7B32 /* QFLineModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QFLineModel.h; sourceTree = "<group>"; };
B5FC8FE822FD5582000E7B32 /* QFLineModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QFLineModel.m; sourceTree = "<group>"; };
B5FC8FE922FD5583000E7B32 /* QFLineRowView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QFLineRowView.m; sourceTree = "<group>"; };
B5FC8FEA22FD5583000E7B32 /* QFLineView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QFLineView.h; sourceTree = "<group>"; };
B5FC8FEB22FD5584000E7B32 /* QFLineRowView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QFLineRowView.h; sourceTree = "<group>"; };
B5FC8FEF22FD55F2000E7B32 /* HPLineController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HPLineController.h; sourceTree = "<group>"; };
B5FC8FF022FD55F2000E7B32 /* HPLineController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HPLineController.m; sourceTree = "<group>"; };
BFB4809821FE9B74003DF07B /* HPHomeController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HPHomeController.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -233,8 +230,6 @@
children = (
B5FC8FE722FD5582000E7B32 /* QFLineModel.h */,
B5FC8FE822FD5582000E7B32 /* QFLineModel.m */,
B5FC8FEB22FD5584000E7B32 /* QFLineRowView.h */,
B5FC8FE922FD5583000E7B32 /* QFLineRowView.m */,
B5FC8FEA22FD5583000E7B32 /* QFLineView.h */,
B5FC8FE622FD5581000E7B32 /* QFLineView.m */,
B5FC8FEF22FD55F2000E7B32 /* HPLineController.h */,
Expand Down Expand Up @@ -475,7 +470,6 @@
6003F59A195388D20070C39A /* main.m in Sources */,
BFB480A221FE9B74003DF07B /* HPCardsController.m in Sources */,
BFB480C021FF0A1C003DF07B /* HPTabbarController.m in Sources */,
B5FC8FEE22FD5584000E7B32 /* QFLineRowView.m in Sources */,
B5FC8FF122FD55F2000E7B32 /* HPLineController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
1 change: 1 addition & 0 deletions Example/HPThemeKit/Controllers/LineView/HPLineController.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ - (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor grayColor];

[self.iv removeFromSuperview];
[self loadData];

[self setupUI];
Expand Down
19 changes: 0 additions & 19 deletions Example/HPThemeKit/Controllers/LineView/QFLineRowView.h

This file was deleted.

40 changes: 0 additions & 40 deletions Example/HPThemeKit/Controllers/LineView/QFLineRowView.m

This file was deleted.

65 changes: 43 additions & 22 deletions Example/HPThemeKit/Controllers/LineView/QFLineView.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

#import "QFLineView.h"
#import "QFLineModel.h"
#import <YYKit/UIView+YYAdd.h>
#import "QFLineRowView.h"

@interface QFLineView ()

Expand All @@ -27,18 +25,18 @@ @implementation QFLineView{
- (instancetype)initWithFrame:(CGRect)frame{

if (self = [super initWithFrame:frame]) {
_rowWidth = frame.size.width/7.0f;
_rowWidth = frame.size.width/7.0f;
_lineHeight = frame.size.height -35;
[self configUI];

[self configUI];
}
return self;
}

- (void)configUI{

self.showsHorizontalScrollIndicator = NO;

[self setBackgroundColor:[UIColor whiteColor]];

[self addSubview:self.tipLabel];
Expand All @@ -61,7 +59,7 @@ - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
if (remainder>=_rowWidth/2) {
row++;
}

CGPoint point = CGPointMake(_rowWidth/2+_rowWidth*row, _lineHeight*(1-[_dataArr[row].pointHeight floatValue]/_maxHeight));
self.tipLabel.text = [NSString stringWithFormat:@"学习了%@小时",_dataArr[row].pointHeight];
self.tipLabel.textAlignment = NSTextAlignmentCenter;
Expand All @@ -86,15 +84,47 @@ - (void)setDataArr:(NSArray<QFLineModel *> *)dataArr{
}

self.contentSize = CGSizeMake(dataArr.count*_rowWidth, self.frame.size.height);


UIBezierPath *path=[UIBezierPath bezierPath];
CAShapeLayer *layer=[CAShapeLayer layer];

CGPoint prePoint;
CGPoint nowPoint;

for (int i = 0; i<dataArr.count; i++) {

[self configLineUIWithIndex:i];

CGPoint point = CGPointMake(_rowWidth/2+_rowWidth*i, _lineHeight*(1-[_dataArr[i].pointHeight floatValue]/_maxHeight));
if (i == 0) {
prePoint = point;
[path moveToPoint:prePoint];
}else{

nowPoint = point;

[path addCurveToPoint:nowPoint controlPoint1:CGPointMake((prePoint.x+nowPoint.x)/2.0, prePoint.y) controlPoint2:CGPointMake((prePoint.x+nowPoint.x)/2.0, nowPoint.y)];

prePoint=nowPoint;
}
}

layer.path = path.CGPath;
layer.strokeColor = [UIColor colorWithRed:233/255.0f green:78/255.0f blue:92/255.0f alpha:1].CGColor;
layer.fillColor = [UIColor clearColor].CGColor;
layer.lineWidth = 3;

CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"strokeEnd"];
animation.fromValue=@(0);
animation.toValue=@(1);
animation.duration=6;
[layer addAnimation:animation forKey:nil];
animation.fillMode=kCAFillModeForwards;
animation.removedOnCompletion=NO;

[self.layer addSublayer:layer];
[self addSubview:self.tipLabel];
[self bringSubviewToFront:self.tipLabel];

}

///获取Y轴最高点
Expand All @@ -112,24 +142,15 @@ - (CGFloat )getTheMaxPointHeight:(NSArray<QFLineModel *> *)dataArr{
///ROW UI
- (void)configLineUIWithIndex:(NSInteger)i{

QFLineModel *model = _dataArr[i];

QFLineModel *model = _dataArr[i];
CGPoint point = CGPointMake(_rowWidth/2+_rowWidth*i, _lineHeight*(1-[_dataArr[i].pointHeight floatValue]/_maxHeight));

//线
CAShapeLayer *line = [CAShapeLayer layer];
line.frame = CGRectMake(point.x, 10, 0.55,_lineHeight);
line.backgroundColor = [UIColor lightGrayColor].CGColor;

if (i<_dataArr.count-1) {//折线Line

CGPoint endPoint = CGPointMake(_rowWidth/2+_rowWidth*i, _lineHeight*(1-[_dataArr[i+1].pointHeight floatValue]/_maxHeight));

QFLineRowView *view = [[QFLineRowView alloc] initWithFrame:CGRectMake(point.x, 0,_rowWidth , line.frame.size.height) headPoint:point endPoint:endPoint];
[self addSubview:view];

}

//X轴文字
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 15)];
label.text = model.pointTime;
Expand All @@ -139,7 +160,7 @@ - (void)configLineUIWithIndex:(NSInteger)i{
//
UIView *pointView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 5)];
pointView.center = point;
pointView.backgroundColor = [UIColor redColor];
pointView.backgroundColor = [UIColor colorWithRed:233/255.0f green:78/255.0f blue:92/255.0f alpha:1];

[self addSubview:label];
[self.layer addSublayer:line];
Expand Down
Binary file modified imgs/line.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4665b01

Please sign in to comment.