2012-06-04 8 views
0

는 내가 객체의 새로운 위치를 계산하는 루프의 일부 기능을 사용어떻게 개체의 위치를 ​​바꿀 수 있습니까?

...some code.... 

for (int i = self.frame.origin.x; i <= 710; ++i) { 
    CGPoint newP = CGPointMake(i, 1); 
    float posY = a * pow((newP.x - w.x),2) - w.y; 

    CGPoint result = CGPointMake(i, posY); 
    [NSThread sleepForTimeInterval:1]; 
    self.frame = CGRectMake(result.x, result.y, self.frame.size.width, self.frame.size.height); 
    NSLog(@"[%f, %f]", result.x, result.y); 
} 

,하지만 목적은 아직도 그 자리에있다.

콘솔 인쇄 :

2012-06-04 23:13:19.183 PERT Estimator[326:707] [304.000000, 169.499985] 
2012-06-04 23:13:20.195 PERT Estimator[326:707] [305.000000, 165.172806] 
2012-06-04 23:13:21.197 PERT Estimator[326:707] [306.000000, 160.856293] 
2012-06-04 23:13:22.200 PERT Estimator[326:707] [307.000000, 156.550461] 
2012-06-04 23:13:23.225 PERT Estimator[326:707] [308.000000, 152.255295] 
2012-06-04 23:13:24.265 PERT Estimator[326:707] [309.000000, 147.970810] 

등 ...

무슨 잘못?

+0

정확히 그 루프를 작성하여 무엇을하려합니까? – nhahtdh

답변

1

와우, 실제로 애니메이션 블록을 사용해야합니다.

/* Starting position */ 
[self setFrame:CGRectMake(304, 169.499985,self.frame.size.width, self.frame.size.height)]; 

[UIView animateWithDuration:1.0 
         delay:0.0 
        options:UIViewAnimationCurveEaseOut 
       animations:^ 
       { 
        [self setFrame:CGRectMake(309, 147, 320,110)]; 
       } 
       completion:^(BOOL finished) 
       { 
        if (finished) 
         /* Animation is done, do something, or not */ 
         NSLog(@"[%f, %f]", result.x, result.y); 
       }]; 
+0

도움에 감사드립니다. –

관련 문제