tra*_*uan 1 cocoa-touch objective-c calayer cashapelayer ios
我正在CAShapeLayer
使用 CAShapeLayer 创建一个图层,如下所示:
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.frame = CGRectMake(150, 50, 200, 200);
shapeLayer.fillColor = [UIColor whiteColor].CGColor;
shapeLayer.strokeColor = [UIColor orangeColor].CGColor;
[self.view.layer addSublayer:shapeLayer];
Run Code Online (Sandbox Code Playgroud)
但是,当我执行代码时,shapeLayer
在模拟器/设备中看不到我的代码。
我在这里缺少什么。
PS:如果我使用CALayer *shapeLayer = [CALayer layer];
它有效。困惑
添加一条路径,比如
shapeLayer.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 2.0*radius, 2.0*radius)
cornerRadius:radius].CGPath;
Run Code Online (Sandbox Code Playgroud)
一个成型的层需要一个形状……
我把它放在我的视图控制器中,它工作正常:
- (void)viewDidLoad
{
[super viewDidLoad];
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.frame = CGRectMake(150, 50, 200, 200);
shapeLayer.fillColor = [UIColor whiteColor].CGColor;
shapeLayer.strokeColor = [UIColor orangeColor].CGColor;
NSUInteger radius = 90;
shapeLayer.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 2.0*radius, 2.0*radius)
cornerRadius:radius].CGPath;
[self.view.layer addSublayer:shapeLayer];
}
Run Code Online (Sandbox Code Playgroud)
如果你改变路径
shapeLayer.path = [UIBezierPath bezierPathWithRect:shapeLayer.bounds].CGPath;
Run Code Online (Sandbox Code Playgroud)
它会导致
归档时间: |
|
查看次数: |
2803 次 |
最近记录: |