[英]iOS: Animate color change from left to right
我想从左到右(像进度条一样)设置UITableViewCell
的背景色,但我很困惑。 这可能吗?
编辑
建议添加一个背景视图,该视图会定期扩展其宽度,但这种方法不起作用。 这是我现在拥有的代码:
// in viewDidLoad
self.tableView.reloadData()
self.beginWorkout()
...
// beginWorkout
private func beginWorkout() {
let indexPath = NSIndexPath(forRow: 1, inSection: 0)
let cell = self.tableView.cellForRowAtIndexPath(indexPath) as! MovementCell
cell.animateProgressView()
}
...
// MovementCell animateProgressView
func animateProgressView() {
UIView.animateWithDuration(15, animations: {
self.progressViewWidth.constant = self.screenWidth
})
}
但动画不会随着时间的流逝而执行。 progressViewWidth
常数立即变为屏幕宽度。
你可以做,
UIView * testView = [[UIView alloc] initWithFrame:CGRectMake(320.0f, 100.0f, 320.0f, 200.0f)];
[testView setBackgroundColor:[UIColor blueColor]];
[self.view addSubview:testView]; //In your case cell's content view
[UIView animateWithDuration:0.7f
delay:0.0f
options:UIViewAnimationOptionTransitionNone
animations:^{
[testView setFrame:CGRectMake(0.0f, 100.0f, 320.0f, 200.0f)];
}
completion:nil];
您可以更改不同的动画选项。 例如,如果您想自动反向并重复,则可以使用UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
作为选项。
希望这会有所帮助:)
如果您希望它的行为像进度条一样,则将UIView(例如蓝色背景)放在Z顺序最低的单元格中。
现在设置其相对于单元格宽度的宽度的动画。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.