画图4

简易画板画图


{

//画布用于显示的图层

CAShapeLayer *_layer;

//用于记录移动点路径

UIBezierPath *_beziePath;

}

- (void)viewDidLoad {

[super viewDidLoad];

//

_layer = [CAShapeLayer layer];

_layer.frame = self.view.frame;

_layer.backgroundColor = [UIColorcyanColor].CGColor;

_layer.strokeColor = [UIColororangeColor].CGColor;

_layer.lineWidth = 5;

//@[@10]虚线

//@[@10,@0]实线

_layer.lineDashPattern = @[@10,@0];

_layer.fillColor = [UIColorclearColor].CGColor;

_layer.lineCap = @"round";

_layer.lineJoin = @"round";

[self.view.layer addSublayer:_layer];

_beziePath = [[UIBezierPath alloc] init];

_layer.path =_beziePath.CGPath;

}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

CGPoint point = [[touches anyObject] locationInView:self.view];

[_beziePath moveToPoint:point];

}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

CGPoint point = [[touches anyObject] locationInView:self.view];

[_beziePath addLineToPoint:point];

_layer.path =_beziePath.CGPath;

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥iOS动画全貌。在这里你可以看...
    F麦子阅读 10,533评论 5 13
  • 前言 本文只要描述了iOS中的Core Animation(核心动画:隐式动画、显示动画)、贝塞尔曲线、UIVie...
    GitHubPorter阅读 9,007评论 7 11
  • "小画板程序"完成"小画板"程序。 下载地址:http://git.oschina.net/changyou/my...
    _浅墨_阅读 3,987评论 0 5
  • Core Animation Core Animation,中文翻译为核心动画,它是一组非常强大的动画处理API,...
    45b645c5912e阅读 8,179评论 0 21
  • 《跃迁》是专注生涯规划领域的古典老师的第三本力作,在继《拆掉思维的墙》和《你的生命有什么可能》之后,关于思维,信念...
    幸福快乐针灸师阅读 1,124评论 0 1