美文网首页
iOS简单的画板

iOS简单的画板

作者: Desert_Eagle | 来源:发表于2018-02-11 16:55 被阅读0次
#import "ViewController.h"

@interface ViewController ()

@property (nonatomic, strong) CAShapeLayer *shapeLayer;
@property (nonatomic, strong) UIBezierPath *path;
@end

@implementation ViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.shapeLayer = [CAShapeLayer layer];
    self.shapeLayer.frame = self.view.bounds;
    self.shapeLayer.strokeColor = [UIColor redColor].CGColor;
    self.shapeLayer.fillColor = [UIColor clearColor].CGColor;
    self.shapeLayer.lineJoin = kCALineJoinRound;
    self.shapeLayer.lineCap = kCALineCapRound;
    self.shapeLayer.lineWidth = 5;
    [self.view.layer addSublayer:_shapeLayer];
    
    self.path = [[UIBezierPath alloc] init];
    
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    CGPoint point = [[touches anyObject] locationInView:self.view];
    [self.path moveToPoint:point];
}

- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    CGPoint point = [[touches anyObject] locationInView:self.view];
    [self.path addLineToPoint:point];
    
    self.shapeLayer.path = self.path.CGPath;
}


@end

相关文章

网友评论

      本文标题:iOS简单的画板

      本文链接:https://www.haomeiwen.com/subject/sdfltftx.html