TableviewCell accesory view moves when the height of row is increased(expanded)

51 views Asked by At

I use a animation to incrementing the height of a row, when user tap the row and I use a custom accessory view, but when I increase the height of the row the accessory view moves down on it y axis y aproximately half of the row, this is annoying. How can I mantain the accesory view on top of the row? when I doing the animation of increasing the height of row and turn the accessory 90 degree. attaching code and image

This code animates the tableview

         self.flag = !self.flag;

        [tableView beginUpdates];
        [tableView reloadRowsAtIndexPaths:@[indexPath]
                              withRowAnimation:UITableViewRowAnimationAutomatic];

        [tableView endUpdates];

This code increasing the row height

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:    (NSIndexPath *)indexPath{

    if (indexPath.section == 1 ){

    if (indexPath.row == 0) {

        return YES == self.flag ? 70 : 44;

    }else if (indexPath.row == 1) {

        return YES == self.flag ? 70 : 44;

    }
    }

And this code turns the custom accessory view 90 degrees

 self.accesoryButton.transform = CGAffineTransformMakeRotation(M_PI / 2.0f);

This image shows how the accessory moves down on y axis

1

There are 1 answers

1
Mike On
# tableViewCell.m

- (void)layoutSubviews
{
    [super layoutSubviews];
    CGRect adjustedFrame = self.accesoryButton.frame;
    adjustedFrame.origin.y = self.accesoryButton.y;
    self.accesoryButton.frame = adjustedFrame;
}