Animate UICollectionView contentInset adjustment - ios

Is there any way to animate the invalidateLayout() call on a UICollectionView layout? I have a collectionView with a custom layout, and a view that is animating on top of that collectionView. I would like to animate the repositioning of the cells in the collection view (much like a default UIScrollView implementation would do), but calling invalidateLayout() during an animation block repositions the cells with a fade animation, rather than an interpolation of the frames.
Is there any way to dictate the type of animation used in the layout change?

I finally found the answer, and hope this helps someone else. The trick was simply to call collectionView.performBatchUpdtes(nil, completion: nil) inside the animation block.

Related

UITableView layout animates on first load

I'm experiencing a strange behaviour in my UITableView. In my app when the UIViewController that contains the tableView is first shown (ViewDidLoad?) all of its elements (from cells to UISearchBar) are animating their sizes and finally get the right dimensions. After that (ViewWillAppear...), every time i present this view everything looks good. I'm using Autolayout in Storyboard and it's like the constraints are animating to their proper values. I'm using Swift 1.2, Xcode 6.4 and it's a UITabBar based app. Any ideas what i'm doing wrong? Thanks!
EDIT: My UITableView uses self-sizing cells with UITableViewAutomaticDimension height. It also contains a UISearchBar.
|search bar|
|---cell 1---|
|---cell 2---|
...
This usually happens when there is an animation in progress while the cells in the table view are about to load. Try looking into all the animations in your file and see which animation block is adding those animations to your table view cells.
Also if you are animating constraints using UIView animation block, do call [self.view layoutIfNeeded]
before the animation block and inside the block.

animation not correct with implicit autolayout

I upload my demo code here:https://github.com/liuxuan30/Problems
The main problem is, I had a view which have a scroll view inside, and there is a label and collection view inside scroll view.
There will be a unread message button generated by code, when there is unread messages, the button will pop out, and I expect the animation: label and collection view will down-shift by the button's height.
When I test the animation without adding the button in subviews, animate as expected.
When I add the button in, it seems like the label and collection view's origin.Y up-shifted, and start the animation. Turning off auto layout will solve it, but I have to have auto layout. I tried to add constraints for all views, but the animation still not work out.
You can try comment out
[self.HomeScrollView addSubview:AlertView]; and self.UnreadAlertView.alpha = 1.0f; inside the code to see the animation.
Hope someone could figure out where i did wrong.
UICollectionView is already a subclass of UIScrollView. Embedding your collection view inside a scroll view may be what is causing problems with your animation.
Try removing your scroll view and just put your UIButton, UILabel, and UICollectionView inside your overarching view.

Timing child view layout with UICollectionView layout changes

I have a UICollectionView that has a custom layout that changes the sizes of its cells when the device rotates. When the layout changes the size of a cell, layoutSubviews is called on each cell. This is what I want. However layoutSubviews does not execute in an animated manner but the change in size of the cell does. I would like to synchronize the two changes.
For example right now if the cell gets larger, the subviews resize instantly and then the cell size animates its change. I don't think I should put animation code in layoutSubviews. Is that correct? What is the best way to handle this?

UITableViewCell layoutSubViews: why don't I get animation?

I always thought that whatever changes I perform in layoutSubViews: is done animated?
Is this incorrect information?
In my case I'm inheriting from a UITableViewCell.
The controller gets informed that the user wants to enlarge the cells, so I first use a UITableView animation block to increase row height. The height increases smoothly animated to the new height.
Then I loop my visible cells, set a flag and call setNeedsLayout:
The cells indeed layout and adust the content to the new height but without animation.
No, that is not correct, the default approach for layoutSubviews will not be performed animated, it is up to you to begin / commit an animation block or use the blocks animation feature.

iPhone - layoutSubviews being called when updating subview

I have a custom view with a grid-like layout. When I touch each subview I want to animate them. The superview overrides layoutSubviews to create the grid of subviews.
The problem is whenever I change the frame of a subview for animation, the superview's layoutSubviews method is called overwriting the frame and no animation happens.
Why does layoutSubviews get called in this scenario and how can I prevent it?
There are other questions similar to this, but none of them have been properly answered.
Thanks!
I ended up adding a flag property on my superview and then set it to YES from my subview to prevent it from laying out subviews. Seems very hacky but it works.

Resources