Class: UICollectionViewLayout
Overview
The UICollectionViewLayout class is an abstract base class that you subclass and use to generate layout information for a collection view. The job of a layout object is to determine the placement of cells, supplementary views, and decoration views inside the collection view’s bounds and to report that information to the collection view when asked. The collection view then applies the provided layout information to the corresponding views so that they can be presented onscreen.
Direct Known Subclasses
Instance Attribute Summary (collapse)
-
- collectionView
readonly
The collection view object currently using this layout object.
Class Method Summary (collapse)
-
+ layoutAttributesClass
Returns the class to use when creating layout attributes objects.
Instance Method Summary (collapse)
-
- collectionViewContentSize
Returns the width and height of the collection view’s contents.
-
- finalizeAnimatedBoundsChange
Cleans up after any animated changes to the view’s bounds or after the insertion or deletion of items.
-
- finalizeCollectionViewUpdates
Performs any additional animations or clean up needed during a collection view update.
-
- finalLayoutAttributesForDisappearingDecorationElementOfKind:atIndexPath:
Returns the final layout information for a decoration view that is about to be removed from the collection view.
-
- finalLayoutAttributesForDisappearingItemAtIndexPath:
Returns the final layout information for an item that is about to be removed from the collection view.
-
- finalLayoutAttributesForDisappearingSupplementaryElementOfKind:atIndexPath:
Returns the final layout information for a supplementary view that is about to be removed from the collection view.
-
- initialLayoutAttributesForAppearingDecorationElementOfKind:atIndexPath:
Returns the starting layout information for a decoration view being inserted into the collection view.
-
- initialLayoutAttributesForAppearingItemAtIndexPath:
Returns the starting layout information for an item being inserted into the collection view.
-
- initialLayoutAttributesForAppearingSupplementaryElementOfKind:atIndexPath:
Returns the starting layout information for a supplementary view being inserted into the collection view.
-
- invalidateLayout
Invalidates the current layout and triggers a layout update.
-
- layoutAttributesForDecorationViewOfKind:atIndexPath:
Returns the layout attributes for the specified decoration view.
-
- layoutAttributesForElementsInRect:
Returns the layout attributes for all of the cells and views in the specified rectangle.
-
- layoutAttributesForItemAtIndexPath:
Returns the layout attributes for the item at the specified index path.
-
- layoutAttributesForSupplementaryViewOfKind:atIndexPath:
Returns the layout attributes for the specified supplementary view.
-
- prepareForAnimatedBoundsChange:
Prepares the layout object for animated changes to the view’s bounds or the insertion or deletion of items.
-
- prepareForCollectionViewUpdates:
Prepares the layout object to receive changes to the contents of the collection view.
-
- prepareLayout
Tells the layout object to update the current layout.
-
- registerClass:forDecorationViewOfKind:
Registers a class for use in creating decoration views for a collection view.
-
- registerNib:forDecorationViewOfKind:
Registers a nib file for use in creating decoration views for a collection view.
-
- shouldInvalidateLayoutForBoundsChange:
Asks the layout object if the new bounds require a layout update.
-
- targetContentOffsetForProposedContentOffset:withScrollingVelocity:
Returns the point at which to stop scrolling.
Methods inherited from NSObject
#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version
Constructor Details
This class inherits a constructor from NSObject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class NSObject
Instance Attribute Details
- (UICollectionView) collectionView (readonly)
The collection view object currently using this layout object. (read-only) The collection view object sets the value of this property when a new layout object is assigned to it.
Class Method Details
+ (Class) layoutAttributesClass
Returns the class to use when creating layout attributes objects. If you subclass UICollectionViewLayoutAttributes in order to manage additional layout attributes, you should override this method and return your custom subclass. The methods for creating layout attributes use this class when creating new layout attributes objects.This method is intended for subclassers only and does not need to be called by your code.
Instance Method Details
- (CGSize) collectionViewContentSize
Returns the width and height of the collection view’s contents. Subclasses must override this method and use it to return the width and height of the collection view’s content. These values represent the width and height of all the content, not just the content that is currently visible. The collection view uses this information to configure its own content size for scrolling purposes. The default implementation of this method returns CGSizeZero.
- (Object) finalizeAnimatedBoundsChange
Cleans up after any animated changes to the view’s bounds or after the insertion or deletion of items. The collection view calls this method after creating the animations for changing the view’s bounds or after the animated insertion or deletion of items. This method is the layout object’s opportunity to do any cleanup related to those operations. You can also use this method to perform additional animations. Any animations you create are added to the animation block used to handle the insertions, deletions, and bounds changes.
- (Object) finalizeCollectionViewUpdates
Performs any additional animations or clean up needed during a collection view update. The collection view calls this method as the last step before preceding to animate any changes into place. This method is called within the animation block used to perform all of the insertion, deletion, and move animations so you can create additional animations using this method as needed. Otherwise, you can use it to perform any last minute tasks associated with managing your layout object’s state information.
- (UICollectionViewLayoutAttributes) finalLayoutAttributesForDisappearingDecorationElementOfKind(elementKind, atIndexPath:elementIndexPath)
Returns the final layout information for a decoration view that is about to be removed from the collection view. This method is called after the prepareForCollectionViewUpdates: method and before the finalizeCollectionViewUpdates method for any decoration views that are about to be deleted. Your implementation should return the layout information that describes the final position and state of the view. The collection view uses this information as the end point for any animations. (The starting point of the animation is the view’s current location.) If you return nil, the layout object uses the same attributes for both the start and end points of the animation.The default implementation of this method returns nil.
- (UICollectionViewLayoutAttributes) finalLayoutAttributesForDisappearingItemAtIndexPath(itemIndexPath)
Returns the final layout information for an item that is about to be removed from the collection view. This method is called after the prepareForCollectionViewUpdates: method and before the finalizeCollectionViewUpdates method for any items that are about to be deleted. Your implementation should return the layout information that describes the final position and state of the item. The collection view uses this information as the end point for any animations. (The starting point of the animation is the item’s current location.) If you return nil, the layout object uses the same attributes for both the start and end points of the animation.The default implementation of this method returns nil.
- (UICollectionViewLayoutAttributes) finalLayoutAttributesForDisappearingSupplementaryElementOfKind(elementKind, atIndexPath:elementIndexPath)
Returns the final layout information for a supplementary view that is about to be removed from the collection view. This method is called after the prepareForCollectionViewUpdates: method and before the finalizeCollectionViewUpdates method for any supplementary views that are about to be deleted. Your implementation should return the layout information that describes the final position and state of the view. The collection view uses this information as the end point for any animations. (The starting point of the animation is the view’s current location.) If you return nil, the layout object uses the same attributes for both the start and end points of the animation.The default implementation of this method returns nil.
- (UICollectionViewLayoutAttributes) initialLayoutAttributesForAppearingDecorationElementOfKind(elementKind, atIndexPath:elementIndexPath)
Returns the starting layout information for a decoration view being inserted into the collection view. This method is called after the prepareForCollectionViewUpdates: method and before the finalizeCollectionViewUpdates method for any decoration views that are about to be inserted. Your implementation should return the layout information that describes the initial position and state of the view. The collection view uses this information as the starting point for any animations. (The end point of the animation is the view’s new location in the collection view.) If you return nil, the layout object uses the item’s final attributes for both the start and end points of the animation.The default implementation of this method returns nil.
- (UICollectionViewLayoutAttributes) initialLayoutAttributesForAppearingItemAtIndexPath(itemIndexPath)
Returns the starting layout information for an item being inserted into the collection view. This method is called after the prepareForCollectionViewUpdates: method and before the finalizeCollectionViewUpdates method for any items that are about to be inserted. Your implementation should return the layout information that describes the initial position and state of the item. The collection view uses this information as the starting point for any animations. (The end point of the animation is the item’s new location in the collection view.) If you return nil, the layout object uses the item’s final attributes for both the start and end points of the animation.The default implementation of this method returns nil.
- (UICollectionViewLayoutAttributes) initialLayoutAttributesForAppearingSupplementaryElementOfKind(elementKind, atIndexPath:elementIndexPath)
Returns the starting layout information for a supplementary view being inserted into the collection view. This method is called after the prepareForCollectionViewUpdates: method and before the finalizeCollectionViewUpdates method for any supplementary views that are about to be inserted. Your implementation should return the layout information that describes the initial position and state of the view. The collection view uses this information as the starting point for any animations. (The end point of the animation is the view’s new location in the collection view.) If you return nil, the layout object uses the item’s final attributes for both the start and end points of the animation.The default implementation of this method returns nil.
- (Object) invalidateLayout
Invalidates the current layout and triggers a layout update. You can call this method at any time to update the layout information. This method invalidates the layout of the collection view itself and returns right away. Thus, you can call this method multiple times from the same block of code without triggering multiple layout updates. The actual layout update occurs during the next view layout update cycle.
- (UICollectionViewLayoutAttributes) layoutAttributesForDecorationViewOfKind(decorationViewKind, atIndexPath:indexPath)
Returns the layout attributes for the specified decoration view. If your layout object defines any decoration views, you must override this method and use it to return layout information for those views.
- (Array) layoutAttributesForElementsInRect(rect)
Returns the layout attributes for all of the cells and views in the specified rectangle. Subclasses must override this method and use it to return layout information for all items whose view intersects the specified rectangle. Your implementation should return attributes for all visual elements, including cells, supplementary views, and decoration views. When creating the layout attributes, always create an attributes object that represents the correct element type (cell, supplementary, or decoration). The collection view differentiates between attributes for each type and uses that information to make decisions about which views to create and how to manage them.
- (UICollectionViewLayoutAttributes) layoutAttributesForItemAtIndexPath(indexPath)
Returns the layout attributes for the item at the specified index path. Subclasses must override this method and use it to return layout information for items in the collection view. You use this method to provide layout information only for items that have a corresponding cell. Do not use it for supplementary views or decoration views.
- (UICollectionViewLayoutAttributes) layoutAttributesForSupplementaryViewOfKind(kind, atIndexPath:indexPath)
Returns the layout attributes for the specified supplementary view. If your layout object defines any supplementary views, you must override this method and use it to return layout information for those views.
- (Object) prepareForAnimatedBoundsChange(oldBounds)
Prepares the layout object for animated changes to the view’s bounds or the insertion or deletion of items. The collection view calls this method before performing any animated changes to the view’s bounds or before the animated insertion or deletion of items. This method is the layout object’s opportunity to perform any calculations needed to prepare for those animated changes. Specifically, you might use this method to calculate the initial or final positions of inserted or deleted items so that you can return those values when asked for them.You can also use this method to perform additional animations. Any animations you create are added to the animation block used to handle the insertions, deletions, and bounds changes.
- (Object) prepareForCollectionViewUpdates(updateItems)
Prepares the layout object to receive changes to the contents of the collection view. When items are inserted or deleted, the collection view notifies its layout object so that it can adjust the layout as needed. The first step in that process is to call this method to let the layout object know what changes to expect. After that, additional calls are made to gather layout information for inserted, deleted, and moved items that are going to be animated around the collection view.
- (Object) prepareLayout
Tells the layout object to update the current layout. Layout updates occur the first time the collection view presents its content and whenever the layout is invalidated explicitly or implicitly because of a change to the view. During each layout update, the collection view calls this method first to give your layout object a chance to prepare for the upcoming layout operation. The default implementation of this method does nothing. Subclasses can override it and use it to set up data structures or perform any initial computations needed to perform the layout later.
- (Object) registerClass(viewClass, forDecorationViewOfKind:decorationViewKind)
Registers a class for use in creating decoration views for a collection view. This method gives the layout object a chance to register a decoration view for use in the collection view. Decoration views provide visual adornments to a section or to the entire collection view but are not otherwise tied to the data provided by the collection view’s data source.You do not need to create decoration views explicitly. After registering one, it is up to the layout object to decide when a decoration view is needed and return the corresponding layout attributes from its layoutAttributesForElementsInRect: method. For layout attributes that specify a decoration view, the collection view creates (or reuses) a view and displays it automatically based on the registered information. If you previously registered a class or nib file with the same kind string, the class you specify in the viewClass parameter replaces the old entry. You may specify nil for viewClass if you want to unregister the decoration view.
- (Object) registerNib(nib, forDecorationViewOfKind:decorationViewKind)
Registers a nib file for use in creating decoration views for a collection view. This method gives the layout object a chance to register a decoration view for use in the collection view. Decoration views provide visual adornments to a section or to the entire collection view but are not otherwise tied to the data provided by the collection view’s data source.You do not need to create decoration views explicitly. After registering one, it is up to the layout object to decide when a decoration view is needed and return the corresponding layout attributes from its layoutAttributesForElementsInRect: method. For layout attributes that specify a decoration view, the collection view creates (or reuses) a view and displays it automatically based on the registered information. If you previously registered a class or nib file with the same kind string, the class you specify in the viewClass parameter replaces the old entry. You may specify nil for viewClass if you want to unregister the decoration view.
- (Boolean) shouldInvalidateLayoutForBoundsChange(newBounds)
Asks the layout object if the new bounds require a layout update. The default implementation of this method returns NO. Subclasses should override it and return an appropriate value based on whether changes in the bounds of the collection view require changes to the layout of cells and supplementary views.
- (CGPoint) targetContentOffsetForProposedContentOffset(proposedContentOffset, withScrollingVelocity:velocity)
Returns the point at which to stop scrolling. If you want the scrolling behavior to snap to specific boundaries, you can override this method and use it to change the point at which to stop. For example, you might use this method to always stop scrolling on a boundary between items, as opposed to stopping in the middle of an item.