我有以下代碼:畫的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不起作用?