2

In my application I am developing a sort of tile system. Instead of doing my tiles manually I am planning on having UIImageViews that "snap" to a specific location.

Here's my question:

How can I round my new location to a factor of (in my case) 16?

Matt S.
  • 13,305
  • 15
  • 73
  • 129

1 Answers1

4

Same as how you would do with individual float values.

CGPoint snap(CGPoint p) {
  return CGPointMake(roundf(p.x / 16) * 16,
                     roundf(p.y / 16) * 16);
}
kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005