Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable auto layout animation for one view

Tags:

ios

I'm sorry, I don't know a better title.

The issue:

I've got one UITableViewCell with auto layout, the default height in the nib is 300. 300 is the correct size for one of my UIViewControllers.

I'm using a UINavigationController inside a container view, beneath the container view is a UIView called FooterView.

In the container view are two UIViewControllers; VC1 and VC2.

When I'm pushing VC2 onto VC1, I'm also changing the height of FooterView with it's NSLayoutConstraint height constant.

I'm doing this inside a animation block, with [self.view setNeedsLayout];

I'm setting the height for the UITableViewCell inside VC2 to 200.

Now the problem is that when I'm transitioning from VC1 to VC2 you also see the UITableViewCell being animated from 300 to 200.

My guess is that this is because of the animation block. I've tested it by removing the animation and the cell didn't animate (as expected).

Is there any way to stop this animation chaining?

I'm sorry if I'm not clear enough.

like image 713
Rick van der Linde Avatar asked Nov 22 '15 16:11

Rick van der Linde


1 Answers

All I needed to do was to override layoutSubviews inside the cell:

- (void)layoutSubviews
{
    [UIView performWithoutAnimation:^{
        [super layoutSubviews];
        [self.contentView layoutIfNeeded];
        _shadowView.layer.shadowPath = [UIBezierPath bezierPathWithRect:_shadowView.bounds].CGPath;
    }];
}
like image 131
Rick van der Linde Avatar answered Sep 23 '22 21:09

Rick van der Linde