2010-04-02 3 views
0

저는 이미지 애니메이션을 만들고 싶습니다. 이제는 이미지 이름을 설정하고 싶지만 ... png 형식의 이미지가 50 개 있습니다. 동일한 이미지 이름을 검색합니다. {iPhone SDK}

내 이미지 이름

은 다음과 같습니다 iamge_0000 to image_0050

pasheAnimation.animationImages = [NSArray arrayWithObjects: 
            [UIImage imageNamed:@"pashe_0000.png"],nil]; 

    [pasheAnimation setAnimationRepeatCount:5]; 
    pasheAnimation.animationDuration = 4; 
    [pasheAnimation startAnimating]; 

?!?!?!?

제이슨 코드 [EDITED] :

NSMutableArray* myImages = [[[NSMutableArray alloc] initWithCapacity:607] autorelease]; 
    for(int i = 1; i <= 607; i++) { 
     [myImages addObject:[UIImage imageNamed:[NSString stringWithFormat:@"p%d.png",i]]]; 
    } 

    butterflyView.animationImages = myImages; 
    [butterflyView setAnimationRepeatCount:100]; 
    butterflyView.animationDuration = 0; 
    [butterflyView startAnimating]; 
+0

실제로 이미지 이름을 나타내려면 문자열 형식을 변경해야합니다. 따라서 이미지의 이름이 pashe_0000.png 인 경우 문자열 형식은 pashe_ % 04d.png이어야합니다. 매우 중요합니다. 또한 실제로 608 개의 이미지가 있습니까? –

+0

제이슨, 내 파일 이름을 변경하고 p607로 변경했습니다. 내 응용 프로그램이 다시 충돌합니다 .. 그게 저를 미치게합니다 !!!! : @ 예 짧은 애니메이션 PLZ입니다. – Momi

+0

다시 코드를 편집합니다. 보세요 – Momi

답변

2
// There are actually 51 images in this series (0000-0050)  
NSMutableArray* myImages = [[[NSMutableArray alloc] initWithCapacity:51] autorelease]; 
for(int i = 0; i <= 50; i++) { 
    [myImages addObject:[UIImage imageNamed:[NSString stringWithFormat:@"image_%04d.png", i]]?:[NSNull null]]; 
} 
+0

-1 : UIImage가 nil이면 예외를 throw합니다. 또한 4 문자 길이의 제로 패딩 십진수의 경우 % 04가 아니라 % 02이어야합니다. –

+0

@Alex Reynolds : 나는 당신의 문제가 내게 어떤 것인지 정말로 모르지만, 당신의 대답이 오해의 소지가 있음에도 불구하고 나는 당신을 투표하지 않았다. –

+0

문제가 없지만 대답이 잘못되었습니다. –

1

당신은 실제로 오십에 0에서 51 개 이미지를 가지고있다.

NSMutableArray *myImages = [NSMutableArray arrayWithCapacity:51]; 
for (NSUInteger idx = 0; idx <= 50; idx++) { 
    NSString *filename = [NSString stringWithFormat:"image_%04d.png", idx]; 
    UIImage *image = [UIImage imageNamed:filename]; 
    if (image) { 
     [myImages addObject:image]; 
    } 
    else { 
     NSLog(@"Could not add %@", filename); // could also throw exception, if you want 
    } 
}