totalSmallButtonLocationsという配列によって事前に決定された、さまざまな場所に移動するUIButtonがいくつかあります。そこで、availableLocations、NSMutableArrayを調べ、さまざまなCGPointを割り当て、それらのポイントをavailableLocationsから削除します。それが完了すると、ボタンを新しい場所に移動するためのUIViewアニメーションがあります。
現在、これは機能しますが、以下に示すように、非常に長くなっています(実際のプロジェクトでは、さらに多くのボタンと場所があります)。
int randomNumber;
NSValue *val;
CGPoint a, b, c;
NSMutableArray *availableLocations;
availableLocations = [NSMutableArray arrayWithArray:totalSmallButtonLocations];
randomNumber = arc4random_uniform(3);
val = [availableLocations objectAtIndex:randomNumber];
a = [val CGPointValue];
[availableLocations removeObjectAtIndex:randomNumber];
randomNumber = arc4random_uniform(13);
val = [availableLocations objectAtIndex:randomNumber];
b = [val CGPointValue];
[availableLocations removeObjectAtIndex:randomNumber];
randomNumber = arc4random_uniform(12);
val = [availableLocations objectAtIndex:randomNumber];
c = [val CGPointValue];
[UIView animateWithDuration:0.5 animations:^{
button1.center = a;
button2.center = b;
button3.center = c;
ループを作成しようとしていますが、CGPointアスペクトがいくつかの問題を引き起こしています。私のループは大丈夫だと思いますが、アニメーションセクションでループを割り当てる方法がわからず、エラーが発生します。
"互換性のないタイプIDから'CGPoint'(別名'struct CGPoint')に割り当てる":
int randomNumber;
NSValue *val;
CGPoint a;
NSMutableArray *availableLocations;
availableLocations = [NSMutableArray arrayWithArray:totalSmallButtonLocations];
NSMutableArray *points = [NSMutableArray array];
for(int looper = 14; looper > 0; looper--)
{
randomNumber = arc4random_uniform(looper);
val = [availableLocations objectAtIndex:randomNumber];
a = [val CGPointValue];
[points addObject:[ NSValue valueWithCGPoint:a]];
}
[UIView animateWithDuration:0.5 animations:^{
button1.center = [points objectAtIndex:1];
button2.center = [points objectAtIndex:2];
button3.center = [points objectAtIndex:3];