iOS Guides | Samples

MonoTouch.UIKit.UICollectionViewLayout Class

Base class for specifying the layout of a UICollectionView.

See Also: UICollectionViewLayout

Syntax

[MonoTouch.Foundation.Register("UICollectionViewLayout", true)]
[MonoTouch.ObjCRuntime.Introduced(MonoTouch.ObjCRuntime.PlatformName.iOS, 6, 0, MonoTouch.ObjCRuntime.PlatformArchitecture.None, null)]
public class UICollectionViewLayout : NSObject, INSCoding, IDisposable

See Also

Remarks

Collection Views allow content to be displayed using arbitrary layouts. Grid-like layouts can use the UICollectionViewFlowLayout or application developers can subtype UICollectionViewLayout to create their own flexible pattern.

The layout of the UICollectionViewCells in a UICollectionView is controlled by a UICollectionViewLayout, which can be passed in to the UICollectionView.UICollectionView(UICollectionViewLayout) constructor or can changed with UICollectionView.SetCollectionViewLayout.

Application developers can create fully custom layouts by subclassing either UICollectionViewFlowLayout or UICollectionViewLayout.

The key methods to override are:

MethodDescription
UICollectionViewLayout.PrepareLayoutUsed for performing initial geometric calculations that will be used throughout the layout process.
UICollectionViewLayout.CollectionViewContentSize Returns the size of the area used to display content.
UICollectionViewLayout.LayoutAttributesForElementsInRectReturns the layout attributes for all the cells and views within the specified rectangle.
UICollectionViewLayout.LayoutAttributesForItemThe layout attributes of a specific cell
UICollectionViewLayout.ShouldInvalidateLayoutForBoundsChangeReturns true if the new bounds require an update of the layout.

The following code, taken from the "Introduction to Collection Views" class, creates a circular layout, as shown in the following image:

C# Example

          public override UICollectionViewLayoutAttributes LayoutAttributesForItem (NSIndexPath path)
          {
            UICollectionViewLayoutAttributes attributes = UICollectionViewLayoutAttributes.CreateForCell (path);
            attributes.Size = new SizeF (ItemSize, ItemSize);
          
            attributes.Center = new PointF (center.X + radius * (float)Math.Cos (2 * path.Row * Math.PI / cellCount),
              center.Y + radius * (float)Math.Sin (2 * path.Row * Math.PI / cellCount));
            return attributes;
          }

Related content

Requirements

Namespace: MonoTouch.UIKit
Assembly: monotouch (in monotouch.dll)
Assembly Versions: 0.0.0.0

The members of MonoTouch.UIKit.UICollectionViewLayout are listed below.

See Also: NSObject

Public Constructors

Default constructor, initializes a new instance of this class.
A constructor that initializes the object from the data stored in the unarchiver object.
Constructor to call on derived classes to skip initialization and merely allocate the object.
A constructor used when creating managed representations of unmanaged objects; Called by the runtime.

Public Properties

[read-only]
override
ClassHandleIntPtr. The handle for this class.
[read-only]
CollectionViewUICollectionView. The UICollectionView which this UICollectionViewLayout is laying out.
[read-only]
CollectionViewContentSizeSizeF. The SizeF of this UICollectionViewLayout's content.
[read-only]
static
LayoutAttributesClassClass. The UICollectionViewLayoutAttributes used for layout attributes for this UICollectionViewLayout.

Public Methods

