2011-04-12 157 views
1

我的应用程序内有以下代码,但它不会动画UIImageView,谁能告诉我为什么?UIImageView不动画

UITableViewCell* cell = [selectedTable cellForRowAtIndexPath:selectedPath]; 

    NSArray* myImageArray = [NSArray arrayWithObjects: 
          [UIImage imageNamed:[[NSBundle mainBundle] pathForResource:@"boxBeingChecked117x11" ofType:@"png"]], 
          [UIImage imageNamed:[[NSBundle mainBundle] pathForResource:@"boxBeingChecked217x11" ofType:@"png"]], 
          [UIImage imageNamed:[[NSBundle mainBundle] pathForResource:@"boxBeingChecked317x11" ofType:@"png"]], 
          [UIImage imageNamed:[[NSBundle mainBundle] pathForResource:@"boxBeingChecked417x11" ofType:@"png"]], 
          [UIImage imageNamed:[[NSBundle mainBundle] pathForResource:@"boxBeingChecked517x11" ofType:@"png"]], 
          [UIImage imageNamed:[[NSBundle mainBundle] pathForResource:@"boxBeingChecked617x11" ofType:@"png"]], 
          nil]; 


    cell.imageView.animationImages = myImageArray; 
    cell.imageView.animationDuration = 4.20; 
    cell.imageView.animationRepeatCount = 1; 
    [cell.imageView startAnimating]; 
    [NSTimer scheduledTimerWithTimeInterval:4.0 
            target:self 
            selector:@selector(methodToInvokeAfterAnimationIsDone) 
            userInfo:nil 
            repeats:NO]; 

回答

2

你应该使用这样的:

NSArray* myImageArray = [NSArray arrayWithObjects: 
          [UIImage imageNamed:@"boxBeingChecked117x11.png"]], 
          [UIImage imageNamed:@"boxBeingChecked217x11.png"]], 
          [UIImage imageNamed:@"boxBeingChecked317x11.png"]], 
          [UIImage imageNamed:@"boxBeingChecked417x11.png"]], 
          [UIImage imageNamed:@"boxBeingChecked517x11.png"]], 
          [UIImage imageNamed:@"boxBeingChecked617x11.png"]], 
          nil]; 

你需要给名称的文件,而不是路径的,在imageNamed:方法。

+0

@ user698952 - 欢迎使用StackOverflow!请考虑更改您的用户名,以便其他用户将您识别为有贡献的社区成员。另外,请记住在问题和答案中正确地制定句子。拼写和语法计数! :-) – Moshe 2011-04-12 03:49:03

0

确保imageViewhighlighted属性设置为NO,否则上面的代码将不起作用。如果要为突出显示的图像制作动画,请使用highlightedAnimationImages