arc4random - 8个按钮重叠

时间:2012-02-25 18:33:14

标签: xcode overlapping arc4random

我正在构建一个应用程序,其中我有8个UI按钮,使用arc4random给出所有随机坐标。一直想弄清楚如何阻止它们重叠。

任何想法或帮助都会非常感激,因为这是阻止我的应用程序的唯一方法!

由于

1 个答案:

答案 0 :(得分:0)

您需要一组不重叠的可能位置:

CGPoint possibleLocations[] = {
    { 0, 0 },
    { 25, 25 },
    { 25, 50 },
    // etc.
}

int numLocations = sizeof(possibleLocations) / sizeof(CGPoint);
BOOL takenLocations[numLocations];

CGPoint finalLocation;
int index;

while ((takenLocations[index = arc4random_uniform(numLocations]))
{
}

takenLocations[index] = YES;
finalLocation = possibleLocations[index];