如何让 UITouch 返回 float 而不是 int ?

发布于 2024-12-17 07:45:04 字数 236 浏览 2 评论 0原文

我正在根据 UITouch 分配视图的中心。我读到 UITouch 返回一个 int 值——这意味着它没有给我触摸的确切位置。有什么方法可以投射触摸值,以便我获得触摸点的不圆角位置?

CGPoint touchPoint = [touch locationInView:self];
 self.thumb.center = CGPointMake(touchPoint.x, touchPoint.y);

I'm assigning the center of a view based on a UITouch. I read that UITouch returns an int value -- meaning that it doesn't give me the exact location of the touch. Is there any way to cast the touch value so that I get the unrounded location of the touchpoint?

CGPoint touchPoint = [touch locationInView:self];
 self.thumb.center = CGPointMake(touchPoint.x, touchPoint.y);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空城之時有危險 2024-12-24 07:45:04

您到底在哪里读到 UITouch 返回 int 值?这完全是错误的。您的代码已经证明了它是多么错误,因为您已经知道 UITouch 返回一个 CGPoint 值。如果您查看 CGPoint 的定义,它由两个 CGFloat 字段组成,因此它已经是一个浮点值。

Where exactly did you read that a UITouch returns an int value? That's just plain wrong. Your code already demonstrates how wrong it is, since you already know that a UITouch returns a CGPoint value. If you look at the definition of CGPoint, it's made up of two CGFloat fields, so it's already a floating-point value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文