![](/img/trans.png)
[英]UIView.animateWithDuration does not work within a UITableviewCell
[英]UITableViewCell animateWithDuration does not work
我在自定義單元格上有圖像視圖。 單元上的所有元素都有約束。 我已經實現了這種方法來動畫我的箭頭。 旋轉效果很好,但沒有動畫。 我有調試單元,從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];
}
嘗試使用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: Method中執行操作。
請參考此http://www.thinkandbuild.it/animating-uitableview-cells/解決方案以在tableview單元內執行動畫
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.