画图2

定时器画图


- (id)initWithFrame:(CGRect)frame {

self= [super initWithFrame:frame];

if(self) {

_movePoint= CGPointMake(10, 10);

_linePoint = CGPointMake(10, 10);

[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(onTimer) userInfo:nil repeats:YES];

}

return self;

}

- (void)onTimer {

CGPoint movePoint =_movePoint;

movePoint.x += 10;

movePoint.y += 10;

_movePoint = movePoint;

CGPoint linePoint = _linePoint;

linePoint.x += 5;

linePoint.y += 20;

_linePoint = linePoint;

//调用drawRect方法重新绘制

[self setNeedsDisplay];

}

- (void)drawRect:(CGRect)rect {

[super drawRect:rect];

//创建画布获取当前画板

CGContextRefcontext = UIGraphicsGetCurrentContext();

CGContextSetLineWidth(context, 10);

CGContextSetRGBStrokeColor(context, 1, 1, 0, 1);

CGContextSetLineJoin(context,kCGLineJoinRound);

CGContextMoveToPoint(context,_movePoint.x,_movePoint.y);

CGContextAddLineToPoint(context,_linePoint.x,_linePoint.y);

CGContextStrokePath(context);

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Quartz2D以及drawRect的重绘机制字数1487 阅读21 评论1 喜欢1一、什么是Quartz2D Q...
    PurpleWind阅读 4,243评论 0 3
  • #define kBlackColor [UIColor blackColor] //.h //划线 + (voi...
    CHADHEA阅读 4,198评论 0 1
  • --绘图与滤镜全面解析 概述 在iOS中可以很容易的开发出绚丽的界面效果,一方面得益于成功系统的设计,另一方面得益...
    韩七夏阅读 7,813评论 2 10
  • 时常听到有朋友跟我说起某某某:“她怎么就能那么肆无忌惮呢?起个床的声音巴不得把整栋楼都掀了!跟个男生一样。”又或是...
    杰西娅阅读 4,556评论 0 1
  • 理由,借口,推脱责任的事由,是对做错一件事情的心理慰藉,责任的逃避使自己更加的脆弱和颓废。 勇于承担责任,活出一个自我。
    颜燚阅读 1,943评论 0 0