0

現在NSBezierPathでパスを排出しています:

- (void)drawRect:(NSRect)dirtyRect 
{
    [[NSColor blueColor] set];
    [path stroke];
}

しかし、線はかなり醜いようです(滑らかではありません)

次に、いくつかの解決策をグーグルで検索したところ、次のようになりました。

- (void)drawRect:(NSRect)dirtyRect 
{
    NSGraphicsContext *graphicsContext;
    BOOL oldShouldAntialias;

    graphicsContext = [NSGraphicsContext currentContext];
    oldShouldAntialias = [graphicsContext shouldAntialias];
    [graphicsContext setShouldAntialias:NO];

    [[NSColor blueColor] set];
    [path stroke];

    [graphicsContext setShouldAntialias:oldShouldAntialias];
}

しかし、私にとっては、変更されたことに注意してください、私はまだ醜い道を歩んでいます。

なにか提案を?

ご回答ありがとうございます。

詳細は次のとおりです。

  1. cocoa アプリケーションを作成する (ドキュメントベースではない)
  2. 新しいクラス「StretchView」を作成します

StretchView.h

#import <Cocoa/Cocoa.h>

@interface StretchView : NSView {

    NSBezierPath *path;
}

-(void)myTimerAction:(NSTimer *) timer;

@end

StretchView.m

#import "StretchView.h"

@implementation StretchView

- (id)initWithFrame:(NSRect)frame 
{
    self = [super initWithFrame:frame];
    if (self) {

        path = [[NSBezierPath alloc] init]; 
        NSPoint p = CGPointMake(0, 0); 
        [path moveToPoint:p]; 
        myTimer = [NSTimer scheduledTimerWithTimeInterval:1.0
                                                   target:self
                                                 selector:@selector(myTimerAction:)
                                                 userInfo:nil
                                                  repeats:YES];
    }
    return self;
}

- (void)drawRect:(NSRect)dirtyRect 
{
    NSLog(@"drawRect");

    [[NSColor blueColor] set];
    [path stroke];
}

-(void)myTimerAction:(NSTimer *) timer
{  
    NSPoint p = CGPointMake(a, b); //a, b is random int val
    [path lineToPoint:p]; 
    [path moveToPoint:p]; 
    [path closePath];

    [self setNeedsDisplay:YES];
} 

-(void)dealloc
{
    [path release]; 
    [super dealloc];
}

@end

3.Interface Builder を開き、「スクロール ビュー」をメイン ウィンドウにドラッグします
。 4.「スクロール ビュー」を選択し、クラス「StretchView」を設定します (クラス ID ウィンドウで)。

4

1 に答える 1

0

を使用lineToPointすると、ベジェパスの一部としても、直線のジグザグ線が作成されます。「スムーズ」が「曲線」を意味する場合は、curveToPoint代わりにチェックアウトする必要があります。また、これらの「toPoint」メソッドはすでにポイントを移動していることに注意してmoveToPointください。ラインが終了した場所とは別のポイントに移動する場合を除いて、移動する必要はありません。

于 2011-06-30T06:03:34.770 に答える