Pergunta
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?
Solução
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);
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow