【发布时间】:2016-06-25 02:41:58
【问题描述】:
从右端开始,我必须在UITableViewCell 中填充颜色(或者更好地说,在一小段时间内从右到左更改UITableViewCell 的背景)。我怎样才能做到这一点?
【问题讨论】:
标签: ios uicolor uitableview ios-animations
从右端开始,我必须在UITableViewCell 中填充颜色(或者更好地说,在一小段时间内从右到左更改UITableViewCell 的背景)。我怎样才能做到这一点?
【问题讨论】:
标签: ios uicolor uitableview ios-animations
这很容易。
只需在背景中放置一个视图,从 0 宽度开始,在 tableview/tableview 单元格的右侧,然后将其动画到父视图的整个宽度。
代码 sn-p(以 Swift 游乐场的形式)
导入 UIKit 导入 XCPlayground
let tableView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 200))
tableView.backgroundColor = UIColor.whiteColor()
var animatedBackroundColorView = UIView(frame: CGRect(x: tableView.frame.width, y: tableView.frame.origin.y, width: tableView.frame.width, height: tableView.frame.height))
animatedBackroundColorView.backgroundColor = UIColor.orangeColor()
tableView.addSubview(animatedBackroundColorView)
UIView.animateWithDuration(1) { () -> Void in
animatedBackroundColorView.frame = tableView.frame
}
XCPShowView("identifier", view: tableView)
【讨论】:
试试这个
UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(cell.frame.size.width + 1,0,cell.frame.size.width,cell.frame.size.height)];
[backgroundView setBackgroundColor:yourColor];
[cell addSubview:backgroundView];
[UIView animateWithDuration:2.0 animations:^{
CGRect rect = backgroundView.frame;
rect.origin.x = 0;
[backgroundView setFrame:rect];
} completion:NULL];
【讨论】: