내 리소스 폴더에 50 개의 이미지 폴더 ("beeanim")가 있습니다. 이 이미지로 배열을 채운 다음 이미지가있는 애니메이션을 실행하고 싶습니다. 각 이미지의 이름은 bee1
, bee2
......... bee50
입니다.배열을 프로그래밍 방식으로 애니메이션으로 채우기
내가 엑스 코드에서 응용 프로그램을 실행하기 위해 갈 때 내가 콘솔에 오류가 말을 얻을 :
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
이 날 내가 제대로 이름을 참조되지 않을 수 있다고 생각합니다하지만 난 모르겠어요 내가 이미 가지고있는 것보다 다른 방법. 나는 어떤 도움을 주셔서 감사합니다. 내 코드 :
-(void) createBeeImage {
NSString *fileName;
NSMutableArray *imageArray = [[NSMutableArray alloc] init];
for(int i = 1; i <= 51; i++) {
fileName = [NSString stringWithFormat:@"beeanim/bee%d.png", i];
[imageArray addObject:[UIImage imageNamed:fileName]];
}
UIImageView * imgView = [[UIImageView alloc] initWithFrame:
CGRectMake(215, 250, 174, 80)];
imgView.animationImages = imageArray;
imgView.animationDuration = 2;
imgView.animationRepeatCount = 0;
imgView.contentMode = UIViewContentModeBottomLeft;
[self.view addSubview:imgView];
[imgView startAnimating];
}
보인다 삽입 할 수 없습니다 50 개의 이미지 만 있고 51 개의 이미지 (ur 코드에 표시된 것처럼)를 반복하려고하면 코드가 충돌하는 것처럼 'i <= 51'을 '1 <= 50'(으)로 변경하십시오. 이제는 작동해야합니다 ... – samfisher
나중에 참조 할 일은 NSLog 또는 NSAssert를 사용하여 일어나는 일이 일어나는지 확인하는 것입니다. 예를 들어,'fileName = [NSString stringWithFormat : @ "beeanim/bee % d.png ", i];'NSLog (@"% @ ", fileName) 이미지 추가하기, – EmilioPelaez