如何让 UITouch 返回 float 而不是 int ?
我正在根据 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您到底在哪里读到 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 ofCGPoint
, it's made up of twoCGFloat
fields, so it's already a floating-point value.