1

UIBezierPath と-touches...UIView のメソッドを使用して簡単な描画コードを作成しました。絵はうまくいきますが、私はいくつかの悪い経験をしました.

  1. 私が非常にゆっくりと絵を描いているとき、それはうまく機能します。しかし、速く描けば描くほど、線はエッジの効いたものになります。では、それらを「滑らか」にしてエッジの効かない(ポイントを増やす)にはどうすればよいですか?

  2. setLineWidth太い線幅で使用すると、線が非常に醜くなります。

これは、醜いが実際に 何を意味するかを示す画像です。これが実際に意味するのは

なんであんなに太い線が引けるの!?

編集:ここにいくつかのコード

- (void)drawInRect:(CGRect)rect
{
    for(UIBezierPath *path in pathArray) {
        [[UIColor blackColor] setStroke];
        [path setLineWidth:50.0];
        [path stroke];
    }
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    startPoint = [[touches anyObject] locationInView:self];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:startPoint];
    [path addLineToPoint:[[touches anyObject] locationInView:self]];
    if(isDrawing) {
        [pathArray removeLastObject];
    }
    else {
        isDrawing = YES;
    }
    [pathArray addObject:path];
    [path close];
    [self setNeedsDisplay];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    isDrawing = NO;
}

誰かがこれらの問題で私を助けてくれることを願っています。どうもありがとう、よろしく、ジュリアン

4

1 に答える 1

1

Mmmmh, I'm not going to address performance issues with your implementation in this thread, but take a look at setNeedsDisplayInRect: in UIView once you get the basics working.

I think you're basically trying to take out the last created path from your array and replace it with a new one for as long as you're moving.

You should try to put a CGMutablePathRef in your array instead (take a look here for that CGMutablePathRef to NSMutableArray).

The basic flow would be something like:

  1. touchesBegan:

    1. Create the CGMutablePathRef
    2. Call moveToPoint
    3. Store in the array
  2. touchesMoved:

    1. Get the lastObject from your array (i.e. the CGMutablePathRef)
    2. Call addLineToPoint
    3. [self setNeedsDisplay]

Then in drawInRect, iterate through your paths and paint them.

Again, this will be slow at first, then you need to optimize. CGLayerRef can help. setNeedsDisplayInRect most definitely will also.

于 2012-05-04T12:14:47.220 に答える