iOS Developer Library

Developer

UIKit Framework Reference UICollectionViewLayoutInvalidationContext Class Reference

Options
Deployment Target:

On This Page
Language:

UICollectionViewLayoutInvalidationContext

A UICollectionViewLayoutInvalidationContext object declares which parts of your layout need to be updated when the layout is invalidated. Layout objects that are designed to support invalidation contexts can use that information to optimize their behavior during the invalidation cycle.

You can create an invalidation context object as a precursor to invalidating a layout object. After configuring the invalidation context object, pass it to the layout object’s invalidateLayoutWithContext: method, which is responsible for using the context object to update the layout efficiently. The collection view also creates invalidation contexts in response to specific changes. For example, it creates an invalidation context when you change the layout or data source object, when you insert or delete items, and when you call the reloadData method.

Subclassing Notes

If you create your own custom layout objects, you can subclass UICollectionViewLayoutInvalidationContext and add properties to specify which aspects of your layout data can be invalidated separately. You must then design your layout object to check for these properties and update the layout appropriately.

For more information about how to support custom invalidation contexts in your layout objects, see UICollectionViewLayout Class Reference.

Inheritance


Conforms To


Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 7.0 and later.
  • A Boolean that indicates that all layout data should be marked as invalid. (read-only)

    Declaration

    Swift

    var invalidateEverything: Bool { get }

    Objective-C

    @property(nonatomic, readonly) BOOL invalidateEverything

    Discussion

    You do not set this property yourself. The collection view sets it in response to specific types of layout invalidation scenarios. For example, the collection view sets it to YEStrue when you change the current layout object, change the data source of the collection view, or call the reloadData method and subsequently request a layout invalidation context.

    If this property is set to YEStrue, the layout object should recompute all of its layout-related data.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • A Boolean that indicates whether the layout should ask for new section and item counts. (read-only)

    Declaration

    Swift

    var invalidateDataSourceCounts: Bool { get }

    Objective-C

    @property(nonatomic, readonly) BOOL invalidateDataSourceCounts

    Discussion

    You do not set this property yourself. The collection view sets it in response to specific types of layout invalidation scenarios. For example, the collection view sets it to YEStrue when you insert or delete items or call the collection view’s reloadData method.

    If this property is set to YEStrue, the layout object should query its delegate for the number of sections and items and update its layout based on the new number of items.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • The delta value to be applied to the collection view’s content offset.

    Declaration

    Swift

    var contentOffsetAdjustment: CGPoint

    Objective-C

    @property(nonatomic) CGPoint contentOffsetAdjustment

    Discussion

    Use this property to update the content offset of the collection view. The default value of this property is CGPointZero. Changing the value causes the collection view to add the specified x and y values to its contentOffset property. Thus, positive values increase the content offset and negative values decrease it.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.

  • The delta value to be applied to the collection view’s content size.

    Declaration

    Swift

    var contentSizeAdjustment: CGSize

    Objective-C

    @property(nonatomic) CGSize contentSizeAdjustment

    Discussion

    Use this property to update the size of the collection view’s content area. The default value of this property is CGSizeZero. Changing the value causes the collection view to add the specified height and width values to its contentSize property. Thus, positive values grow the content area and negative values shrink it.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.

  • Adds the cells at the specified index paths to the list of invalid items.

    Declaration

    Swift

    func invalidateItemsAtIndexPaths(_ indexPaths: [AnyObject])

    Objective-C

    - (void)invalidateItemsAtIndexPaths:(NSArray *)indexPaths

    Parameters

    indexPaths

    An array of NSIndexPath objects. Each index path represents a cell whose layout needs to be recomputed.

    Discussion

    Call this method to identify the specific cells of your layout that require updates. The cells you specify are added to the array in the invalidatedItemIndexPaths property.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.

  • Adds the supplementary views at the specified index paths to the list of invalid items.

    Declaration

    Swift

    func invalidateSupplementaryElementsOfKind(_ elementKind: String, atIndexPaths indexPaths: [AnyObject])

    Objective-C

    - (void)invalidateSupplementaryElementsOfKind:(NSString *)elementKind atIndexPaths:(NSArray *)indexPaths

    Parameters

    elementKind

    A string that identifies the type of the supplementary views. This parameter must not be nil.

    indexPaths

    An array of NSIndexPath objects. Each index path represents a supplementary view of the given kind whose layout needs to be recomputed.

    Discussion

    Call this method to identify the specific supplementary views of your layout that require updates. The views you specify are added to the dictionary in the invalidatedSupplementaryIndexPaths property. All of the views you specify should be of the type that you specified in the elementKind parameter. If you call this method two or more times with the same value for the elementKind parameter, this method merges the new index paths with the ones previously specified.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.

  • Adds the decoration views at the specified index paths to the list of invalid items.

    Declaration

    Swift

    func invalidateDecorationElementsOfKind(_ elementKind: String, atIndexPaths indexPaths: [AnyObject])

    Objective-C

    - (void)invalidateDecorationElementsOfKind:(NSString *)elementKind atIndexPaths:(NSArray *)indexPaths

    Parameters

    elementKind

    A string that identifies the type of the decoration views. This parameter must not be nil.

    indexPaths

    An array of NSIndexPath objects. Each index path represents a supplementary view of the given kind whose layout needs to be recomputed.

    Discussion

    Call this method to identify the specific decoration views whose layout attributes changed. The views you specify are added to the dictionary in the invalidatedDecorationIndexPaths property. All of the views you specify should be of the type that you specified in the elementKind parameter. If you call this method two or more times with the same value for the elementKind parameter, this method merges the new index paths with the ones previously specified.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.

  • An array of index paths representing the cells that were invalidated. (read-only)

    Declaration

    Swift

    var invalidatedItemIndexPaths: [AnyObject]? { get }

    Objective-C

    @property(nonatomic, readonly) NSArray *invalidatedItemIndexPaths

    Discussion

    The array contains zero or more NSIndexPath objects, each of which represents a cell whose layout changed.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.

  • A dictionary that identifies the supplementary views that were invalidated. (read-only)

    Declaration

    Swift

    var invalidatedSupplementaryIndexPaths: [NSObject : AnyObject]? { get }

    Objective-C

    @property(nonatomic, readonly) NSDictionary *invalidatedSupplementaryIndexPaths

    Discussion

    The keys in this dictionary are the element kind strings of the invalid supplementary views. The value for each key is an array of NSIndexPath objects indicating which specific supplementary views have layout changes.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.

  • A dictionary that identifies the decoration views that were invalidated. (read-only)

    Declaration

    Swift

    var invalidatedDecorationIndexPaths: [NSObject : AnyObject]! { get }

    Objective-C

    @property(nonatomic, readonly) NSDictionary *invalidatedDecorationIndexPaths

    Discussion

    The keys in this dictionary are the element kind strings of the invalid decoration views. The value for each key is an array of NSIndexPath objects indicating which specific decoration views have layout changes.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.