我一直有同样的问题,其他人与UITableViewCell剪裁到它的界限。正如其他人正确指出的那样,该单元的contentView有一个新的超级视图。所以我这样做:iOS 7 UITableViewCell剪辑TEMPORARILY
- (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:
通过检索标记细胞的子视图,并加载适当的内容。这工作正常。没有其他提到clipToBounds
或layer.masksToBounds
。但是:当我重新加载选中的单元格时,它临时剪辑到边界,然后它碰到上面的代码,并得到它的权利。所以大约1-2秒钟后,我将细胞剪掉。这是ItemCell
内部正在发生的事情。我只是让这个类去看看那个clipToBounds
属性为TRUE。
@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;
}
}
即使我将它们变为假时他们变为TRUE,我仍然得到剪切/未剪切之间的差距。它只是更小。这在iOS6上没有发生。这是堆栈跟踪时clipsToBounds
财产变为1,则可以看到CALayer setMasksToBounds
被自动调用:
没有人有任何修补程序的任何想法?谢谢!
我想我有类似的问题。 – djskinner
如果您找到任何解决方案,请让我知道。到目前为止我没有得到任何东西,我有很多项目需要开展工作,而且小故障被经理声明为“可接受的”,所以我再也没有做过这方面的工作。但我仍然好奇。 – George