2014-11-25 69 views
2

我在我的自定义UITableViewCell中有UIImageView,UILabel,UIButton。 当我将编辑模式设置为YES时,整个单元格框架向右移动太多。UITableViewCell contentView框在编辑模式下移动得太多

上下滚动表格似乎可以修复它。

但是,为什么会发生,我怎么才能真正解决它?

+0

“太多”相比有哪些这将解决问题了吗?相比之下没有什么,或者你期望的缩进?如果是后者,你为什么期望这个确切的距离;你有没有调整过这个值? – Andreas 2014-11-25 12:39:56

+0

与正常帧移动相比太多。我甚至不知道如何调整这个值。 – 2014-11-25 12:44:13

回答

2

在您的自定义UITableViewCell中使用layoutSubviews和willTransitionToState。 在你的.h文件中添加int状态; 在您的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]; 
    } 
} 

这应该是足够的定制缩进。

1

这通常发生是由于细胞的布局是没有得到所谓的使用习惯小区设置layoutSubviews帧