我有以下代码:画的CALayer成CGContext上
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不起作用?