I'm planning to add one view to my collection view at a certain position. Therefore I want to use a decoration view. Now the position should change every minute. How can this be done with UICollectionView
on iOS 7 and iOS 8?
It seems that this can be done with invalidateLayoutWithContext
, but can multiple UICollectionViewLayoutInvalidationContext
be used for a layout?
When reading the documentation
To define a custom invalidation context for your layout, subclass the UICollectionViewLayoutInvalidationContext class. In your subclass, define custom properties that represent the parts of your layout data that can be recomputed independently. When you need to invalidate your layout at runtime, create an instance of your invalidation context subclass, configure the custom properties based on what layout information changed, and pass that object to your layout’s invalidateLayoutWithContext: method. Your custom implementation of that method can use the information in the invalidation context to recompute only the portions of your layout that changed.
If you define a custom invalidation context class for your layout object, you should also override the invalidationContextClass method and return your custom class. The collection view always creates an instance of the class you specify when it needs an invalidation context. Returning your custom subclass from this method ensures that your layout object always has the invalidation context it expects.
it seems that only one invalidation context can be used, because you don't know when to return which context in invalidationContextClass
.
There are times when I need to invalidate the complete layout (e.g. orientation change), but I also need to change the decoration view only.
Is this possible?
Other questions like here , here or here doesn't provide a complete solution for my case or only for iOS 8.