1

从右端开始,我必须填充颜色UITableViewCell(或者更好地说,UITableViewCell在一小段时间内改变从右到左开始的背景)。我怎样才能做到这一点?

4

2 回答 2

4

这很容易。

只需在背景中放置一个视图,从 0 宽度开始,在 tableview/tableview 单元格的右侧,然后将其动画到父视图的全宽。

代码片段(以 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)

渲染:在此处输入图像描述

于 2016-03-10T10:11:17.637 回答
1

试试这个

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];
于 2016-03-10T10:11:25.300 回答