3

When you invalidate layout on a UICollectionViewFlowLayout it creates a bunch of new layout attributes for each of your cells; it doesn't tell your cells to redraw however, which causes distortions in any Layer drawings.

I don't want to tell my collection to reload its data because this removes any nice transitions you have between flow attributes : I have a grid layout transitioning into a coverflow for example.

I need a way for the UICollectionViewController class to tell the cells to call their [setNeedsDisplay] method after being given the layout attributes.

nsgulliver
  • 12,655
  • 23
  • 43
  • 64
Lee Probert
  • 10,308
  • 8
  • 43
  • 70

1 Answers1

4

When your cells change size, it's up to them how to handle that (stretching vs redrawing). This is controlled by the UIView contentMode property; try setting it to UIViewContentModeRedraw to cause resizing to invalidate your views contents like setNeedsDisplay: would.

If you're using CALayers directly as sub-layers of your cell, you can set their needsDisplayOnBoundsChange to YES in order to get the same effect.

Jesse Rusak
  • 56,530
  • 12
  • 101
  • 102
  • needsDisplayOnBoundsChange is OSX only I believe. UIViewContentModeRedraw works but slows it down a tad during the layout transitions. You're right though, the views need to handle their own state. I'll use the contentMode property. Thanks. – Lee Probert Mar 12 '13 at 15:50
  • @LeeProbert You're welcome. The docs seem to say that needsDisplayOnBoundsChange is on CALayer from iOS 2 and up. – Jesse Rusak Mar 12 '13 at 15:52
  • yea, you're correct. I can't seem to get it to recognise the property. – Lee Probert Mar 12 '13 at 16:06
  • weird : https://www.evernote.com/shard/s4/sh/9bd7c9c0-3a80-46b2-bd31-b68426db4202/1a7a58be89f77e9abec62618b65cacb9 – Lee Probert Mar 12 '13 at 16:10
  • The key in that error message is "on *forward* class CALayer"; this means it can't find a definition for CALayer and so none of its methods will be available. Try `#include ` in this file (and add to your project if needed). – Jesse Rusak Mar 12 '13 at 16:12
  • Yes, you're right. I'd thought it was included in my prefix file. Thanks for your help. This works a treat. – Lee Probert Mar 13 '13 at 10:03