UITableViewCell animate height issue in iOS 10

后端 未结 7 1855
余生分开走
余生分开走 2020-12-13 14:23

My UITableViewCell will animate it\'s height when recognizing a tap. In iOS 9 and below this animation is smooth and works without issues. In iOS 10 beta there\

7条回答
  •  盖世英雄少女心
    2020-12-13 15:01

    I don't use auto layout, instead I derive a class from UITableViewCell and use its "layoutSubviews" to set the frames of the subviews programmatically. So I tried to modify cnotethegr8's answer to fit my needs, and I came up with the following.

    Reimplement "setFrame" of the cell, set the cell's content height to the cell height and trigger a relayout of the subviews in an animation block:

    @interface MyTableViewCell : UITableViewCell
    ...
    @end
    
    @implementation MyTableViewCell
    
    ...
    
    - (void) setFrame:(CGRect)frame
    {
        [super setFrame:frame];
    
        if (self.window)
        {
            [UIView animateWithDuration:0.3 animations:^{
                self.contentView.frame = CGRectMake(
                                            self.contentView.frame.origin.x,
                                            self.contentView.frame.origin.y,
                                            self.contentView.frame.size.width,
                                            frame.size.height);
                [self setNeedsLayout];
                [self layoutIfNeeded];
            }];
        }
    }
    
    ...
    
    @end
    

    That did the trick :)

提交回复
热议问题