当我需要刷新 UITableView 时,我需要一些自定义动画。我在寻找类似的东西:
[self.table reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationLeft];
但要设置我自己的动画。如果这个动画基于 UITableViewCell 就完美了,因为我需要单独为单元格中的一些元素设置动画。
我尝试做的事情:
我有这样的自定义单元格
___________________________________
| lable |separator| lable 2 |
-----------------------------------
我希望标签 2 向左或向右滑动,但不是整个单元格。
马可
最佳答案
在 .h 中,您将拥有 reloadInWithMyOwnAnimation BOOL 变量。在重新加载该部分之前,将其设置为 YES。重新加载后将其设置为 NO。
reloadingWithMyOwnAnimation = YES;
[tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationLeft];
reloadingWithMyOwnAnimation = NO;
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *myCustomCell = cell;
BOOL swipeLeft = YES;
if (reloadingWithMyOwnAnimation == YES) {
[UIView animateWithDuration:0.8f animations:^{
if (swipeLeft) {
//Swipe Right
//Get the label frame
CGRect myLabelFrame = myCustomCell.textLabel.frame;
//Set it to 0
myLabelFrame.origin.x = 0;
//Move it to Right
myLabelFrame.origin.x += cell.bounds.size.width;
//Set the frame of the label
[myCustomCell.textLabel setFrame:myLabelFrame];
}
else{
//Swipe Left
//Get the label frame
CGRect myLabelFrame = myCustomCell.textLabel.frame;
//Set it to 0
myLabelFrame.origin.x = 0;
//Move it to Left
myLabelFrame.origin.x -= cell.bounds.size.width;
//Set the frame of the label
[myCustomCell.textLabel setFrame:myLabelFrame];
}
[myCustomCell layoutSubviews];
} completion:^(BOOL finished) {
NSLog(@"Done");
}];
}
}
关于ios - UITableViewCell 的自定义行动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23929212/