簡體   English   中英

如何使用UIBezierpath在touchesEnded上在屏幕上繪制一個點

[英]How can I draw a dot on the screen on touchesEnded using UIBezierpath

有人可以告訴我如何使用UIBezierpath繪制一個點嗎? 我可以使用UIBezier路徑繪制一條線,但是如果我移開手指並將其放回去,則移除屏幕上的任何內容。

- (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];
}

您的路徑不包括要描邊的任何線段或曲線段。

試試這個:

- (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];
}

我用過這段代碼:

 -(void)handleTap:(UITapGestureRecognizer*)singleTap { 
     //draw dot on screen

     CGPoint tapPoint = [singleTap locationInView:self];
     [bezierPath_ moveToPoint:tapPoint];
     [bezierPath_ addLineToPoint:tapPoint];

     [self setNeedsDisplay]; 
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM