【发布时间】:2014-03-08 04:07:34
【问题描述】:
我已经创建了一个这样的 CALayer 子类:
#import <QuartzCore/QuartzCore.h>
@interface SHBaseLayer : CALayer
@end
和实施:
#import "SHBaseLayer.h"
@implementation SHBaseLayer
- (void)drawInContext:(CGContextRef)theContext
{
CGContextSetStrokeColorWithColor(theContext, [UIColor blueColor].CGColor);
CGMutablePathRef thePath = CGPathCreateMutable();
CGPathMoveToPoint(thePath,NULL,15.0f,15.f);
CGPathAddCurveToPoint(thePath,
NULL,
15.f,250.0f,
295.0f,250.0f,
295.0f,15.0f);
CGContextBeginPath(theContext);
CGContextAddPath(theContext, thePath);
CGContextSetLineWidth(theContext, 5);
CGContextDrawPath(theContext, kCGPathStroke);
}
@end
我在视图控制器视图的层中添加这个层并调用setNeedsDisplay,但是当我运行应用程序时没有显示任何内容。
这是我的 ViewController 的 viewDidLoad。
- (void)viewDidLoad
{
[super viewDidLoad];
SHBaseLayer *l = [SHBaseLayer layer];
[self.view.layer addSublayer:l];
[l setNeedsDisplay];
}
我在这里做错了什么?
【问题讨论】:
标签: ios objective-c core-animation calayer quartz-core