iOS 7 UITableViewCell临时剪辑
我和其他人一样,在UITableViewCell剪裁到其边界时遇到了同样的问题。正如其他人正确指出的那样,单元格的contentView有一个新的superview。所以我这样做了:iOS 7 UITableViewCell临时剪辑,uitableview,ios7,cliptobounds,Uitableview,Ios7,Cliptobounds,我和其他人一样,在UITableViewCell剪裁到其边界时遇到了同样的问题。正如其他人正确指出的那样,单元格的contentView有一个新的superview。所以我这样做了: - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *cellIdentifier = @"HomeTableViewCell";
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellIdentifier = @"HomeTableViewCell";
ItemCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(!cell)
{
cell = [[ItemCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
//add views here as subviews to cell.contentView. Set them tags and retrieve later.
}
cell.clipsToBounds = FALSE;
cell.layer.masksToBounds = FALSE;
cell.contentView.clipsToBounds = FALSE;
cell.contentView.layer.masksToBounds = FALSE;
cell.contentView.superview.clipsToBounds = FALSE;
cell.contentView.superview.layer.masksToBounds = FALSE;
[self loadCell:cell inTable:tableView atIndexPath:indexPath];
return cell;
}
loadCell:inTable:atIndexPath:
通过标记检索单元格的子视图并加载适当的内容。那很好。没有其他提到cliptobunds
或layer.masksToBounds
。但是:当我重新加载选定的单元格时,它会临时剪辑到边界,然后点击上面的代码并将其正确。因此,大约1-2秒钟,我将细胞剪断。这就是ItemCell
中发生的事情。我创建这个类只是为了看看是什么将cliptobunds
属性变成了真
@implementation ItemCell
- (id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]))
{
[self addObserver:self forKeyPath:@"layer.masksToBounds" options:NSKeyValueObservingOptionNew context:nil];
[self addObserver:self forKeyPath:@"clipsToBounds" options:NSKeyValueObservingOptionNew context:nil];
}
return self;
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
NSNumber *nr = [change objectForKey:@"new"];
if(nr.intValue)
{
self.clipsToBounds = FALSE; // STAY FALSE!!
self.layer.masksToBounds = FALSE;
}
}
即使当它们变为真时,我把它们弄错了,但我仍然得到了剪裁/未剪裁之间的差距。只是小一些。这在iOS6上没有发生。这是当clipstobunds
属性变为TRUE时的堆栈跟踪,您可以看到CALayer setMasksToBounds
被自动调用:
有人知道有什么办法吗??谢谢大家! 我现在似乎已经在代码中解决了这个问题。首先,确保在Interface Builder中设置了有关剪裁等的所有内容。然后,似乎需要以下代码的全部或部分组合: 在
tableView:cellforrowatinexpath:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
//ios7 hacks
[cell.contentView.superview setClipsToBounds:NO];
[cell.contentView setClipsToBounds:NO];
[cell setClipsToBounds:NO];
return cell;
}
在tableView:willDisplayCell:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
//ios 7 cell background fix
[cell.contentView.superview setClipsToBounds:NO];
[cell.contentView setClipsToBounds:NO];
[cell setClipsToBounds:NO];
[cell setBackgroundColor:[UIColor clearColor]];
//ios 7 content clipping fix
[cell.contentView.superview setClipsToBounds:NO];
[cell.contentView setClipsToBounds:NO];
[cell setClipsToBounds:NO];
}
我想我也遇到了类似的问题。如果你有任何解决办法,请告诉我。到目前为止,我什么都没有得到,我有很多项目要做,经理宣布这个小故障是“可以接受的”,所以我再也没有做过了。但我还是很好奇。谢谢你的回复。我曾尝试使用“willDisplayCell”实现这一点,但不幸的是,它也不起作用。另一件可能适用的事情是,我最终关闭了动画-只是使用
重新加载数据,而不是开始更新和结束更新。显然,这不是一个理想的解决方案!我正在重新装入2个电池。以前选择的和新选择的。“开始”和“结束”更新是在您希望同时执行更多操作并设置动画时使用的…例如删除一行、更新另一行和插入另一行,而不是设置每件事的动画。我将尝试使用“UITableViewCellAnimationNone”,但顺便说一句,这里仍然涉及一些动画(在WWDC关于表格的视频中看到了这一点。)谢谢!