gpt4 book ai didi

swift - 对 UIBezierPath 应用变换使绘图消失

转载 作者:行者123 更新时间:2023-11-30 11:23:56 27 4
gpt4 key购买 nike

也许这是一个愚蠢的问题,但我正在尝试将转换应用到像这样简单的路径:

let path = UIBezierPath(rect: CGRect(x: 10, y: 10, width: 20, height: 20))
path.apply(CGAffineTransform(rotationAngle: 2.0))
"colorLiteral".setFill()
path.fill()

似乎添加“应用”行的事实,完全删除了 View 上的形状,而如果我不包含该行,则形状会正确显示在其位置上。

我对 Swift 还很陌生,所以我想我错过了这方面的重要一步?谢谢大家!

最佳答案

试试这个并记住rotationAngle采用弧度

let bounds = CGRect(x: 10, y: 10, width: 20, height: 20)
let path = UIBezierPath(rect: bounds)
path.apply(CGAffineTransform(translationX: -bounds.midX, y: -bounds.midY))
path.apply(CGAffineTransform(rotationAngle: CGFloat.pi / 4))
path.apply(CGAffineTransform(translationX: bounds.midX, y: bounds.midY))

关于swift - 对 UIBezierPath 应用变换使绘图消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50961198/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com