2013-05-07 2 views
-2

특정 기간 내에 애니메이션을 만들고 싶습니다. 내 코드는 다음과 같습니다 :애니메이션이 경과 한 후 애니메이션이 계속됩니다.

- (void)animate{ 

NSArray *myImages = [[NSArray alloc] initWithObjects: 
        [UIImage imageNamed:@"01.png"], 
        [UIImage imageNamed:@"02.png"], 
        [UIImage imageNamed:@"03.png"], 
        [UIImage imageNamed:@"04.png"], 
        [UIImage imageNamed:@"05.png"], 
        [UIImage imageNamed:@"06.png"], 
        [UIImage imageNamed:@"07.png"], 
        [UIImage imageNamed:@"08.png"], 
        [UIImage imageNamed:@"09.png"], 
        [UIImage imageNamed:@"10.png"], 
        [UIImage imageNamed:@"11.png"], 
        [UIImage imageNamed:@"12.png"], 
        [UIImage imageNamed:@"13.png"], 
        nil]; 


faceImage.animationImages = myImages; 
faceImage.animationDuration = 4.0; 
faceImage.animationRepeatCount = 4; 

[faceImage startAnimating]; 

}

지금 문제가 경과 animationDuration 후, animationRepeatCount이 몇 초 동안 계속됩니다! 하지만 나는 4 초 내에 animationRepeatCount를 만들고 싶다. 4 초 후에 내 애니메이션이 멈춰야합니다! 내 코드를 수행하는 데 문제가 무엇입니까? 아니면 어떻게 해결할 수 있습니까?

+0

애니메이션 재생 시간은 1 – Impossible

+1

입니다. 시퀀스를 반복 할 때마다 16 초, 4 초가 걸립니다. 문서에 모두 나와 있습니다. – rdelmar

+0

그래서 @rdelmar와 요구 사항에 따라 다음과 같이 할 수 있습니다 : faceImage.animationDuration = 1.0; faceImage.animationRepeatCount = 4; – Amit

답변

1

코드는 다음과 같아야합니다, 두 번째의 경우

int imageCount = ...; 
int *longestStringLength = [NSString stringWithFormat:@"%d", imageCount - 1].length; 
NSMutableArray *myImages = [[NSMutableArray alloc] init]; 
for (int i = 0; i < imageCount; i++) { 

    NSString *filename = [NSString stringWithFormat:@"%d", i]; 
    while(filename.length < longestStringLength) { 

     filename = [NSString stringWithFormat:@"0%@", filename]; 
    } 
    filename = [filename stringByAppendingString:@".png"]; 
    [myImages addObject:[UIImage imageNamed:filename]]; 
} 

현재 애니메이션 기간을 확인하여 변수를 분할 : 모든

- (void)animate 
{ 
    NSArray *myImages = [[NSArray alloc] initWithObjects: 
        [UIImage imageNamed:@"01.png"], 
        [UIImage imageNamed:@"02.png"], 
        [UIImage imageNamed:@"03.png"], 
        [UIImage imageNamed:@"04.png"], 
        [UIImage imageNamed:@"05.png"], 
        [UIImage imageNamed:@"06.png"], 
        [UIImage imageNamed:@"07.png"], 
        [UIImage imageNamed:@"08.png"], 
        [UIImage imageNamed:@"09.png"], 
        [UIImage imageNamed:@"10.png"], 
        [UIImage imageNamed:@"11.png"], 
        [UIImage imageNamed:@"12.png"], 
        [UIImage imageNamed:@"13.png"], 
        nil]; 


    faceImage.animationImages = myImages; 
    faceImage.animationDuration = 1.0; 
    faceImage.animationRepeatCount = 4; 

    [faceImage startAnimating]; 
} 
+1

고맙습니다. – Leo

2

당신은 당신이 다음 이해할 필요가 더 진행하기 전에 :

animationDuration; // 이미지의 한주기 동안. 기본값은 이미지 수 * 1/30 초 (즉, 30fps)입니다.

즉, 설정 한 애니메이션 재생 시간은 이미지 1주기를 의미합니다. 이제 애니메이션을 4 초 동안 4 번 반복하고 싶다면 animationDuration 1 초 설정.

필요한 경우 수동으로 stopAnimating을 수동으로 수행 할 수도 있습니다.

0

먼저이 같은으로 끔찍한 배열 초기화를 교체 필요한 경우 4.

관련 문제