Skip to content

Instantly share code, notes, and snippets.

View EMCollectionViewFlowLayout.swift
import UIKit
class SleepLogCollectionViewFlowLayout: UICollectionViewFlowLayout {
override func targetContentOffset(
forProposedContentOffset proposedContentOffset: CGPoint,
withScrollingVelocity velocity: CGPoint
) -> CGPoint {
var _proposedContentOffset = CGPoint(
x: proposedContentOffset.x, y: proposedContentOffset.y
mstubna / gist:f1529160ae0268a355df
Created Apr 14, 2015
Lazy loader that can be used for backing a view collection in order to keep a small number of views loaded. Appropriate for use in a scrolling image gallery for example.
View gist:f1529160ae0268a355df
class @LazyLoader
# Queue that lazily constructs new items only as required to keep the buffers full
# If objects in the queue back a corresponding view, they should implement a destroy_view() function so that they can be properly garbage collected
# - object_constructor should be a function that accepts a single argument - the index of the newly constructed object
# - buffer_size is the number of prev and next items to keep continuously populated
# - initial_index is the index of the initial object to construct
constructor: (@obj_constructor, @buffer_size, initial_index) ->
@prev_objs = []
@next_objs = []
You can’t perform that action at this time.