現在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];
}
しかし、私にとっては、変更されたことに注意してください、私はまだ醜い道を歩んでいます。
なにか提案を?
ご回答ありがとうございます。
詳細は次のとおりです。
- cocoa アプリケーションを作成する (ドキュメントベースではない)
- 新しいクラス「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 ウィンドウで)。