UITableViewCell not clipping to bounds in editing mode in iOS8 (works in iOS7.1)

[亡魂溺海] 提交于 2019-12-06 21:48:39

问题


I am setting the height of a UITableViewCell so that it will clip and not all the content for the row is visible. This works fine in iOS7 both "not edit" mode and "edit" mode. In iOS8 it is only working in "not edit" mode. When editing the entire content of the cell is shown after the red delete button on the left is tapped so that you see the delete button on the right.

I had been setting cell.clipsToBounds = YES and thought this was all I needed to do.

EDIT: I also tried cell.contentView.clipsToBounds = YES but this didn't work.

iOS7: (this is what I want)

iOS8:


回答1:


Looks like the UITableView in iOS 8 set cell.contentView.clipToBounds to NO when begin editing. This code help me resolve your issue:

- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.contentView.clipsToBounds = YES;
}



回答2:


I tried Vitaliy and ToddB's solutions and unfortunately they were not always 100% consistent for me although they did work most of the time.

I hate to have to override layoutSubviews but I've found no other solution that works 100% of the time thus far :'(

override func layoutSubviews() {
    super.layoutSubviews()
    self.contentView.clipsToBounds = true
}


来源:https://stackoverflow.com/questions/27432095/uitableviewcell-not-clipping-to-bounds-in-editing-mode-in-ios8-works-in-ios7-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!