UICollectionViewCells 中的 CABasicAnimation 在屏幕外完成
CABasicAnimation inside UICollectionViewCells finish offscreen
我正在将自定义 CABasicAnimation 动画放置在 UICollectionViewCells 中。目的是一旦单元格出现在屏幕上,就会单独触发每个单元格的动画。我的方法是实现一个在单元格 class 上设置 CABasicAnimation 的函数。我从控制器的 willDisplayCell 调用它。
此方法适用于所有重复使用的单元格。但是,最初为控制器加载的所有单元将立即(屏幕外)完成动画,而不是根据动画时间。可能是什么问题?
// Cell
-(void)animate {
[CATransaction begin]; {
// My timed animations (CABasicAnimation)
} [CATransaction commit];
}
// Controller
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
[((CustomCell*)cell) animate];
}
在你的手机上试试这个 class:
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
[self animate];
}
我通过应用以下更改解决了这个问题。感觉像是黑客,但至少它有效。
// Controller
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[((CustomCell*)cell) animate];
});
}
我正在将自定义 CABasicAnimation 动画放置在 UICollectionViewCells 中。目的是一旦单元格出现在屏幕上,就会单独触发每个单元格的动画。我的方法是实现一个在单元格 class 上设置 CABasicAnimation 的函数。我从控制器的 willDisplayCell 调用它。
此方法适用于所有重复使用的单元格。但是,最初为控制器加载的所有单元将立即(屏幕外)完成动画,而不是根据动画时间。可能是什么问题?
// Cell
-(void)animate {
[CATransaction begin]; {
// My timed animations (CABasicAnimation)
} [CATransaction commit];
}
// Controller
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
[((CustomCell*)cell) animate];
}
在你的手机上试试这个 class:
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
[self animate];
}
我通过应用以下更改解决了这个问题。感觉像是黑客,但至少它有效。
// Controller
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[((CustomCell*)cell) animate];
});
}