IOS - 使用autolayout和drawRect

The*_*ker 0 core-graphics drawrect uiviewanimation ios autolayout

我正在使用autolayout,我有一个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);

}
Run Code Online (Sandbox Code Playgroud)

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

[self layoutIfNeeded];
Run Code Online (Sandbox Code Playgroud)

在动画块中,圆形像素看起来更大更难看.

我这样做的方法是否正确?

正确 不正确

The*_*ker 10

我从这篇文章中得到了它!

问题是os在每个动画步骤都没有调用drawRect.要强制它,在RoundView的init中:

self.contentMode = UIViewContentModeRedraw;
Run Code Online (Sandbox Code Playgroud)