IGFlowLayoutView Class Reference

Inherits from UIScrollView
Declared in IGFlowLayoutView.h

Overview

A flow layout view allows users to scroll through a list of items horizontally or vertically. The item’s are provided to the view via the IGFlowViewDataSource protocol. All items are relatively sized instead of absolutely, which allows for dynamic layouts when the view is resized.

Configuring a Flow Layout View

– dequeueReusableCellWithIdentifier:

Returns a reusable IGFlowLayoutViewCell object located by its identifier

- (id)dequeueReusableCellWithIdentifier:(NSString *)identifier

Parameters

identifier

A string identifying the cell object to be reused. By default, a reusable cell’s identifier is it’s class name, but you can change it to any arbitrary value.

Return Value

A IGFlowLayoutViewCell object with the associated identifier or nil if no such object exists in the reusable-cell queue.

Discussion

For performance reasons, a flow layout view’s data source should generally reuse IGFlowLayoutViewCell objects. A flow layout view maintains a queue or list of IGFlowLayoutViewCell objects that the view’s dataSource has marked for reuse. It marks a cell for reuse by assigning it a reuse identifier when it creates it (that is, in the initWithReuseIdentifier: method of IGFlowLayoutViewCell). The data source can access specific template cell objects in this queue by invoking this method. You can access a cell’s reuse identifier through it’s reuseIdentifier property, which is defined by IGFlowLayoutViewCell.

Declared In

IGFlowLayoutView.h

  layoutType

Determines the direction in which items in the flow layout view will be layed out.

@property (nonatomic, assign) IGFlowLayoutType layoutType

Discussion

If horizontal, the items will be laid out top to bottom then left to right, so that the view scrolls horizontally. If vertical, the items will be laid out left to right then top to bottom, so that the view scrolls vertically.

Declared In

IGFlowLayoutView.h

Accessing Cells and Items

– cellAtIndex:

Returns the IGFlowLayoutViewCell for a particular index.

- (IGFlowLayoutViewCell *)cellAtIndex:(NSInteger)index

Parameters

index

The index of cell that should be returned.

Return Value

The IGFlowLayoutViewCell for the specified index or nil if the item isn’t in view.

Discussion

Nil will be returned if an item at that index isn’t in the current viewport.

Declared In

IGFlowLayoutView.h

– cellAtPoint:

Returns the IGFlowLayoutViewCell located at a particular point.

- (IGFlowLayoutViewCell *)cellAtPoint:(CGPoint)point

Parameters

point

A point within the flow layout view.

Return Value

The IGFlowLayoutViewCell located at the specified point or nil if no item exists at that point.

Discussion

Nil will be returned if an item at that point doesn’t exist.

Declared In

IGFlowLayoutView.h

– closestItemAtPoint:

Returns the index of an item located at a particular point.

- (NSInteger)closestItemAtPoint:(CGPoint)point

Parameters

point

A point within the flow layout view.

Return Value

The index of an item located at the specified point or the closest index plus one if no item exists at a particular point.

Discussion

An index will always be returned. If no particular item is located at that point, then the closest index plus one will be returned instead.

Declared In

IGFlowLayoutView.h

– boundsOfItemAtIndex:

Returns the Bounds of an item at the specified index.

- (CGRect)boundsOfItemAtIndex:(NSInteger)index

Parameters

index

The index of an item within the flow layout view.

Return Value

The bounds of the item for the specified index.

Discussion

This method will always return a valid bounds, even if the item isn’t in view. If the index specified is an invalid index, then CGRectZero is returned.

Declared In

IGFlowLayoutView.h

– itemAtPoint:

Returns the index of an item located at a particular point.

- (NSInteger)itemAtPoint:(CGPoint)point

Parameters

point

A point within the flow layout view.

Return Value

The index of an item located at the specified point or -1 if no item exists at the specified point.

Discussion

If no item exists at the specified point, -1 will be returned. To always get an index, use closestItemAtPoint:

Declared In

IGFlowLayoutView.h

  allowSubPixelBlockSizes

@property (nonatomic, assign) BOOL allowSubPixelBlockSizes

– registerClass:forCellReuseIdentifier:

Registers a class for use in creating new flowLayout cells.

- (void)registerClass:(Class)cellClass forCellReuseIdentifier:(NSString *)identifier

Parameters

cellClass

The class of a cell that you want to use in the flowLayout.

identifier

The reuse identifier for the cell. This parameter must not be nil and must not be an empty string.

Discussion

Prior to dequeueing any cells, call this method to tell the flowLayout view how to create new cells. If a cell of the specified type is not currently in a reuse queue, the flowLayout view uses the provided information to create a new cell object automatically.

If you previously registered a class file with the same reuse identifier, the class you specify in the cellClass parameter replaces the old entry. You may specify nil for cellClass if you want to unregister the class from the specified reuse identifier.

Declared In

IGFlowLayoutView.h

