Search code examples
objective-ccastingfloating-pointintegeruitouch

How to get UITouch to return a float instead of an int?


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);

Solution

  • 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.