【发布时间】:2015-04-15 09:11:58
【问题描述】:
我想让特殊的UITableViewCells 闪烁它的边框。问题是我无法同步边框闪烁并且我的单元格“随机”闪烁。
这是我尝试过的。我有self.borderAnimationStartDate 来设置初始时间点。我在显示单元格时添加闪烁动画,并尝试为单元格的图层设置“时间偏移”(beginDate)。
- (void)tableView:(UITableView*)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
// ...
if (myCondition)
{
Z9EmptySlotCell* emptySlotCell = (Z9EmptySlotCell*)cell;
emptySlotCell.isNew = YES;
[emptySlotCell.backgroundCellView.layer addAnimation:self.borderAnimation forKey:@"color"];
emptySlotCell.backgroundCellView.layer.beginTime = -[[NSDate date] timeIntervalSinceDate:self.borderAnimationStartDate];
}
}
}
- (CABasicAnimation*)borderAnimation
{
if (!_borderAnimation)
{
_borderAnimation = [CABasicAnimation animationWithKeyPath:@"borderColor"];
_borderAnimation.fromValue = (id)[UIColor colorWithRed:255.0/255.0 green:231.0/255.0 blue:153.0/255.0 alpha:1].CGColor;
_borderAnimation.toValue = (id)[UIColor clearColor].CGColor;
_borderAnimation.duration = 2;
_borderAnimation.repeatCount = HUGE_VALF;
}
return _borderAnimation;
}
【问题讨论】:
-
如何设置self.borderAnimationStartDate?
-
ZeMoon,现在我在
viewDidLoad中将其设置为[NSDate date]。将来我计划在添加一些视图后设置它的值 -
你必须大量使用通知来实现这一点。这是唯一的方法。
标签: ios objective-c uitableview core-animation calayer