如何检测用户绘制的是圆形正方形还是字母如“Z”?

时间:2015-09-08 14:49:46

标签: ios objective-c uibezierpath quartz-core

我试图在不释放手指的情况下绘制一个图形,当我释放手指时,我想比较那个形状,看它是一条线,一个圆圈,一个正方形还是让我们说一个“Z”。

我对绘画和类似的东西都是新手,所以我不知道如何制作它。

我正在使用以下代码:

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

    mouseSwiped = NO;
    UITouch *touch = [touches anyObject];
    lastPoint = [touch locationInView:self.view];
}

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

    mouseSwiped = YES;
    UITouch *touch = [touches anyObject];
    CGPoint currentPoint = [touch locationInView:self.view];

    UIGraphicsBeginImageContext(self.view.frame.size);
    [self.mainImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), brush );
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), red, green, blue, 1.0);
    CGContextSetBlendMode(UIGraphicsGetCurrentContext(),kCGBlendModeNormal);

    CGContextStrokePath(UIGraphicsGetCurrentContext());
    self.mainImage.image = UIGraphicsGetImageFromCurrentImageContext();
    [self.mainImage setAlpha:opacity];
    UIGraphicsEndImageContext();

    lastPoint = currentPoint;


//    [CGRect.testForCircle(, <#NSDate *firstTouchDate#>)]
}

我的问题是:如何检测是什么画的是正方形或“Z”的圆圈?

欢迎提出意见/建议/代码! 谢谢!

0 个答案:

没有答案