我试图让石英2D手柄和看在线图书石英2D图形的Mac OS X开发 。
这是混淆了我一个非常基本的东西是CGContext上。 例如,我可以得出用下面的代码一个简单的“U”形,并在使用它CAShapeLayer
而不引用CGContext
。 是上下文暗示/默认情况下由提供CAShapeLayer
?
我可能在这里混了几个的iOS / OSX图形API,所以也许有人能澄清我要去的地方错了。
CGPoint pt1 = CGPointMake(100, 100);
CGPoint pt2 = CGPointMake(150, 100);
CGPoint pt3 = CGPointMake(150, 200);
CGPoint pt4 = CGPointMake(190, 200);
CGPoint pt5 = CGPointMake(190, 100);
CGPoint pt6 = CGPointMake(210, 100);
CGPoint pt7 = CGPointMake(210, 250);
CGPoint pt8 = CGPointMake(100, 250);
CGPoint pt9 = CGPointMake(100, 100);
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, nil, pt1.x,pt1.y);
CGPathAddLineToPoint(path, nil, pt2.x, pt2.y);
CGPathAddLineToPoint(path, nil, pt3.x, pt3.y);
CGPathAddLineToPoint(path, nil, pt4.x, pt4.y);
CGPathAddLineToPoint(path, nil, pt5.x, pt5.y);
CGPathAddLineToPoint(path, nil, pt6.x, pt6.y);
CGPathAddLineToPoint(path, nil, pt7.x, pt7.y);
CGPathAddLineToPoint(path, nil, pt8.x, pt8.y);
CGPathAddLineToPoint(path, nil, pt9.x, pt9.y);
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
[self.view.layer addSublayer:shapeLayer];