2012-12-11 6 views
0

totalSmallButtonLocations라는 배열로 미리 지정된 여러 위치로 이동하는 일부 UIButton이 있습니다. 그래서 availableLocations, NSMutableArray, 다른 CGPoints 할당 및 availableLocations에서 해당 점을 제거합니다. 그 작업이 끝나면 버튼을 새로운 위치로 이동시키는 UIView 애니메이션이 있습니다.루핑, 저장 및 CGPoint 사용하기

현재이 작동하지만, 당신이 아래에 볼 수있는 매우 긴 (실제 프로젝트에 더 많은 버튼과 위치가 있습니다) :

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 측면은 몇 가지 문제를 일으키고 있습니다. 내 루프가 괜찮아요,하지만 애니메이션 섹션 동안 그것을 할당하는 방법을 모르겠다 고 오류를 던지고있다 :

"CGPoint '(일명'구조 CGPoint ') 호환되지 않는 유형 id ":

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]; 
+1

'xcode' 태그를 남용하지 마십시오. 제거되었습니다. –

+0

와우, 나는 미래를 염두에 두겠다. –

+0

명심 해 주셔서 감사합니다. –

답변

2

문제는 CGPoint 자체 대신 CGPoint 포인터를 가져 오는 것입니다. 문제는 여기 [points objectAtIndex:1];입니다. CGPoint 구조체 대신 객체를 가져옵니다. 이 코드를 마치 [[points objectAtIndex:1] CGPointValue];처럼 감쌀 때 경고가 사라져야합니다.

+0

감사합니다. 매력을 발휘했습니다. –

+0

기꺼이 도와 드리겠습니다 :) 해피 코딩. –