Inserting, Deleting, and Resizing Cells

  transitionDuration

A value that represents time in seconds it will take for cells to be moved, inserted or deleted

@property (nonatomic, assign) CGFloat transitionDuration

Declared In

IGFlowLayoutView.h

– insertItemAtIndex:

Tells the flow layout view that an item was inserted in the underlying data source at a specific index. Which results in the new item and all items after that index being animated to their new location.

- (void)insertItemAtIndex:(NSInteger)index

Parameters

index

The index the item was inserted at.

Discussion

The duration of the animation is based off the time specified in the transitionDuration property.

Declared In

IGFlowLayoutView.h

– removeItemAtIndex:

Tells the flow layout view that an item was removed from the underlying data source at a specific index. Which results in the removed item and all items after that index being animated to their new location.

- (void)removeItemAtIndex:(NSInteger)index

Parameters

index

The index the item was removed at.

Discussion

The duration of the animation is based off the time specified in the transitionDuration property.

Declared In

IGFlowLayoutView.h

– updateItemAtIndex:

Tells the flow layout view that an item was reszied in the underlying data source at a specific index. Which results in the resized item and all items after that index being animated to their new location.

- (void)updateItemAtIndex:(NSInteger)index

Parameters

index

The index the item was resized at.

Discussion

The duration of the animation is based off the time specified in the transitionDuration property.

Declared In

IGFlowLayoutView.h

– moveItemAtIndex:toIndex:

Tells the flow layout view that an item was moved to a new position in the underlying data source at a specific index. Which results in the item animated to the new position.

- (void)moveItemAtIndex:(NSInteger)index toIndex:(NSInteger)newIndex

Parameters

index

The original index of the item.

newIndex

The new index of the item.

Discussion

The duration of the animation is based off the time specified in the transitionDuration property.

Declared In

IGFlowLayoutView.h

Reloading the Flow Layout View

– updateData

Triggers a recalculation of the layout of all cells in the FLowLayoutView.

- (void)updateData

Discussion

Calling this method invokes all methods from the datasource and delegate used to build content area of the flow layout view.

Declared In

IGFlowLayoutView.h

Managing the Delegate and the Data Source

  dataSource

The object that acts as the data source of the flow layout view.

@property (nonatomic, weak, nullable) id<IGFlowLayoutViewDataSource> dataSource

Discussion

The delegate must adopt the IGFlowLayoutViewDataSource protocol.

Declared In

IGFlowLayoutView.h

  delegate

The object that acts as the delegate of the flow layout view.

@property (nonatomic, weak, nullable) id<IGFlowLayoutViewDelegate> delegate

Discussion

The data source must adopt the IGFlowLayoutViewDelegate protocol.

Declared In

IGFlowLayoutView.h

Editing

  editable

When set to YES, a user can select an item to resize or move it.

@property (nonatomic, assign) BOOL editable

Discussion

In order to have resizing support, the dataSource must implement the following selector: flowLayoutView:newSize:forItemAtIndex:

In order to have reordering support, the dataSource must implement the following selector: flowLayoutView:moveItemAtIndex:toIndex:

Declared In

IGFlowLayoutView.h

  editItem

The index of the currently selected item, or -1 if no item is selected.

@property (nonatomic, readonly) NSInteger editItem

Declared In

IGFlowLayoutView.h

  editItemColor

The color of the select item’s border

@property (nonatomic, retain) UIColor *editItemColor

Declared In

IGFlowLayoutView.h

  editItemHandleColor

The color of the resize handles for an editable item

@property (nonatomic, retain) UIColor *editItemHandleColor

Declared In

IGFlowLayoutView.h

  clipEditItemHandles

Whether the editItemHandles are clipped so that they don’t exceed past the border of the editItem view

@property (nonatomic, assign) BOOL clipEditItemHandles

Declared In

IGFlowLayoutView.h

  editItemHandleSize

The size of the resize handles for an editable item

@property (nonatomic, assign) CGFloat editItemHandleSize

Declared In

IGFlowLayoutView.h

  editItemBorderWidth

The size of the border on an editable item

@property (nonatomic, assign) CGFloat editItemBorderWidth

Declared In

IGFlowLayoutView.h

– selectItemAtIndex:

Selects the item at the specified index.

- (void)selectItemAtIndex:(NSInteger)index

Parameters

index

The index of the item to select. If an invalid index such as -1 is passed in, no item will be selected.

Declared In

IGFlowLayoutView.h

Navigation

– maximizeItem:

Maximizes the item at the specified index.

- (void)maximizeItem:(NSInteger)index

Parameters

index

The index of the item to maximize. If an invalid index such as -1 is passed in, no item will be maximized.

Declared In

IGFlowLayoutView.h

– minimize

If the flowLayout is currently in a maximized state, the control will transtion back to its normal state.

- (void)minimize

Declared In

IGFlowLayoutView.h