【问题标题】:Drawing 100+ circles with different position using UIBezierPaths使用 UIBezierPath 绘制 100 多个不同位置的圆圈
【发布时间】:2014-06-05 15:10:50
【问题描述】:

我正在尝试在 UIView 的 drawRect 函数中绘制 100 多个 UIBezierPath 圆圈。我正在创建 UIBezierPaths 并将其添加到数组中:

for (int i = 0; i < 100; i++) {

    UIBezierPath *path = [UIBezierPath bezierPath];
    [path addArcWithCenter:centerPoint radius:10 startAngle:0 endAngle:360 clockwise:YES];

    path.lineWidth = 2;
    [bezierPaths addObject:path];
}

在调用 setNeedDisplay 之前。然后在 drawRect 我遍历数组

- (void)drawRect:(CGRect)rect {

       for (UIBezierPath *path in bezierPaths) {
            [path fill];
            [path stroke];
       }
    }

这看起来有点矫枉过正,有更好的方法吗?使用 Profile 我可以看到 MainThread 的 86% 被用于调用 drawRect 中的 [path stroke]。

【问题讨论】:

  • 唯一不同的是中心点吗?
  • 圆圈会改变位置吗?
  • 嗨大卫,我设法自己回答了......我正在通过 0 度和 360 度而不是辐射点,并且它绘制了太多次。不幸的是,我没有 15 名“回答您的问题”的声誉。感谢您抽出宝贵的时间!
  • 您可以(并且被鼓励)回答您自己的问题并接受它,以便其他可能遇到相同问题的人可以从您的解决方案中受益。
  • 您没有阅读我上面的全部评论 :] - “很遗憾,我没有 15 名“回答您的问题”的声誉。不过,感谢您抽出宝贵的时间!”

标签: ios drawrect uibezierpath


【解决方案1】:

我正在传递 0 度和 360 度,而不是辐射点,它绘制它们的次数太多了。

【讨论】:

    猜你喜欢
    • 2014-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-12
    • 1970-01-01
    • 2020-01-30
    相关资源
    最近更新 更多