Objective c 使用CentreY约束设置子视图的动画

Objective c 使用CentreY约束设置子视图的动画,objective-c,uitableview,uiviewanimation,Objective C,Uitableview,Uiviewanimation,我有一个带两个UILabel和一个UISwitch的UITableViewCell。这些标签是多行的,并相互重叠放置。开关垂直居中。当我关闭开关时,我会隐藏其中一个标签,行的高度也会改变。这会导致开关在我调用时跳转: [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; 以下是我的tableviewcell类实现: [self.tableVi

我有一个带两个UILabel和一个UISwitch的UITableViewCell。这些标签是多行的,并相互重叠放置。开关垂直居中。当我关闭开关时,我会隐藏其中一个标签,行的高度也会改变。这会导致开关在我调用时跳转:

[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
以下是我的tableviewcell类实现:

[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
 - (void)setBounds:(CGRect)bounds
{
  [super setBounds:bounds];

  self.contentView.frame = self.bounds;
}

- (void)setUpView{

    self.numberLabel.text = [NSString stringWithFormat:@"Quote number %ld",    [self.cellData[@"rowNumber"] integerValue]];
    [self.controlSwitch setOn:[self.cellData[@"checked"] boolValue]];

    [UIView animateWithDuration:0.5 animations:^{
    if ([self.controlSwitch isOn]) {
        self.quoteLabel.text = self.cellData[@"quote"];
        self.quoteLabel.hidden = NO;
        self.bottomConst.constant = 10;
    }else{
        self.quoteLabel.text = @"";
        self.quoteLabel.hidden = YES;
        self.bottomConst.constant = 0;
    }
 }];


}

- (void)layoutSubviews
{
  [super layoutSubviews];

  self.selectionStyle = UITableViewCellSelectionStyleNone;
  [self.contentView updateConstraintsIfNeeded];
  [self.contentView layoutIfNeeded];

  self.numberLabel.preferredMaxLayoutWidth = CGRectGetWidth(self.numberLabel.frame);
  self.quoteLabel.preferredMaxLayoutWidth = CGRectGetWidth(self.quoteLabel.frame);
}


- (IBAction)removeQuote:(id)sender {
   [self.delegate updateCell:self];
}
UITableViewCell上的约束设置如下所示

[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
当开关打开时,我只需取消隐藏引号标签并设置文本。 是关于它看起来如何的链接。这是默认行为还是有一种方法可以在行设置动画时控制开关的移动?

尝试以下操作:

[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
...
[self.contentView updateConstraintsIfNeeded];

[UIView beginAnimations:nil context:nil];
[self.contentView layoutIfNeeded];
[UIView commitAnimations];
...

那没用。是开关上的约束中心导致其跳转