0

arc4random を使用してすべてのランダムな座標が指定された 8 つの UI ボタン​​を持つアプリを構築しています。それらの重なりを止める方法を見つけようとしています。

私のアプリを妨げているのはそれだけなので、アイデアや助けをいただければ幸いです。

ありがとう

4

1 に答える 1

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];
于 2012-02-25T18:40:01.897 に答える