我的圖像動畫有問題。圖像動畫問題
這裏是.H
@interface Flash_ViewController : UIViewController {
IBOutlet UITextField *textField;
IBOutlet UIButton *generateFlash;
IBOutlet UIImageView *theFlash;
IBOutlet UILabel *testLabel;
NSArray *letterArray;
NSMutableArray *imageArray;
NSTimer *myTimer;
int runLoopTimes;
int indexTimes;
}
-(IBAction) generateFlashNow:(id)sender;
@end
這裏所述的.m
-(IBAction) generateFlashNow:(id)sender{
[textField resignFirstResponder];
/*
NSString *string1 = textField.text;
//NSString *string2 = [string1 stringByReplacingOccurrencesOfString:@"" withString:@","];
NSArray *arrayOfLetters = [string1 componentsSeparatedByString:@","];
*/
NSString *string = textField.text;
NSMutableArray *arrayOfLetters = [[NSMutableArray alloc] init];
for(int i = 0; i < [string length]; i++) {
NSString *myChar = [NSString stringWithFormat:@"%c", [string characterAtIndex:i]];
[arrayOfLetters addObject:myChar];
}
NSLog(@"Log Array :%@", arrayOfLetters);
//NSArray *imageArray = [[NSArray alloc] init];
NSLog(@"Log First Letter of array: %@",[arrayOfLetters objectAtIndex:0]);
runLoopTimes = [arrayOfLetters count];
NSLog(@"Letters:%d", runLoopTimes);
while (runLoopTimes > 0) {
NSLog(@"loopedy Loop");
NSString *LetterString = [NSString stringWithFormat:@"%@", [arrayOfLetters objectAtIndex:indexTimes]];
runLoopTimes --;
NSLog(@"letter String : %@", LetterString);
NSString *imageName = [LetterString stringByAppendingString:@".png"];
NSLog(@" IMAGE NAME: %@", imageName);
[imageArray addObject:[UIImage imageNamed:imageName]];
NSLog(@"Added object %d", indexTimes);
testLabel.text = LetterString;
indexTimes ++;
}
NSLog(@"done");
runLoopTimes = 0;
indexTimes = 0;
[arrayOfLetters autorelease];
[theFlash setAnimationImages:imageArray];
[theFlash setAnimationRepeatCount:1];
theFlash.animationDuration = 4;
[theFlash startAnimating];
NSLog(@"images flashed");
}
和我讓 indexTimes = 0;在viewDidLoad方法中使用 。
我的連接是在IB中完成的,並且所有的日誌消息都會被觸發。但是,我仍然沒有看到動畫。我究竟做錯了什麼?
任何想法,將不勝感激。
謝謝,山姆
很難從你發佈的代碼中發現錯誤。 我們應該更多地瞭解你在界面構建器中做了什麼(這不容易在這裏發佈......)。 你確定theFlash被添加到子視圖中並且可見嗎? – 2010-01-15 08:35:25