LayoutBlockProtocol

public protocol LayoutBlockProtocol

Defines general methods for any layout block

  • Flag, defines that block will be used for layout

    Declaration

    Swift

    var isActive: Bool { get }
  • Snapshot for current state without recalculating

    Declaration

    Swift

    var currentSnapshot: LayoutSnapshotProtocol { get }
  • Undocumented

    Declaration

    Swift

    var currentRect: CGRect { get }
  • Calculate and apply frames layout items. Should be call when parent LayoutElement element has corrected bounds. Else result unexpected.

    Declaration

    Swift

    func layout()
  • Calculate and apply frames layout items in custom space.

    Declaration

    Swift

    func layout(in sourceRect: CGRect)

    Parameters

    sourceRect

    Source space

  • Returns snapshot for all LayoutElement items in block. Attention: in during calculating snapshot frames of layout items must not changed.

    Declaration

    Swift

    func snapshot(for sourceRect: CGRect) -> LayoutSnapshotProtocol

    Parameters

    sourceRect

    Source space for layout

    Return Value

    Snapshot that contains frames layout items

  • Returns snapshot for all LayoutElement items in block. Does not call this method directly outside LayoutBlockProtocol object. Method implementation should operate completedRects with all LayoutElement items, that has been used to constrain this and child blocks.

    Declaration

    Swift

    func snapshot(for sourceRect: CGRect, completedRects: inout [(AnyObject, CGRect)]) -> LayoutSnapshotProtocol

    Parameters

    sourceRect

    Source space for layout. For not top level blocks rect should define the available bounds of block

    completedRects

    LayoutElement items with corrected frame

    Return Value

    Snapshot that contains frames layout items

  • Applying frames from snapshot to LayoutElement items in this block. Snapshot array should be ordered such to match LayoutElement items sequence.

    Declaration

    Swift

    func apply(snapshot: LayoutSnapshotProtocol)

    Parameters

    snapshot

    Snapshot represented as array of frames.

LayoutBlock

  • Returns snapshot for all LayoutElement items in block. Use this method when you need to get snapshot for block, that has been constrained by LayoutElement items, that is not included to this block. For example: block constrained by super element and you need to get size of block.

    Declaration

    Swift

    func snapshot(for sourceRect: CGRect, constrainRects: [(AnyObject, CGRect)]) -> LayoutSnapshotProtocol

    Parameters

    sourceRect

    Source space for layout.

    constrainRects

    LayoutElement items, that not included to block, but use for constraining.

    Return Value

    Snapshot that contains frames layout items