2012-02-10 94 views
0

我必須創建一個在每個單元格中都有一個旋轉按鈕的表格。uitableviewcell中的旋轉按鈕

這裏是我CustomCell類動畫方法

- (void)animateButton { 
__block CustomCell *block_button = self; 
void (^animationBlock)(void) = ^(void) { 
block_button.downloadBackButton.transform = 
    CGAffineTransformMakeRotation(M_PI * 2/3); 
}; 

[UIView animateWithDuration:3.0 
         delay:0.0 
        options:UIViewAnimationOptionRepeat|UIViewAnimationOptionCurveLinear 
       animations:animationBlock 
       completion:nil];} 

而且我CustomTableViewController的cellForRowAtIndexPath:方法:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
static NSString *CellIdentifier = @"cell"; 

FAMasterTableCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil]; 
    cell = (CustomCell *) [nib objectAtIndex:0]; 
} 
    [cell animateButton]; 
return cell; 

}

的問題是,表視圖是在iPod生澀,但在iPhone 4s上運行正常。

有什麼建議嗎?

回答

0

您是否嘗試過使用已與單元格關聯的動畫,而不是每次都添加新的動畫?

FAMasterTableCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil]; 
    cell = (CustomCell *) [nib objectAtIndex:0]; 
    [cell animateButton]; 
} 
return cell; 

您可能還需要考慮使用CAAnimations而不是使用UIView的動畫。我相信動畫而不是視圖會提高性能。

+1

UIView動畫不應該比直接CABasicAnimations慢得多。 UIViews僅僅是CALayers的輕量級包裝,我注意到在我的基準測試中,即使在最老的iOS硬件上,一個動畫與另一個動畫的性能差異都微乎其微。 – 2012-02-10 17:50:53

+0

非常好的信息,我沒有意識到他們只是輕量級的包裝。 – 2012-02-10 17:53:51

+0

是的,它不像Mac上的NSViews,它有更多的行李。我在iPhone SDK測試版中做的第一件事就是看UIView的表現,並且對它印象深刻。我在原始CALayers中做了一些工作,但主要是針對Mac/iOS跨平臺顯示代碼(如Core Plot)。作爲其基礎之一,UIKit顯然是以Core Animation爲基礎構建的。 – 2012-02-10 17:57:47