【问题标题】:How to calculate height/width based on CGPoint positions如何根据 CGPoint 位置计算高度/宽度
【发布时间】:2020-05-16 21:06:08
【问题描述】:

我有一个包含 3 个 CGPoints 的数组,我想做的是根据这些 CGPoint 坐标创建一个 CGRect。我需要这个 CGRect 来设置视图的边界,这样它就可以在视图加载后立即“放大”到这些坐标,但我不确定如何获得高度和宽度。非常感谢任何帮助!

【问题讨论】:

标签: ios swift cgrect cgpoint


【解决方案1】:
let points: [CGPoint] = [
    .init(x: 1, y: 1), 
    .init(x: 5, y: 1), 
    .init(x: 8, y: 5)
]

let bounds = points.reduce(CGRect.null) { rect, point in
    return rect.union(CGRect(origin: point, size: .zero))
}

【讨论】:

    猜你喜欢
    • 2022-10-18
    • 2013-08-26
    • 1970-01-01
    • 2011-03-28
    • 2017-02-23
    • 1970-01-01
    • 1970-01-01
    • 2013-08-11
    • 2015-06-26
    相关资源
    最近更新 更多