在非视网膜显示器上渲染圆圈

时间:2014-01-17 11:58:27

标签: ios render geometry

我有收集视图。项目 - 是一个包含2个圆圈的视图 - 用于选择和标记的圆形视图。我的一些观点渲染不正确。我处理视图框架并进行更改:所有浮动值现在都是整数。它对视网膜显示有帮助。我可以为非视网膜显示器做些什么?

- (void)layoutSubviews
{
    [super layoutSubviews];
    CGRect frame, contentFrame, markFrame, selectFrame;
    int markFrameMargin, contentHeight, selectRadius, markRadius;

    frame = self.frame;
    frame.origin.x = (int) frame.origin.x;
    frame.origin.y = (int) frame.origin.y;
    frame.size.width = (int) frame.size.width;
    frame.size.height = (int) frame.size.height;
    self.frame = frame;

    contentHeight = (int) self.bounds.size.height * ContentFrameRatio + 1;
    CGRectDivide(self.bounds, &contentFrame, &markFrame, contentHeight, CGRectMinYEdge);

    selectFrame = contentFrame;
    markFrame   = CGRectInset(markFrame, (markFrame.size.width - markFrame.size.height) / 2, 0);

    markFrameMargin = (int) markFrame.size.width / MarkFrameMarginRatio;
    markFrame = CGRectInset(markFrame, markFrameMargin, markFrameMargin);

    selectRadius = selectFrame.size.width / 2;
    markRadius   = markFrame.size.width / 2;

    self.contentLabel.frame = contentFrame;
    self.selectedBackgroundView.frame = selectFrame;
    self.markView.frame = markFrame;

    self.selectedBackgroundView.layer.cornerRadius = selectRadius;
    self.markView.layer.cornerRadius = markRadius;
}

屏幕:

enter image description here

我找到了解决方案。为了获得良好的圆形渲染,请确保:

  1. 框架的位置是整数值
  2. 宽度和高度是整数
  3. 宽度和高度均匀(宽度%2 == 0)

0 个答案:

没有答案