【发布时间】:2011-05-26 04:00:00
【问题描述】:
我有以下代码:
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CALayer *sublayer = [CALayer layer];
sublayer.backgroundColor = [UIColor orangeColor].CGColor;
sublayer.cornerRadius = 20.0;
sublayer.frame = CGRectMake(20, 0, 300, 20);
[sublayer setNeedsDisplay];
[sublayer drawInContext:context];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
但是当我查看返回的 newImage 时,只有一个空图像。当我将drawInContext更改为renderInContext时,我得到了上面的子层,但似乎坐标系混乱了。
知道为什么上面的 drawInContext 不起作用吗?
【问题讨论】: