123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- //
- // AFView.m
- // animationFrame
- //
- // Created by pingshw on 14-5-27.
- // Copyright (c) 2014年 pingshw. All rights reserved.
- //
- #import "AFView.h"
- #import "AFDescribeObj.h"
- @interface CCView : UIView
- @end
- @implementation AFView
- {
- CGFloat w;
- CGFloat h;
- }
- @synthesize min_Y;
- @synthesize max_Y;
- @synthesize min_X;
- @synthesize max_X;
- @synthesize data;
- @synthesize x_labels;
- @synthesize y_labels;
- - (id)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- w = frame.size.width;
- h = frame.size.height;
-
- //背景色
- // self.backgroundColor = RQMianColor;
- }
- return self;
- }
- - (void)setData:(NSArray *)_data
- {
- data = [NSArray arrayWithArray:_data];
-
- // NSString* imgName = @"question_index_bg.png";
- CGFloat startTime = .5f;
- // UIImageView *iv;
-
- UIColor* lineCol = [UIColor whiteColor];
-
- CGFloat imgw = 12;
- CGPoint e;
- UIView* ccv;
- if (_data.count >0) {
- e = [data[0] CGPointValue];
- if (max_X == min_X) {
- //如果只有一个点 就把点放中间
- e.x = w / 2.0;
- }else{
- e.x = (e.x - min_X)*0.8*w/(max_X - min_X) + 0.125*w;
- }
-
- e.y = 0.875*h - (e.y - min_Y)*0.8*h/(max_Y - min_Y);
- ccv = [[CCView alloc] initWithFrame:CGRectMake(0, 0, imgw, imgw)];
- [self addSubview:ccv];
- ccv.center = e;
- }
-
- for (int i=1; i<data.count; i++)
- {
-
- CGPoint s = [data[i-1] CGPointValue];
- CGPoint e = [data[i] CGPointValue];
-
- s.x = (s.x - min_X)*0.8*w/(max_X - min_X) + 0.125*w;
- s.y = 0.875*h - (s.y - min_Y)*0.8*h/(max_Y - min_Y);
- e.x = (e.x - min_X)*0.8*w/(max_X - min_X) + 0.125*w;
- e.y = 0.875*h - (e.y - min_Y)*0.8*h/(max_Y - min_Y);
-
- AFDescribeObj *desObj = [[AFDescribeObj alloc] initWithType:AFAnimationStrokeEnd inView:self];
- [desObj setStartTime:startTime andDuration:1.5f/data.count];//用1.5S来画线
- [desObj addLineFrom:s toPoint:e color:lineCol];
- startTime += 0.5f;
-
- ccv = [[CCView alloc] initWithFrame:CGRectMake(0, 0, imgw, imgw)];
- [self addSubview:ccv];
- ccv.center = e;
- // [ccArr addObject:ccv];
- }
-
- // for (UIView* v in ccArr) {
- // [self bringSubviewToFront:v];
- // }
- }
- - (void)setX_labels:(NSArray *)_x_labels
- {
- x_labels = [NSArray arrayWithArray:_x_labels];
- CGFloat num = ((CGFloat)x_labels.count)-1.0;
- if (num == 0.0) {
- num = 2.0f;
- }
- CGFloat x_interval = 0.8*w/num;
-
- UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0.9*h, w, 0.1*h)];
- v.alpha = 0;
-
- for (int i=0; i<x_labels.count; i++)
- {
- NSString *str = x_labels[i];
- if (x_labels.count == 1) {
- //如果只有一个点 将label放中间
- i ++;
- }
- UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0.025*w+i*x_interval, 0, 0.2*w, 0.1*h)];
- label.backgroundColor = [UIColor clearColor];
- label.textAlignment = NSTextAlignmentCenter;
- label.font = [UIFont scaleSize:16.0];
- label.text = str;
- [v addSubview:label];
- [label setTextColor:[UIColor whiteColor]];
- }
-
- [self addSubview:v];
- [UIView animateWithDuration:1.5f
- animations:^{
- v.alpha = 1;
- }];
- }
- - (void)setY_labels:(NSArray *)_y_labels
- {
- y_labels = [NSArray arrayWithArray:_y_labels];
- CGFloat num = ((CGFloat)y_labels.count)-1.0;
- CGFloat y_interval = 0.8*h/num;
-
- CGFloat wid = .2*w;
- UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, wid, h)];
- v.alpha = 0;
-
- for (int i=0; i<y_labels.count; i++)
- {
- NSString *str = y_labels[y_labels.count- 1 - i];
- UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(5, 0.875*h - 6 - y_interval*i, wid, w/28.0)];
- [label setFrame:CGRectMake(5,h*.78- h/7.0*i, wid, h/7.0)];
- label.backgroundColor = [UIColor clearColor];
- label.textAlignment = NSTextAlignmentLeft;
- label.font = [UIFont scaleSize:16.0];
- label.text = str;
- [v addSubview:label];
- [label setTextColor:[UIColor whiteColor]];
-
- CGFloat hei = h*.95;
- UIView*v = [[UIView alloc] initWithFrame:CGRectMake(0.1*w,.08*hei+hei*1.0/y_labels.count*i, w, 1)];
- [v setBackgroundColor:RGBA_COLOR(240, 240, 240, 1)];//[UIColor colorWithRed:240 green:240 blue:240 alpha:1]
- [self addSubview:v];
-
- label.center = CGPointMake(label.center.x, v.y);
- }
-
- [self addSubview:v];
- [UIView animateWithDuration:1.5f
- animations:^{
- v.alpha = 1;
- }];
- }
- @end
- @implementation CCView
- -(instancetype)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- [self setBackgroundColor:[UIColor clearColor]];
- }
- return self;
- }
- -(void)drawRect:(CGRect)rect
- {
- //圆的线条宽度
- CGFloat lw = 2;
- UIColor *color = [UIColor whiteColor];
- [color set];//设置线条颜色
- CGFloat d = self.frame.size.width * .8;
- CGFloat x = (self.frame.size.width - d)/2.0;
- UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(x, x, d, d)];
- path.lineWidth = lw;
- [path stroke];//空心的图形
- }
- @end
|