我的自定义 UITableViewCell
中有一个 UIImageView
、UILabel
、UIButton
。
当我将编辑模式设置为"is"时,整个单元格框架向右移动太多。
上下滚动表格似乎可以解决这个问题。
但是为什么会发生这种情况以及我该如何解决它?
最佳答案
在您的自定义 UITableViewCell 中使用layoutSubviews 和 willTransitionToState。 在你的 .h 文件中添加 int state; 在您的 .m 单元格中添加
- (void)willTransitionToState:(UITableViewCellStateMask)aState
{
[super willTransitionToState:aState];
state = aState;
}
还添加以下内容:
- (void)layoutSubviews
{
[super layoutSubviews];
self.contentView.frame = CGRectMake(0,
self.contentView.frame.origin.y,
self.contentView.frame.size.width,
self.contentView.frame.size.height);
if (self.editing )
{
switch (state) {
case 2:
// swipe action -> here you play with how much your content will move
self.contentView.frame = CGRectMake(90,
self.contentView.frame.origin.y,
self.contentView.frame.size.width-90,
self.contentView.frame.size.height);
break;
}
} else {
NSLog(@"subview not in edit %i",state);
self.contentView.frame = CGRectMake(0,
self.contentView.frame.origin.y,
self.contentView.frame.size.width,
self.contentView.frame.size.height);
[self setNeedsDisplay];
}
}
这应该足以自定义缩进。
关于ios - UITableViewCell contentView 框架在编辑模式下向右移动太多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27126896/