如何在触摸屏上在屏幕上绘制点 [英] How can I draw a dot on the screen on touchesEnded using UIBezierpath

查看:70
本文介绍了如何在触摸屏上在屏幕上绘制点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有人可以告诉我如何使用UIBezierpath绘制单个点吗?我可以使用UIBezierpath画一条线,但是如果我松开手指然后放回去,然后又什么也没画,就会在屏幕上画出线条.

Can someone here please show me how to draw a single dot using UIBezierpath? I am able to draw a line using the UIBezierpath but if I remove my finger and put it back and then remove nothing get drawn on the screen.

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint p = [touch locationInView:self];
    [pPath moveToPoint:p];
    [pPath stroke];
    [self setNeedsDisplay];
}

- (void)drawRect:(CGRect)rect
{
     [pPath stroke];
}

推荐答案

您的路径不包含任何要描边的线段或曲线段.

Your path doesn't include any line or curve segments to be stroked.

尝试以下方法:

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    CGPoint p = [touches.anyObject locationInView:self];
    static CGFloat const kRadius = 3;
    CGRect rect = CGRectMake(p.x - kRadius, p.y - kRadius, 2 * kRadius, 2 * kRadius);
    pPath = [UIBezierPath bezierPathWithOvalInRect:rect];
    [self setNeedsDisplay];
}

- (void)drawRect:(CGRect)rect {
    [[UIColor blackColor] setFill];
    [pPath fill];
}

这篇关于如何在触摸屏上在屏幕上绘制点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