2012-02-21 2 views
0

카드가 3 장 있습니다. 처음에는 모든 카드가 오른쪽으로 이동 한 후 1 초 후 card2가보기의 왼쪽에 표시되고 다시 두 번째 카드 2가 오른쪽으로 이동합니다. 다음 코드를 사용하여 구현했습니다. 뷰로드 나는 다음과 같은 코드가있을 때, 여기 다른 애니메이션을 3 단계로 움직이면

counter = 0; 
timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(performAnimationToRight) userInfo:nil repeats:YES]; 

는 performAnimationToRightMethod

-(void)performAnimationToRight 
{ 
if (counter == 0) { 

    CGAffineTransform transformToLeft = CGAffineTransformMakeTranslation(388,0); 

    [UIView beginAnimations:@"Move1" context:nil]; 
    [UIView setAnimationDuration:2]; 

    card0.transform = transformToLeft; 
    card1.transform = transformToLeft; 
    card2.transform = transformToLeft; 

    [UIView commitAnimations]; 

}else if(counter == 50){ 

    card2.frame = CGRectMake(-300,card2.frame.origin.y, card2.frame.size.width, card2.frame.size.height); 

}else if(counter == 200){ 

    timer = nil; 
    counter = 0; 
    CGAffineTransform transformToLeft = CGAffineTransformMakeTranslation(-300,0); 

    [UIView beginAnimations:@"Move2" context:nil]; 
    [UIView setAnimationDuration:2]; 

    card2.transform = transformToLeft; 

    [UIView commitAnimations]; 
} 

counter++; 
} 

문제의 구현 대신 왼쪽으로 오른쪽으로 이동 이동의 마지막 액션 카드 2에 그입니다 그리고 그것은,

CGAffineTransform transformToLeft = CGAffineTransformMakeTranslation(-300,0); 

또는

어떠했는지의 여부를 제가 사용개

답변

1

두 의견 :

첫째, 당신의 설정하여 counter == 50에서 왼쪽으로 당신의 카드 2를 이동하는 프레임 기원은 시작 위치의 왼쪽 (아마도)이 될 수 있습니다.

둘째로 CAKeyframeAnimation을 사용하면 구현하기가 더 쉽습니다. NSTimercounter 메커니즘을 관리 할 필요가 없습니다.

관련 문제