FinalizeAnimatedBoundsChange()
When overridden, performs custom cleanup after animated changes to the bounds or after items have been inserted or deleted.
FinalizeCollectionViewUpdates()
When overridden, allows additional animations or clean up during an update.
FinalizeLayoutTransition()
Called prior to transition animations, informs the layout object to perform any steps necessary before the animations.
FinalLayoutAttributesForDisappearingDecorationElement(NSString, NSIndexPath) : UICollectionViewLayoutAttributes
The final layout information for a decoration element that is about to be removed from this UICollectionViewLayout.
FinalLayoutAttributesForDisappearingItem(NSIndexPath) : UICollectionViewLayoutAttributes
The final layout information for an item that is about to be removed from the UICollectionView.
FinalLayoutAttributesForDisappearingSupplementaryElement(NSString, NSIndexPath) : UICollectionViewLayoutAttributes
The final layout information for a supplementary view that is about to be removed from the collection view.
GetIndexPathsToDeleteForDecorationViewOfKind(NSString) : NSIndexPath[]
An array of NSIndexPaths indicating the decoration views to remove.
GetIndexPathsToDeleteForSupplementaryView(NSString) : NSIndexPath[]
An array of NSIndexPaths indicating the supplementary views to remove.
GetIndexPathsToInsertForDecorationView(NSString) : NSIndexPath[]
An array of NSIndexPaths indicating the decoration views to add.
GetIndexPathsToInsertForSupplementaryView(NSString) : NSIndexPath[]
An array of index paths indicating the supplementary views to add.
GetInvalidationContext(UICollectionViewLayoutAttributes, UICollectionViewLayoutAttributes) : UICollectionViewLayoutInvalidationContext
Gets the invalidated areas for a change from originalAttributes to preferredAttributes.
GetInvalidationContextForBoundsChange(RectangleF) : UICollectionViewLayoutInvalidationContext
Returns a UICollectionViewLayoutInvalidationContext that specifies the portions of the layout that change in response to a change in bounds.
GetInvalidationContextForEndingInteractiveMovementOfItems(NSIndexPath[], NSIndexPath[], Boolean) : UICollectionViewLayoutInvalidationContext
Returns a validation context for the moved items.
GetInvalidationContextForInteractivelyMovingItems(NSIndexPath[], PointF, NSIndexPath[], PointF) : UICollectionViewLayoutInvalidationContext
Returns a validation context for the items that the user is moving.
GetLayoutAttributesForInteractivelyMovingItem(NSIndexPath, PointF) : UICollectionViewLayoutAttributes
Returns the layout attributes for items that the user is moving.
GetTargetIndexPathForInteractivelyMovingItem(NSIndexPath, PointF) : NSIndexPath
Returns the target index path for items that the user is moving.
InitialLayoutAttributesForAppearingDecorationElement(NSString, NSIndexPath) : UICollectionViewLayoutAttributes
Information on the starting layout of a decoration view that is being inserted into the UICollectionView.
InitialLayoutAttributesForAppearingItem(NSIndexPath) : UICollectionViewLayoutAttributes
Information on the starting layout of an item that is being inserted into the UICollectionView.
InitialLayoutAttributesForAppearingSupplementaryElement(NSString, NSIndexPath) : UICollectionViewLayoutAttributes
Information on the starting layout of a supplementary view that is being inserted into the UICollectionView.
InvalidateLayout()
Invalidates the current layout and initiates an update.
InvalidateLayout(UICollectionViewLayoutInvalidationContext)
Forces recomputation and application of the collection view.
static
InvalidationContextClass() : Class
The custom UICollectionViewLayoutInvalidationContext used for this UICollectionViewLayout.
LayoutAttributesForDecorationView(NSString, NSIndexPath) : UICollectionViewLayoutAttributes
The UICollectionViewLayoutAttributes for the specified decoration view.
LayoutAttributesForElementsInRect(RectangleF) : UICollectionViewLayoutAttributes[]
The UICollectionViewLayoutAttributes for all the cells and views in the specified RectangleF.
LayoutAttributesForItem(NSIndexPath) : UICollectionViewLayoutAttributes
The UICollectionViewLayoutAttributes for the specified NSIndexPath.
LayoutAttributesForSupplementaryView(NSString, NSIndexPath) : UICollectionViewLayoutAttributes
The UICollectionViewLayoutAttributes for the specified supplementary view.
LayoutAttributesForSupplementaryView(UICollectionElementKindSection, NSIndexPath) : UICollectionViewLayoutAttributes
The attributes for the supplementary view at the specified indexPath.
PrepareForAnimatedBoundsChange(RectangleF)
Called prior to animated changes to the bounds or before insertion or deletion of items.
PrepareForCollectionViewUpdates(UICollectionViewUpdateItem[])
Notifies the layout object that the contents of the UICollectionView are about to change.
PrepareForTransitionFromLayout(UICollectionViewLayout)
Notifies the layout object that it will shortly be installed as the layout for the UICollectionView.
PrepareForTransitionToLayout(UICollectionViewLayout)
Tells the layout object that it will shortly be removed as the layout for the UICollectionView.
PrepareLayout()
Tells the layout object to update the layout.
RegisterClassForDecorationView(Type, NSString)
Registers the class identified by kind as a decoration view.
RegisterNibForDecorationView(UINib, NSString)
Registers the UINib for use as a template for decoration views.
ShouldInvalidateLayout(UICollectionViewLayoutAttributes, UICollectionViewLayoutAttributes) : Boolean
Returns true if the collection view needs to invalidate for a change from preferredAttributes to originalAttributes.
ShouldInvalidateLayoutForBoundsChange(RectangleF) : Boolean
Whether the new bounds requires a layout update.
TargetContentOffset(PointF, PointF) : PointF
The PointF at which to stop scrolling.
TargetContentOffsetForProposedContentOffset(PointF) : PointF
The content offset to use after an animated layout change.