通过 xcode 6 中的 quartz2D 绘图提供图层内容


嗨,根据

核心动画编程指南,您可以通过调用自定义图层类并手动编写提供内容的显示方法来提供图层内容。我想对内容使用 quartz2D 绘图(在使用石英的单独自定义类中编写),但我不知道如何操作。

我正在尝试在这里使用显示方法

-(void) displayLayer: (CALayer *)layer inContext:(CGColorSpaceRef)ctc  inContext:(CGContextRef)ctx {}

石英2D绘图的方法

- (void)drawRect:(CGRect)rect {
        
        CGContextRef context = UIGraphicsGetCurrentContext();
        
        CGContextSetLineWidth(context, 2.0);
        
        CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
        
        CGRect rectangle = CGRectMake(60,170,200,80);
        
        CGContextAddRect(context, rectangle);
        
        CGContextStrokePath(context);
}

你把方法签名都搞混了。而不是:

-(void) displayLayer: (CALayer *)layer inContext:(CGColorSpaceRef)ctc inContext:(CGContextRef)ctx {}

您应该使用:

- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx

让我知道这是否是实际问题。我很乐意提供一个工作示例。

最新更新