目前,我正在使用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];
}但是对我来说,注意到改变了,我仍然有一条丑陋的路。
有什么建议吗?
谢谢你的回答。
详情如下:
创建一个可可应用程序(而不是document-based)
)
StretchView.h
#import <Cocoa/Cocoa.h>
@interface StretchView : NSView {
NSBezierPath *path;
}
-(void)myTimerAction:(NSTimer *) timer;
@endStretchView.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];
}
@end3.打开接口生成器并将“滚动视图”拖动到主窗口
4.选择“滚动视图”并设置类"StretchView“(在类标识窗口中)
发布于 2011-06-30 06:03:34
使用lineToPoint只会创建直线,甚至作为bezier路径的一部分。如果你所说的“平滑”指的是“曲线”,那么你应该去看看curveToPoint。另外,请注意,这些"toPoint“方法已经移动了点,除非您打算移动到与行结束位置不同的点,否则不需要使用moveToPoint。
https://stackoverflow.com/questions/4871278
复制相似问题