Frame is not changing in cellForRowAtIndexPath

前端 未结 2 581
故里飘歌
故里飘歌 2021-01-27 19:44

I want to change the x position frame of view inside the cell in cellForRowAtIndexPath for certain conditions. I have used the following code. But it d

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-27 20:19

    Because of the iOS layout render process, your custom UITableViewCell's layoutSubviews may called more than once. In your case you can change the items frames in the GoalDetailsTableViewCell class's layoutSubviews method.

    @implementation GoalDetailsTableViewCell
    
    -(void)layoutSubviews
    {
        [super layoutSubviews];
        [UIView animateWithDuration: 0.5 animations:^{
                        cell.cardDetails.frame = CGRectOffset(cell.cardDetails.frame, -322.0, 0.0);
                        //        CGRectOffset(cell.cardView.frame, -320.0, 0.0);
                        cell.actionCardReminder.frame = CGRectOffset(cell.actionCardReminder.frame, -322.0, 0.0);
                    }];
         NSLog(@"%f", cell.cardDetails.frame.origin.x);
    }
    @end
    

提交回复
热议问题