9

Calling [self.view layoutIfNeeded]; in the animation block causes all of its child views to animate.

This causes a problem whilst scrolling a UICollectionView because the UICollectionViewCells animates onto the screen.

enter image description here

Is there anyway I can stop the Portsmouth cell from animating in?

** EDIT **

To add insult to injury I am animating the constraints that are controlling the height of the UICollectionView. To increase the size of the feed, I have a disappearing UIView acting like a header.

William George
  • 6,735
  • 3
  • 31
  • 39
  • Have you found any solution/workaround for this? I'm experiencing the same problem with constraints animation – vir us Sep 10 '14 at 13:24
  • @virus - In my case, I made the `UICollectionView` full screen and animated the `contentInsets` instead - However this has caused some other issues - I would much prefer this collection view bug resolved :s – William George Sep 10 '14 at 22:23
  • I'm guessing that making the Collection View full screen and changing it's content offset is the only way for now ? – michal.ciurus Jun 05 '15 at 07:11

2 Answers2

4

You can layoutIfNeeded on any view, so perhaps consider changing the view hierarchy of your cell to isolate the view that contains the constraints that need animating. So that your layoutIfNeeded call only triggers animations on the constraints you intend to animate. Does that make sense?

This would mean inserting a UIView into your hierarchy, and this view would become the superview of the views you are animating via constraints.

Alfie Hanssen
  • 16,964
  • 12
  • 68
  • 74
1

I've spent hours trying to fix this bug, and finally I've found a solution:

[UIView setAnimationsEnabled:NO];
       // Layout cell
[UIView setAnimationsEnabled:YES];

I've been using frames, not auto-layout, but maybe there's a way to disable animations for constraint layouting too.

EDIT:

You could try:

-(void)layoutSubviews
{
[UIView setAnimationsEnabled:NO];
   [super layoutSubviews];
[UIView setAnimationsEnabled:YES];
}
michal.ciurus
  • 3,616
  • 17
  • 32
  • Thanks Michal, I went with the content Inset animation. I will try to see whether turning animations off will solve the problem for auto layout. – William George Jun 08 '15 at 09:16