我正在一个项目中,我需要将某些收藏夹视图单元格背景色设置为闪烁状态。我在我的collectionviewcell子类上使用以下代码:
- (void) fadeInAnimation{
if (!self.animationRunning) {
if ([self canRunAnimation]) {
typeof(self) __weak weakSelf = self;
self.nameLabel.textColor = [UIColor blackColor];
self.animationRunning = true;
[UIView animateWithDuration:1.0
delay:0.0
options: UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionAllowUserInteraction animations:^{
self.backgroundColor = [self.backgroundColor colorWithAlphaComponent:1.0];
}
completion:^(BOOL finished) {
[weakSelf fadeOutAnimation];
}];
}
else {
[self.layer removeAllAnimations];
self.backgroundColor = [self.backgroundColor colorWithAlphaComponent:1.0];
}
}
}
- (void) fadeOutAnimation {
typeof(self) __weak weakSelf = self;
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionAllowUserInteraction animations:^{
self.backgroundColor = [self.backgroundColor colorWithAlphaComponent:0.65];
}
completion:^(BOOL finished) {
weakSelf.animationRunning = NO;
[weakSelf fadeInAnimation];
}];
}
我的问题是,即使此代码有效,我认为它也不是很有效,需要清理。我还需要的是,当前正在运行的所有动画都应同步闪烁,但是我的代码使单元在不同的时间淡入和淡出。我有一个刷新方法,该方法每隔几秒钟就会根据API调用的结果刷新一次UI。有什么想法可以同步当前正在运行的UIAnimations吗?我希望我已经清楚我的问题。
我通过遍历视图的子视图并捕获多个子视图上的所有collectionview单元来解决问题,一旦有了它们,我便会逐渐使用alpha分量设置它们的背景色。 :Animation UITableViewCell backgroundcolor
- (void) animateCellFromView:(UIView*)subview {
if ([subview isKindOfClass:[PageCollectionItemCell class]]) {
PageCollectionItemCell *cell = (PageCollectionItemCell*)subview;
if ([cell canRunAnimation]) {
cell.backgroundColor = [cell.backgroundColor colorWithAlphaComponent:self.alpha];
}
}
}