NSView上的NSBezierPath没有正确排列

时间:2013-08-08 16:11:56

标签: cocoa nsview nsbezierpath

我有一个带有NSView的NSWindow(存储在笔尖中):

enter image description here

我正在尝试将BezierPath添加到该视图的图层(self.view2):

CAShapeLayer* circleLayer = [CAShapeLayer layer];
[self.view2 setLayer:circleLayer];

circleLayer.fillColor = [NSColor redColor].CGColor;
circleLayer.path = [NSBezierPath bezierPathWithOvalInRect:self.view2.bounds].quartzPath;
circleLayer.strokeColor = [NSColor blueColor].CGColor;
circleLayer.strokeStart = 0.0f;
circleLayer.strokeEnd = 0.5f;
circleLayer.lineWidth = 5.0f;
circleLayer.transform = CATransform3DMakeRotation(135.0 / 180.0 * M_PI, 0.0, 0.0, 1.0);

这就是我的回忆:

enter image description here

为什么生成的视图不能正确对齐(即,在我的笔尖上方的右上角)?

1 个答案:

答案 0 :(得分:0)

我只需要将代码放在awakeFromNib()而不是applicationDidFinishLaunching()中。现在它有效。