【问题标题】:Scale touch points for different screen sizes为不同的屏幕尺寸缩放触摸点
【发布时间】:2018-02-12 14:52:27
【问题描述】:

给定一个CGPoint 接触点,是否有办法缩放 x、y 值,以使它们对于所有屏幕尺寸/分辨率(不同的 iPad、不同的 iPhone)都保持一致?

【问题讨论】:

  • 一致是什么意思?

标签: ios swift uitouch cgpoint


【解决方案1】:

确定一个标准尺寸,然后将要插入的点乘以当前宽度/高度与标准宽度/高度的商。

guard let currentSize = (UIApplication.shared.delegate as? AppDelegate)?.window?.bounds.size else {
    return
}

let standardSize = CGSize(width: 320, height: 568)
let point = CGPoint(x: 120, y: 120)
let interpolatedPoint = CGPoint(x: point.x * currentSize.width / standardSize.width, y: point.y * currentSize.height / standardSize.height)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-02
    相关资源
    最近更新 更多