zoukankan      html  css  js  c++  java
  • 简单的画板

    #import "MyView.h"
    @interface MyView ()
    {
        CGMutablePathRef pathRef;
    }
    @end
    @implementation MyView
    -(id)initWithCoder:(NSCoder *)aDecoder
    {
        if (self=[super initWithCoder:aDecoder])
        {
            pathRef=CGPathCreateMutable();
           
        }
        return self;
        
    }
    -(void)drawRect:(CGRect)rect
    {
        CGContextRef contextRef=UIGraphicsGetCurrentContext();
        CGContextAddPath(contextRef, pathRef);
        CGContextStrokePath(contextRef);
        
    }
    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        CGPoint p=[touches.anyObject locationInView:self];
        CGPathMoveToPoint(pathRef, nil, p.x, p.y);
        
    }
    -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    {
        CGPoint p=[touches.anyObject locationInView:self];
        CGPathAddLineToPoint(pathRef, nil, p.x, p.y);
        [self setNeedsDisplay];
    }
    @end
  • 相关阅读:
    和为S的连续正数序列
    数组中只出现一次的数字
    平衡二叉树
    二叉树的深度
    水仙花数
    数列求和
    数值统计
    奇数乘积
    求绝对值
    求两点的距离
  • 原文地址:https://www.cnblogs.com/thbbsky/p/4382411.html
Copyright © 2011-2022 走看看