2010-05-24 5 views
2

를 이동, 애니메이션의 UIView 이동 나는 애니메이션으로 화면을 떨어져 그것을 이동하는 UIView 하위에 다음 코드가 있습니다아이 패드 : 다시

float currentX = xposition; //variables that store where the UIView is located 
float currentY = yposition; 

float targetX = -5.0f - self.width; 
float targetY = -5.0f - self.height; 

moveX = targetX - currentX; //stored as an instance variable so I can hang on to it and move it back 
moveY = targetY - currentY; 

[UIView beginAnimations:@"UIBase Hide" context:nil]; 
[UIView setAnimationDuration:duration]; 
self.transform = CGAffineTransformMakeTranslation(moveX,moveY); 
[UIView commitAnimations]; 

그냥 잘 작동합니다. targetX/Y를 0으로 변경하여 실제로 지정된 점으로 이동했는지 확인합니다.

moveX = -moveX; 
moveY = -moveY; 

[UIView beginAnimations:@"UIBase Show" context:nil]; 
[UIView setAnimationDuration:duration]; 
self.transform = CGAffineTransformMakeTranslation(moveX,moveY); 
[UIView commitAnimations]; 

이 약 3 배까지가해야와 UIView의 박았 : 나는 시도하고 다시 원래 어디까지보기를 이동할 때

문제

입니다. 따라서보기는 일반적으로 화면의 오른쪽에서 벗어납니다 (위치에 따라 다름).

알고 있어야하는 CGAffineTransforMakeTranslation 기능이 있습니까? 나는 그 문서를 읽었고, 내가 말할 수있는 것으로부터, 내가 기대하고있는 일을해야만한다.

누구든지이 문제를 해결할 방법을 제안 했습니까? 감사.

답변

2

transform에 할당하면 이전 항목이 사라집니다. 원래 위치로 되돌리려면 ID 변환을 할당하십시오.

self.transform = CGAffineTransformIdentity; 

(또는 더 나은, 그냥 .transform을 변경하는 대신 .frame을 변경할 수 있습니다.)

+0

Perfect. 어떻게 작동하는지 이해합니다. 빠른 답변 감사합니다. – Joel

2

UIView의 변환되어 있지 첨가제; 난 당신이 대신 할 것을 다시 이동하는 것이 좋습니다 :

self.transform = CGAffineTransformIdentity; 

워드 프로세서 말 (프레임 업데이트에 대한) :

"경고 :이 속성이있는 경우 신원은 프레임 속성 값을 변환하지 정의되어 있지 않으므로 무시해야합니다. "