AnimateWithDuration in the setSelected method of UITableViewCell has no effect

I’m trying a simple animation for selection/deselection of a UITableViewCell like this:

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

    [UIView animateWithDuration: 0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{

        tabConstraint.constant = selected ? 40 : 20;

    } completion:nil];
}

The code inside the animations block will be called, but it’s not animating. Everything works fine, but there’s not any animation at all. How could I make the cell selection animated?

Every time you update a autolayout constraint, you have to call layoutIfNeeded,

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

    [UIView animateWithDuration: 0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{

        tabConstraint.constant = selected ? 40 : 20;
        [self layoutIfNeeded];

    } completion:nil];
}
Hello, buddy!稿源:Hello, buddy! (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 移动开发 » AnimateWithDuration in the setSelected method of UITableViewCell has no effect

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录