【发布时间】:2014-02-06 16:23:10
【问题描述】:
我第一次体验CALayers,毫无疑问我在做一些非常简单、非常错误的事情。
以下代码位于从UIView 扩展的类中。我正在访问视图的 CALayer,这很好,并尝试根据用户触摸绘制的线附加子层。 (CGPath)
通过将背景设置为亮橙色,我可以看到我将正确的 CALayer 传递到我的函数中,但是如果我尝试将 CAShapeLayer *line 设置为橙色 - 我似乎无法在屏幕上看到它。
我在想我把这两者联系在一起是错误的,或者错过了定义一些大小或其他东西,但我没有什么东西可以尝试。谁能直截了当?
(void)makeLineLayer:(CALayer *)layer{
CAShapeLayer *line = [CAShapeLayer layer];
//This line sets the view to orange - so I know 'layer' is pointing to the right thing
//layer.backgroundColor = [UIColor orangeColor].CGColor;
UIBezierPath *linePath=[UIBezierPath bezierPath];
[linePath moveToPoint:self.lineStart];
[linePath addLineToPoint:self.lineEnd];
[linePath setLineWidth:60.0];
line.path=linePath.CGPath;
//This below line is meant to show me where my sublayer is - I currently can't see it.
line.fillColor = [UIColor orangeColor].CGColor;
line.opacity = 1.0;
[layer addSublayer:line];
}
【问题讨论】:
标签: ios objective-c cocoa-touch calayer cashapelayer