我的自定义单元格上有图像视图。单元格上的所有元素都有约束。我已经实现了这个方法来动画我的箭头。旋转工作良好,但没有动画。我有调试单元,并调用了nib方法。
我有从故事板单元格构建的标题:
视图控制器回调:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
static NSString *cellIdentifier = @"SectionHeader";
KNCategorySectionCell *sectionView = (KNCategorySectionCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
sectionView.index = section;
sectionView.delegate = self;
KNCategoryPoxy *category = [_categories objectAtIndex:section];
[sectionView setupViewWithState:category.state];
sectionView.categoryName.text = category.dictionary[@"name"];
return sectionView;
}方法的自定义单元实现:
- (void)setupViewWithState:(KNCategoryState)state
{
switch (state)
{
case KNCategoryStateStateCollapsed:
{
[self.contentView setBackgroundColor:[UIColor red:255 green:255 blue:255]];
} break;
case KNCategoryStateStateExpanded:
{
[UIView animateWithDuration:10.0f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^{
self.arrowImage.transform = CGAffineTransformMakeRotation(M_PI_2);
} completion:^(BOOL finished) {
}];
[self.contentView setBackgroundColor:[UIColor red:230 green:230 blue:230]];
} break;
}
}正如我所说的,旋转是工作的,但它立即旋转视图,以适当的M_PI_2,似乎没有动画。
我使用了Xcode 6.1和iOS 8.1模拟器进行测试。
另外,我在自定义单元格中实现了单个点击手势,并实现了以下方法:
- (void)singleTap
{
[self.delegate sectionDidTappedWithIndex:self.index];
}delegate,它是我的视图控制器,它包含显示所有自定义单元格的表。
在视图控制器中,我实现了设置头、展开和重新加载数据的方法:
- (void)sectionDidTappedWithIndex:(NSInteger)index
{
for (KNCategoryPoxy *category in _categories)
{
category.state = KNCategoryStateStateCollapsed;
}
KNCategoryPoxy *category = [_categories objectAtIndex:index];
category.state = !category.state;
[self.theTableView reloadData];
}发布于 2018-06-06 11:18:14
尝试使用UIView.commmitAnimations()执行动画,例如:
UIView.beginAnimations(“rotation”, context: nil)
UIView.setAnimationDuration(0.8)
cell.layer.transform = CATransform3DIdentity
cell.alpha = 1
cell.layer.shadowOffset = CGSize(width: CGFloat(0), height: CGFloat(0))
UIView.commitAnimations()还尝试在willDisplayCell:方法中执行操作。
请参考此http://www.thinkandbuild.it/animating-uitableview-cells/解决方案在tableview单元格中执行动画。
https://stackoverflow.com/questions/27447635
复制相似问题