2011-04-12 156 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