Iphone 图像动画问题
我的图像动画有问题 这是你的答案Iphone 图像动画问题,iphone,Iphone,我的图像动画有问题 这是你的答案 @interface Flash_ViewController : UIViewController { IBOutlet UITextField *textField; IBOutlet UIButton *generateFlash; IBOutlet UIImageView *theFlash; IBOutlet UILabel *testLabel; NSArray *letterArray; NSMutableArray *imageArray;
@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
这是电话号码
-(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");
}
-(iAction)generateFlashNow:(id)发送方{
[textField resignFirstResponder];
/*
NSString*string1=textField.text;
//NSString*string2=[string1 STRINGBYREPLACINGOURCRENCESOFSTRING:@”“withString:@”“,”];
NSArray*arrayOfLetters=[string1组件由字符串分隔:@“,”];
*/
NSString*string=textField.text;
NSMUTABLEARRY*arrayOfLetters=[[NSMUTABLEARRY alloc]init];
对于(int i=0;i<[字符串长度];i++){
NSString*myChar=[NSString stringWithFormat:@“%c”,[string characterAtIndex:i]];
[arrayOfLetters addObject:myChar];
}
NSLog(@“日志数组:%@”,arrayOfLetters);
//NSArray*imageArray=[[NSArray alloc]init];
NSLog(@“记录数组的第一个字母:%@,[arrayOfLetters对象索引:0]);
runLoopTimes=[arrayOfLetters计数];
NSLog(@“字母:%d”,运行循环时间);
而(运行循环时间>0){
NSLog(@“loopedy Loop”);
NSString*LetterString=[NSString stringWithFormat:@“%@,[arrayOfLetters对象索引:索引时间]];
运行时间--;
NSLog(@“字母串:%@”,字母串);
NSString*imageName=[letterstringbyappendingstring:@.png];
NSLog(@“图像名称:%@”,图像名称);
[imageArray addObject:[UIImage imageName:imageName]];
NSLog(@“已添加对象%d”,索引时间);
testLabel.text=字母字符串;
indexTimes++;
}
NSLog(@“完成”);
运行时间=0;
指数时间=0;
[arrayOfLetters自动释放];
[Offlash setAnimationImages:imageArray];
[Offlash setAnimationRepeatCount:1];
theFlash.animationDuration=4;
[快速启动];
NSLog(@“图像闪烁”);
}
而我
指数时间=0;
在viewDidLoad方法中
我的连接是用IB建立的,所有日志消息都会触发。但是,我仍然看不到动画。我做错了什么
任何想法都将不胜感激
谢谢,Sam你在哪里创建和初始化你的imageArray?(您已经在代码中注释了行:
//NSArray*imageArray=[[NSArray alloc]init];
)因此,首先,请确保您的
imageArray
不是nil并正确初始化。(您还可以检查其count属性以检查图像是否实际添加到其中)您在哪里创建和初始化imageArray?(您已经在代码中注释了行://NSArray*imageArray=[[NSArray alloc]init];
)因此,首先,请确保您的
imageArray
不是nil并正确初始化。(您还可以检查它的count属性,以检查图像是否确实添加到它中)很难从您发布的代码中看出哪里出了问题。我们应该更多地了解您在interface builder中所做的工作(在这里发布并不容易…)。您确定反Flash已添加到子视图且可见吗?很难从您发布的代码中分辨出哪里出了问题。我们应该更多地了解您在interface builder中所做的工作(在这里发布并不容易…)。您确定反Flash已添加到子视图中并且可见吗?好的,这是工作。然而,我需要调用NSMutableArray alloc init,而不仅仅是NSArray。问题出在这里是的,您需要使用数组的可变版本,这一行只是对潜在问题的提示显示它到底通过了“[imageArray addObject:[UIImageName:imageName]];”?如果imageArray为nil,它将顺利工作-您可以向nil发送任何消息,而不会出现任何问题。是的,您是对的。我没想到如果alloc丢失会有严重的超额。好的,这项工作。然而,我需要调用NSMutableArray alloc init,而不仅仅是NSArray。问题出在这里是的,您需要使用数组的可变版本,这一行只是对潜在问题的提示显示它到底通过了“[imageArray addObject:[UIImageName:imageName]];”?如果imageArray为nil,它将顺利工作-您可以向nil发送任何消息,而不会出现任何问题。是的,您是对的。我没想到如果alloc丢失会有严重的超额。