【发布时间】:2013-03-18 12:12:03
【问题描述】:
我将shadows 添加到UITableView 的各个单元格中。阴影在意义上不一致,请考虑以下场景:
有 20 行要显示,最初,在第一个视图中只有 10 行可见。此处阴影按预期正确可见。但是,一旦我向下/向上滚动,现在可见的一些新单元格会按预期显示阴影,而其他单元格则不会。问题似乎出在UITableViewCell 的layer 的zPosition 上。对于某些单元格,阴影在后面,而对于其他单元格,阴影在前面,而位于其下方的单元格则使其对用户可见/不可见。
因为,我遇到的大多数帖子(例如Objective C: How to add Shadow effect to navigation bar and table cells)都没有明确设置UITableViewCell 层的zPosition,所以我想知道这是必需的还是我在这里遗漏了一些东西。
编辑:请在此处找到代码 sn-ps
-(UITableViewCell*)tableView:(UITableView*) tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
navigatorCell* cell = (navigatorCell *)[tableView dequeueReusableCellWithIdentifier:@"cellIdentifier"] forIndexPath:indexPath];
// cell configuration code goes here
//now add shadow
[cell.layer setMasksToBounds:NO];
cell.layer.shadowColor = [[UIColor blackColor] CGColor];
cell.layer.shadowOffset = CGSizeMake(0.0f, 5.0f);
cell.layer.shadowRadius = 3.0f;
cell.layer.shadowOpacity = 0.750f;
cell.clipsToBounds = NO;
//if I uncomment this, then it works properly, but problem arises again if I insert/remove cells
// cell.layer.zPosition = -indexpath.row;
CGRect shadowFrame = cell.layer.bounds;
CGPathRef shadowPath = [UIBezierPath bezierPathWithRect:shadowFrame].CGpath;
cell.layer.shadowPath = shadowPath;
return cell;
}
【问题讨论】:
-
能发一下截图吗……
-
您能否添加您的代码。没有代码我什么都做不了
-
请找到上面的代码。
标签: iphone ios ipad uitableview