2010-12-23 22 views
3

是否有任何方法來動畫移除UITableView單元附件?動畫移除UITableViewCellAccessory

我目前正在展示一個UITableViewCellAccessoryDisclosureIndicator,但是我想動畫交換所有可見表單元格上的UISwitch的披露指標。

我已經試過這樣的事情:

[UIView animateWithDuration:0.3 
       animations:^{ 
        for (SwitchTableViewCell *cell in self.tableView.visibleCells) 
        { 
        cell.accessoryType = UITableViewCellAccessoryNone; 
        }      
       }]; 

...可惜就是沒有影響。披露指標突然消失,contentView寬度一步跳躍,而不是平滑過渡。

回答

3

accessoryType不是動畫屬性。有兩種方法可以做到這一點,這取決於你的情況。最簡單的方法僅適用於因爲進入編輯狀態而將附件更改爲UISwitch的情況。在這種情況下,只需在tableView:cellForRowAtIndexPath:方法中使用cell.editingAccessoryType = theSwitch;即可。當進入編輯模式時,表格視圖會自動淡入/淡出。

如果你這樣做的編輯模式之外,則下面的代碼將做你想做的:

[UIView animateWithDuration:0.3 animations:^{ 
    for(SwitchTableViewCell *cell in self.tableView.visibleCells) { 
     [[cell valueForKey:@"_accessoryView"] setAlpha:0.0]; 
    } 
} completion:^(BOOL done) { 
    for(SwitchTableViewCell *cell in self.tableView.visibleCells) { 
     cell.accessoryView = theSwitch; 
    } 
}]; 

不過,我不知道如果這個代碼將使它進入App Store,因爲它使用隱藏屬性_accessoryView。