gpt4 book ai didi

ios - 无论分辨率如何,获取点的坐标

转载 作者:行者123 更新时间:2023-11-30 12:53:20 24 4
gpt4 key购买 nike

你能给我一种方法来获取在所有 iOS 设备上都相同的点坐标吗?

我在文章Coordinate Systems and Transforms中找到

The user coordinate space in Cocoa is the environment you use for all your drawing commands. It represents a fixed scale coordinate space, which means that the drawing commands you issue in this space result in graphics whose size is consistent regardless of the resolution of the underlying device.

我尝试这样做:

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?)
{
if let touch = touches.first{
let lastPoint = touch.location(in: self.view.superview)
let precisePoint = graphView.convert(lastPoint, to: self.view.superview)
}
}

但lastPoint和precisionPoint取决于所使用的设备。

感谢帮助

最佳答案

感谢@Rikh 下面的回答:

var points = [CGPoint]()

//MARK: Touch events
override func touchesBegan(_ touches: Set<UITouch>,
with event: UIEvent?){
if let touch = touches.first{
let lastPoint = touch.location(in: self.view.superview)

let bounds = UIScreen.main.bounds

points.append(CGPoint(x: lastPoint.x / bounds.maxX, y: lastPoint.y / bounds.maxY))
}
}


func convertPointsToView(){
let bounds = UIScreen.main.bounds

for point in points{
let convertedPoint = CGPoint(x: point.x * bounds.maxX, y: point.y * bounds.maxY)

print(convertedPoint)
}
}

关于ios - 无论分辨率如何,获取点的坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40699471/

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