如何围绕自身边界的中心旋转 UIBezierPath? [英] How to rotate UIBezierPath around center of its own bounds?

查看:16
本文介绍了如何围绕自身边界的中心旋转 UIBezierPath?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有一个 UIBezierPath……它的边界是完全正方形的……就像这样:

Lets say we have a UIBezierPath... the bounds of which are perfectly square... like this:

func getExponentPath(rotate180: Bool) -> UIBezierPath {

    // establish unit of measure (grid) based on this containing view's bounds... (not to be confused with this bezierpath's bounds)

    let G = bounds.width / 5

    let exponentPath = UIBezierPath()

    let sstartPoint = CGPoint(x:(3.8)*G,y:(1.2)*G)
    exponentPath.move(to: sstartPoint)
    exponentPath.addLine(to: CGPoint(x:(5)*G,y:(1.2)*G))
    exponentPath.addLine(to: CGPoint(x:(4.4)*G,y:(0.2)*G))
    exponentPath.addLine(to: CGPoint(x:(5)*G,y:(0.2)*G))
    exponentPath.addLine(to: CGPoint(x:(5)*G,y:(0)*G))
    exponentPath.addLine(to: CGPoint(x:(3.8)*G,y:(0)*G))
    exponentPath.addLine(to: CGPoint(x:(3.8)*G,y:(0.2)*G))
    exponentPath.addLine(to: CGPoint(x:(4.4)*G,y:(0.2)*G))
    exponentPath.addLine(to: sstartPoint)

    exponentPath.close()

    // this does not work:
    // if rotate180 { exponentPath.apply(CGAffineTransform(rotationAngle: CGFloat.pi)) }

    return exponentPath

}

如果旋转,这个 bezierpath 仍然需要在其包含的视图中占据完全相同的区域.

If rotated, this bezierpath still needs to occupy the exact same area within its containing view.

我只能假设这不起作用,因为旋转中心不是我想要的……尽管即使说旋转 0",我也会得到相同(错误)的结果.

I can only presume this does not work because there's some problem with the center of rotation not being what I intend... although I get the same (wrong) result even when saying "rotate by 0."

那么路径如何围绕它自己的中心点旋转呢?

So how can the path be rotated around it's own center point?

似乎应该有一个简单的线性代数矩阵乘法类型可以应用于点集.=T

It seems like there should be a simple linear algebra matrix multiplication type thingy that could be applied to the set of points. =T

推荐答案

我认为你不需要轮换.要倒置绘制相同的形状,只需翻转它:

I don't think you need the rotation. To draw the same shape upside down, just flip it:

        exponentPath.apply(CGAffineTransform(scaleX: 1, y: -1))
        exponentPath.apply(CGAffineTransform(translationX: 0, y: G))

这篇关于如何围绕自身边界的中心旋转 UIBezierPath?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