【问题标题】:IOS - Working with autolayout and drawRectIOS - 使用自动布局和drawRect
【发布时间】:2014-08-06 08:09:40
【问题描述】:

我正在使用自动布局,并且我有一个 RoundView 类(UIButton 的子视图),它的 drawRect 方法是:

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGFloat lineWidth = 0.0;
    CGContextSetLineWidth(context, lineWidth);
    CGContextSetFillColorWithColor(context, _currentBackgroundColor.CGColor);
    CGContextAddEllipseInRect(context, self.bounds);
    CGContextFillPath(context);

}

然后我将它添加到 self(一个 UIView),使用自动布局设置它的宽度和高度。一切看起来都很棒。 但是当我改变它的大小限制(有一个更大的视图),并调用

[self layoutIfNeeded];

在动画块中,圆形像素看起来更大更丑。

我这样做是否正确?

【问题讨论】:

    标签: ios core-graphics autolayout uiviewanimation drawrect


    【解决方案1】:

    我刚从this post 得到它!

    问题是操作系统没有在每个动画步骤调用 drawRect。 为了强制它,在 RoundView 的初始化中:

    self.contentMode = UIViewContentModeRedraw;
    

    【讨论】:

      【解决方案2】:

      您需要考虑视网膜显示[UIDevice mainScreen].scale 的内容比例。查看这个(问题)的答案[CGContext and retina display

      【讨论】:

      • 谢谢,但这与视网膜显示器无关。如果我先设置更大的尺寸,它会看起来很干净
      猜你喜欢
      • 1970-01-01
      • 2013-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-17
      • 2015-04-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多