我想在用户点击单元格时创建一个阴影动画效果,单元格中会有一个阴影"增长"从0到预期的半径。
以下是代码的快照,但我无法将其设置为动画:
-(void) tableView:(UITableView *)tableView_ didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
[CATransaction begin]; {
[CATransaction setAnimationDuration:5];
cell.layer.shadowOpacity = 1.0;
cell.layer.shadowRadius = 20;
cell.layer.shadowColor = [UIColor blackColor].CGColor;
cell.layer.shadowOffset = CGSizeMake(0.0, 0.0);
}
[CATransaction commit];
[tableView_ deselectRowAtIndexPath:indexPath animated:YES];
}
-(void) tableView:(UITableView *)tableView_ didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
CABasicAnimation *animShadow = [CABasicAnimation animationWithKeyPath:@"shadowRadius"];
animShadow.fromValue = [NSNumber numberWithFloat:0.0];
animShadow.toValue = [NSNumber numberWithFloat:20];
animShadow.duration = 3.0;
[cell.layer addAnimation:animShadow forKey:@"shadowRadius"];
[tableView_ deselectRowAtIndexPath:indexPath animated:YES];
}
有什么建议吗?