【发布时间】:2014-11-14 21:16:42
【问题描述】:
我正在尝试使用 Core Graphics 绘制一些圆弧和圆。我正在使用新的 Interface Builder 功能 IBDesignable/IBInspectable 来实时查看我的视图,它就像在 Interface Builder 中一样。很简单,这是我画一个圆圈的代码:
-(void)drawCircleInRect:(CGRect)rect{
[self.circleColor setFill];
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:self.frame];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClearRect(context, rect);
// If you have content to draw after the shape,
// save the current state before changing the transform.
CGContextSaveGState(context);
[path fill];
// Restore the graphics state before drawing any other content.
CGContextRestoreGState(context);
}
我在drawRect: 中调用它,而self.circleColor 是UIColor 的IBInspectable 属性,我已将其设置为白色。这是结果,没有问题:
但是,当我在模拟器或设备上运行时(都尝试过,结果相同),这就是我得到的:
这就像在视图中缩放/错误定位,因此被剪裁了。为什么会这样?好像是2倍。如果反之亦然,我会假设它与 Retina 比例因子有关,但这恰恰相反。它在视网膜设备中绘制太大,在我的非视网膜 Mac 的界面生成器上绘制正常。有什么建议吗?
(底部的黑条其实是我拉黑的标签栏,没有什么异常)
【问题讨论】:
标签: xcode interface-builder core-graphics xcode6 cgcontext