Note that there are some explanatory texts on larger screens.

plurals
  1. POAnimating UICollectionView cell resize triggered by switching layouts
    primarykey
    data
    text
    <p>I am trying to animate between various UICollectionViewFlowLayout subclasses. Each flow layout specifies a different item size. One displays a grid with 3 items across, another a grid with 2 items across, and the third with only 1 item across (Looks like a UITableView).</p> <p>I am calling setCollectionViewLayout:animated: to do this. The animation of the cell sizes works perfectly. However the subviews are a bit of a mess. Each cell contains an image and a label (Have removed the label for now). I want the image to animate its change in size as the cell changes in size, likewise the label.</p> <p>If I use auto layout (not very good at this yet) to layout the subviews of my cell then at the start of the animation the image is resized to the destination cell frame. I understand how UIView animations work in that they change the animated property straight away and the animation is done in the presentation layer, but I expected auto layout to work differently somehow.</p> <p>If I remove auto layout and do the following in initWithFrame:</p> <pre><code>[[self imageView] setAutoresizingMask:UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleRightMargin]; </code></pre> <p>then the size of the image subview animates quite nicely, however after cycling through a few animations the image subview size and location is incorrect in some cases.</p> <p>I've tried laying out the subviews in layoutSubviews, but this gives the same result as AutoLayout.</p> <p>All of the demos I've seen on github for animating between UICollectionViewLayouts have just a coloured background or a subview which fills the entire cell. Has anyone managed to get this working?</p> <p>Below are images of what is occurring (red line is border of UIImageView):</p> <p><a href="http://i44.tinypic.com/2zzkjsy.png">First Layout</a></p> <p><a href="http://i39.tinypic.com/141sj6o.png">Second Layout</a></p> <p><a href="http://i39.tinypic.com/zsuvf9.png">Third Layout</a></p> <p><a href="http://i39.tinypic.com/1rywrq.png">Back to first layout, but subview frames are wrong</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload