美文网首页
最简单的画方画圆 iOS

最简单的画方画圆 iOS

作者: coding_Liu | 来源:发表于2019-07-23 16:47 被阅读0次
//  ViewController.m
//  画方画圆
//
//  Created by Admin on 2019/5/5.
//  Copyright © 2019年 JZY. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@property (nonatomic, strong) UIView *v;

@end

@implementation ViewController

{
    
    CAShapeLayer *shapeLayer;
    CGPoint startPoint;
    CGPoint endPoint;

}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview: self.v];
    self.v.frame = CGRectMake(50, 50, 200, 200);
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    shapeLayer = [CAShapeLayer new];
    shapeLayer.backgroundColor = [UIColor purpleColor].CGColor;
    shapeLayer.fillColor = [UIColor whiteColor].CGColor; //填充颜色
    shapeLayer.strokeColor = [UIColor redColor].CGColor; //边框颜色
    shapeLayer.lineWidth = 2.0f; //边框的宽度
    [self.v.layer addSublayer:shapeLayer];
    self.v.layer.backgroundColor = UIColor.greenColor.CGColor;
    
    UITouch *touch  = [touches anyObject];
    startPoint = [touch locationInView:self.v];
//    UIBezierPath *bezierPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(80, 150) radius:80 startAngle:0 endAngle:M_PI*2 clockwise:YES];
//    shapeLayer.path = bezierPath.CGPath;
}

- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
   
    UITouch *touch  = [touches anyObject];
    endPoint = [touch locationInView:self.v];

    UIBezierPath *bezierPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(startPoint.x, startPoint.y, endPoint.x - startPoint.x, endPoint.y - startPoint.y)];

    
    //bezierPathWithOvalInRect 圆
//    bezierPathWithRect 方
    
    
    
    
    
//    UIBezierPath *bezierPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(point.x, point.y) radius:80 startAngle:0 endAngle:M_PI*2 clockwise:YES];

    shapeLayer.path = bezierPath.CGPath;

}

- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
}

- (UIView *)v {
    if (!_v) {
        _v = [UIView new];
        _v.backgroundColor = [UIColor grayColor];
    }
    return _v;
}

@end

相关文章

  • 最简单的画方画圆 iOS

  • ios绘图基础

    ios常见的图形绘制 画线 画圆、圆弧 画矩形,画椭圆,多边形 画图片 画文字 1:ios绘图基础 几个基本的概念...

  • iOS多线程 之 GCD 四个心法 七个招式

    左手画方 右手画圆 “少侠,你能左手画方,又手画圆吗?” “这有何难,开始看我表演吧” “看,怎么样,厉害吧” “...

  • 左手画圆,右手画方

    小龙女和周伯通因遭经轮法王和坏道士赵志平的陷害,被困一个山洞里,为了突围,老顽童跟小龙女提起了一个他自创的很厉害的...

  • 左手画圆右手画方

    我本将心向明月,奈何明月照沟渠。 “啪!明月啦!啪!沟渠啦!看我不把你打得落花流水。给我记住,我不是明月,你也不是...

  • 自定义控件-绘制顺序

    Android 里面的绘制都是按顺序的,先绘制的内容会被后绘制的盖住。比如你在重叠的位置先画圆再画方,和先画方再画...

  • 成长

    右手画圆,左手画方,不能两成。 ﹎﹎﹎《韩非子》 “师父,可以了吧?都...

  • 2018-12-01【张进的美术评论和诗】具象

    文/张进 把一个圆画圆 把一个方画方 把太阳画在天上 让蓝天选择一种最蓝的颜色 鱼的大小 马的大小 青春的大小 士...

  • 老顽童:双手互博之术

    左手画圆,右手画方,当左脑遇上右脑,会发生什么有趣的事情呢? 在看《神雕英雄传》时,我最佩服的就是周伯通的双手互博...

  • canvas实用手册

    手册地址 canvas API比较简单 context是主要的操作对象 划线操作 画圆弧 画矩形的接口[仅画路径]...

网友评论

      本文标题:最简单的画方画圆 iOS

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