├── .gitignore ├── LICENSE ├── README.md ├── UICollectionView-Spring-Demo.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcuserdata │ └── ash.xcuserdatad │ └── xcschemes │ ├── UICollectionView-Spring-Demo.xcscheme │ └── xcschememanagement.plist └── UICollectionView-Spring-Demo ├── Images.xcassets ├── AppIcon.appiconset │ ├── AppIcon29x29@2x.png │ ├── AppIcon40x40@2x.png │ ├── AppIcon60x60@2x.png │ └── Contents.json ├── Horizontal-TabIcon.imageset │ ├── Contents.json │ └── Horizontal-TabIcon@2x.png ├── LaunchImage.launchimage │ └── Contents.json └── Vertical-TabIcon.imageset │ ├── Contents.json │ └── Vertical-TabIcon@2x.png ├── Storyboard.storyboard ├── TLAppDelegate.h ├── TLAppDelegate.m ├── TLSpringFlowLayout.h ├── TLSpringFlowLayout.m ├── TLViewController.h ├── TLViewController.m ├── UICollectionView-Spring-Demo-Info.plist ├── UICollectionView-Spring-Demo-Prefix.pch ├── en.lproj └── InfoPlist.strings └── main.m /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | .DS_Store 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | *.xcworkspace 13 | !default.xcworkspace 14 | xcuserdata 15 | profile 16 | *.moved-aside 17 | DerivedData 18 | .idea/ 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Teehan+Lax 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | UICollectionView-Spring-Demo 2 | ============================ 3 | A demonstration of UICollectionView and UIKit Dynamics. Uses tiling in order to maintain high-performance even with ten thousand cells. 4 | 5 | ## Demo 6 | ![Animation](http://f.cl.ly/items/161u2F0U383G0f0c3h3j/animation.gif) 7 | 8 | ## Usage 9 | To use this in your project, just add the `TLSpringFlowLayout` classes. Then create a UICollectionView (either with code or in a Storyboard). Set the UICollectionView's Flow Layout object to `TLSpringFlowLayout`. 10 | 11 | ## Extra Goodies 12 | If you setup your collection with code, you can set the `scrollResistanceFactor` property. This property increases the *bounciness* of the collection items as they scroll. 13 | 14 | You can also retrieve the `dynamicAnimator` property (read-only) if necessary. 15 | 16 | ## License 17 | MIT License. Copyright (c) 2013 Teehan+Lax. See the LICENSE file for more information. 18 | 19 | Created by Teehan+Lax. Updated by Sam Spencer on February 8, 2014. 20 | -------------------------------------------------------------------------------- /UICollectionView-Spring-Demo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 5E141AC517A9AC32007C6139 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E141AC417A9AC32007C6139 /* Foundation.framework */; }; 11 | 5E141AC717A9AC32007C6139 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E141AC617A9AC32007C6139 /* CoreGraphics.framework */; }; 12 | 5E141AC917A9AC32007C6139 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E141AC817A9AC32007C6139 /* UIKit.framework */; }; 13 | 5E141ACF17A9AC32007C6139 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 5E141ACD17A9AC32007C6139 /* InfoPlist.strings */; }; 14 | 5E141AD117A9AC32007C6139 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E141AD017A9AC32007C6139 /* main.m */; }; 15 | 5E141AD517A9AC32007C6139 /* TLAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E141AD417A9AC32007C6139 /* TLAppDelegate.m */; }; 16 | 5E141AD717A9AC32007C6139 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5E141AD617A9AC32007C6139 /* Images.xcassets */; }; 17 | 5E141AFA17A9AC9C007C6139 /* TLViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E141AF917A9AC9C007C6139 /* TLViewController.m */; }; 18 | 5E141AFD17A9ACD2007C6139 /* TLSpringFlowLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E141AFC17A9ACD2007C6139 /* TLSpringFlowLayout.m */; }; 19 | 9938B77D18A6D93500E5BC73 /* Storyboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9938B77C18A6D93500E5BC73 /* Storyboard.storyboard */; }; 20 | 9944AA2818AB11FE00BAFCFC /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9944AA2718AB11FE00BAFCFC /* QuartzCore.framework */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXFileReference section */ 24 | 5E141AC117A9AC32007C6139 /* UICollectionView-Spring-Demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "UICollectionView-Spring-Demo.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 25 | 5E141AC417A9AC32007C6139 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 26 | 5E141AC617A9AC32007C6139 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 27 | 5E141AC817A9AC32007C6139 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 28 | 5E141ACC17A9AC32007C6139 /* UICollectionView-Spring-Demo-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "UICollectionView-Spring-Demo-Info.plist"; sourceTree = ""; }; 29 | 5E141ACE17A9AC32007C6139 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 30 | 5E141AD017A9AC32007C6139 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 31 | 5E141AD217A9AC32007C6139 /* UICollectionView-Spring-Demo-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UICollectionView-Spring-Demo-Prefix.pch"; sourceTree = ""; }; 32 | 5E141AD317A9AC32007C6139 /* TLAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TLAppDelegate.h; sourceTree = ""; }; 33 | 5E141AD417A9AC32007C6139 /* TLAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TLAppDelegate.m; sourceTree = ""; }; 34 | 5E141AD617A9AC32007C6139 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 35 | 5E141ADD17A9AC33007C6139 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 36 | 5E141AE517A9AC33007C6139 /* UICollectionView-Spring-DemoTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "UICollectionView-Spring-DemoTests-Info.plist"; sourceTree = ""; }; 37 | 5E141AE717A9AC33007C6139 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 38 | 5E141AE917A9AC33007C6139 /* UICollectionView_Spring_DemoTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UICollectionView_Spring_DemoTests.m; sourceTree = ""; }; 39 | 5E141AF817A9AC9C007C6139 /* TLViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TLViewController.h; sourceTree = ""; }; 40 | 5E141AF917A9AC9C007C6139 /* TLViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TLViewController.m; sourceTree = ""; }; 41 | 5E141AFB17A9ACD2007C6139 /* TLSpringFlowLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TLSpringFlowLayout.h; sourceTree = ""; }; 42 | 5E141AFC17A9ACD2007C6139 /* TLSpringFlowLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TLSpringFlowLayout.m; sourceTree = ""; }; 43 | 9938B77C18A6D93500E5BC73 /* Storyboard.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Storyboard.storyboard; sourceTree = ""; }; 44 | 9944AA2718AB11FE00BAFCFC /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; 45 | /* End PBXFileReference section */ 46 | 47 | /* Begin PBXFrameworksBuildPhase section */ 48 | 5E141ABE17A9AC32007C6139 /* Frameworks */ = { 49 | isa = PBXFrameworksBuildPhase; 50 | buildActionMask = 2147483647; 51 | files = ( 52 | 9944AA2818AB11FE00BAFCFC /* QuartzCore.framework in Frameworks */, 53 | 5E141AC717A9AC32007C6139 /* CoreGraphics.framework in Frameworks */, 54 | 5E141AC917A9AC32007C6139 /* UIKit.framework in Frameworks */, 55 | 5E141AC517A9AC32007C6139 /* Foundation.framework in Frameworks */, 56 | ); 57 | runOnlyForDeploymentPostprocessing = 0; 58 | }; 59 | /* End PBXFrameworksBuildPhase section */ 60 | 61 | /* Begin PBXGroup section */ 62 | 5E141AB817A9AC32007C6139 = { 63 | isa = PBXGroup; 64 | children = ( 65 | 5E141ACA17A9AC32007C6139 /* UICollectionView-Spring-Demo */, 66 | 5E141AE317A9AC33007C6139 /* UICollectionView-Spring-DemoTests */, 67 | 5E141AC317A9AC32007C6139 /* Frameworks */, 68 | 5E141AC217A9AC32007C6139 /* Products */, 69 | ); 70 | sourceTree = ""; 71 | }; 72 | 5E141AC217A9AC32007C6139 /* Products */ = { 73 | isa = PBXGroup; 74 | children = ( 75 | 5E141AC117A9AC32007C6139 /* UICollectionView-Spring-Demo.app */, 76 | ); 77 | name = Products; 78 | sourceTree = ""; 79 | }; 80 | 5E141AC317A9AC32007C6139 /* Frameworks */ = { 81 | isa = PBXGroup; 82 | children = ( 83 | 9944AA2718AB11FE00BAFCFC /* QuartzCore.framework */, 84 | 5E141AC417A9AC32007C6139 /* Foundation.framework */, 85 | 5E141AC617A9AC32007C6139 /* CoreGraphics.framework */, 86 | 5E141AC817A9AC32007C6139 /* UIKit.framework */, 87 | 5E141ADD17A9AC33007C6139 /* XCTest.framework */, 88 | ); 89 | name = Frameworks; 90 | sourceTree = ""; 91 | }; 92 | 5E141ACA17A9AC32007C6139 /* UICollectionView-Spring-Demo */ = { 93 | isa = PBXGroup; 94 | children = ( 95 | 5E141AD317A9AC32007C6139 /* TLAppDelegate.h */, 96 | 5E141AD417A9AC32007C6139 /* TLAppDelegate.m */, 97 | 5E141AF817A9AC9C007C6139 /* TLViewController.h */, 98 | 5E141AF917A9AC9C007C6139 /* TLViewController.m */, 99 | 9938B77C18A6D93500E5BC73 /* Storyboard.storyboard */, 100 | 5E141AFB17A9ACD2007C6139 /* TLSpringFlowLayout.h */, 101 | 5E141AFC17A9ACD2007C6139 /* TLSpringFlowLayout.m */, 102 | 5E141AD617A9AC32007C6139 /* Images.xcassets */, 103 | 5E141ACB17A9AC32007C6139 /* Supporting Files */, 104 | ); 105 | path = "UICollectionView-Spring-Demo"; 106 | sourceTree = ""; 107 | }; 108 | 5E141ACB17A9AC32007C6139 /* Supporting Files */ = { 109 | isa = PBXGroup; 110 | children = ( 111 | 5E141ACC17A9AC32007C6139 /* UICollectionView-Spring-Demo-Info.plist */, 112 | 5E141ACD17A9AC32007C6139 /* InfoPlist.strings */, 113 | 5E141AD017A9AC32007C6139 /* main.m */, 114 | 5E141AD217A9AC32007C6139 /* UICollectionView-Spring-Demo-Prefix.pch */, 115 | ); 116 | name = "Supporting Files"; 117 | sourceTree = ""; 118 | }; 119 | 5E141AE317A9AC33007C6139 /* UICollectionView-Spring-DemoTests */ = { 120 | isa = PBXGroup; 121 | children = ( 122 | 5E141AE917A9AC33007C6139 /* UICollectionView_Spring_DemoTests.m */, 123 | 5E141AE417A9AC33007C6139 /* Supporting Files */, 124 | ); 125 | path = "UICollectionView-Spring-DemoTests"; 126 | sourceTree = ""; 127 | }; 128 | 5E141AE417A9AC33007C6139 /* Supporting Files */ = { 129 | isa = PBXGroup; 130 | children = ( 131 | 5E141AE517A9AC33007C6139 /* UICollectionView-Spring-DemoTests-Info.plist */, 132 | 5E141AE617A9AC33007C6139 /* InfoPlist.strings */, 133 | ); 134 | name = "Supporting Files"; 135 | sourceTree = ""; 136 | }; 137 | /* End PBXGroup section */ 138 | 139 | /* Begin PBXNativeTarget section */ 140 | 5E141AC017A9AC32007C6139 /* UICollectionView-Spring-Demo */ = { 141 | isa = PBXNativeTarget; 142 | buildConfigurationList = 5E141AED17A9AC33007C6139 /* Build configuration list for PBXNativeTarget "UICollectionView-Spring-Demo" */; 143 | buildPhases = ( 144 | 5E141ABD17A9AC32007C6139 /* Sources */, 145 | 5E141ABE17A9AC32007C6139 /* Frameworks */, 146 | 5E141ABF17A9AC32007C6139 /* Resources */, 147 | ); 148 | buildRules = ( 149 | ); 150 | dependencies = ( 151 | ); 152 | name = "UICollectionView-Spring-Demo"; 153 | productName = "UICollectionView-Spring-Demo"; 154 | productReference = 5E141AC117A9AC32007C6139 /* UICollectionView-Spring-Demo.app */; 155 | productType = "com.apple.product-type.application"; 156 | }; 157 | /* End PBXNativeTarget section */ 158 | 159 | /* Begin PBXProject section */ 160 | 5E141AB917A9AC32007C6139 /* Project object */ = { 161 | isa = PBXProject; 162 | attributes = { 163 | CLASSPREFIX = TL; 164 | LastUpgradeCheck = 0500; 165 | ORGANIZATIONNAME = "Teehan+Lax"; 166 | }; 167 | buildConfigurationList = 5E141ABC17A9AC32007C6139 /* Build configuration list for PBXProject "UICollectionView-Spring-Demo" */; 168 | compatibilityVersion = "Xcode 3.2"; 169 | developmentRegion = English; 170 | hasScannedForEncodings = 0; 171 | knownRegions = ( 172 | en, 173 | ); 174 | mainGroup = 5E141AB817A9AC32007C6139; 175 | productRefGroup = 5E141AC217A9AC32007C6139 /* Products */; 176 | projectDirPath = ""; 177 | projectRoot = ""; 178 | targets = ( 179 | 5E141AC017A9AC32007C6139 /* UICollectionView-Spring-Demo */, 180 | ); 181 | }; 182 | /* End PBXProject section */ 183 | 184 | /* Begin PBXResourcesBuildPhase section */ 185 | 5E141ABF17A9AC32007C6139 /* Resources */ = { 186 | isa = PBXResourcesBuildPhase; 187 | buildActionMask = 2147483647; 188 | files = ( 189 | 5E141ACF17A9AC32007C6139 /* InfoPlist.strings in Resources */, 190 | 5E141AD717A9AC32007C6139 /* Images.xcassets in Resources */, 191 | 9938B77D18A6D93500E5BC73 /* Storyboard.storyboard in Resources */, 192 | ); 193 | runOnlyForDeploymentPostprocessing = 0; 194 | }; 195 | /* End PBXResourcesBuildPhase section */ 196 | 197 | /* Begin PBXSourcesBuildPhase section */ 198 | 5E141ABD17A9AC32007C6139 /* Sources */ = { 199 | isa = PBXSourcesBuildPhase; 200 | buildActionMask = 2147483647; 201 | files = ( 202 | 5E141AFD17A9ACD2007C6139 /* TLSpringFlowLayout.m in Sources */, 203 | 5E141AFA17A9AC9C007C6139 /* TLViewController.m in Sources */, 204 | 5E141AD517A9AC32007C6139 /* TLAppDelegate.m in Sources */, 205 | 5E141AD117A9AC32007C6139 /* main.m in Sources */, 206 | ); 207 | runOnlyForDeploymentPostprocessing = 0; 208 | }; 209 | /* End PBXSourcesBuildPhase section */ 210 | 211 | /* Begin PBXVariantGroup section */ 212 | 5E141ACD17A9AC32007C6139 /* InfoPlist.strings */ = { 213 | isa = PBXVariantGroup; 214 | children = ( 215 | 5E141ACE17A9AC32007C6139 /* en */, 216 | ); 217 | name = InfoPlist.strings; 218 | sourceTree = ""; 219 | }; 220 | 5E141AE617A9AC33007C6139 /* InfoPlist.strings */ = { 221 | isa = PBXVariantGroup; 222 | children = ( 223 | 5E141AE717A9AC33007C6139 /* en */, 224 | ); 225 | name = InfoPlist.strings; 226 | sourceTree = ""; 227 | }; 228 | /* End PBXVariantGroup section */ 229 | 230 | /* Begin XCBuildConfiguration section */ 231 | 5E141AEB17A9AC33007C6139 /* Debug */ = { 232 | isa = XCBuildConfiguration; 233 | buildSettings = { 234 | ALWAYS_SEARCH_USER_PATHS = NO; 235 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 236 | CLANG_CXX_LIBRARY = "libc++"; 237 | CLANG_ENABLE_MODULES = YES; 238 | CLANG_ENABLE_OBJC_ARC = YES; 239 | CLANG_WARN_BOOL_CONVERSION = YES; 240 | CLANG_WARN_CONSTANT_CONVERSION = YES; 241 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 242 | CLANG_WARN_EMPTY_BODY = YES; 243 | CLANG_WARN_ENUM_CONVERSION = YES; 244 | CLANG_WARN_INT_CONVERSION = YES; 245 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 246 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 247 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 248 | COPY_PHASE_STRIP = NO; 249 | GCC_C_LANGUAGE_STANDARD = gnu99; 250 | GCC_DYNAMIC_NO_PIC = NO; 251 | GCC_OPTIMIZATION_LEVEL = 0; 252 | GCC_PREPROCESSOR_DEFINITIONS = ( 253 | "DEBUG=1", 254 | "$(inherited)", 255 | ); 256 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 257 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 258 | GCC_WARN_UNDECLARED_SELECTOR = YES; 259 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 260 | GCC_WARN_UNUSED_FUNCTION = YES; 261 | GCC_WARN_UNUSED_VARIABLE = YES; 262 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 263 | ONLY_ACTIVE_ARCH = YES; 264 | SDKROOT = iphoneos; 265 | }; 266 | name = Debug; 267 | }; 268 | 5E141AEC17A9AC33007C6139 /* Release */ = { 269 | isa = XCBuildConfiguration; 270 | buildSettings = { 271 | ALWAYS_SEARCH_USER_PATHS = NO; 272 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 273 | CLANG_CXX_LIBRARY = "libc++"; 274 | CLANG_ENABLE_MODULES = YES; 275 | CLANG_ENABLE_OBJC_ARC = YES; 276 | CLANG_WARN_BOOL_CONVERSION = YES; 277 | CLANG_WARN_CONSTANT_CONVERSION = YES; 278 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 279 | CLANG_WARN_EMPTY_BODY = YES; 280 | CLANG_WARN_ENUM_CONVERSION = YES; 281 | CLANG_WARN_INT_CONVERSION = YES; 282 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 283 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 284 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 285 | COPY_PHASE_STRIP = YES; 286 | ENABLE_NS_ASSERTIONS = NO; 287 | GCC_C_LANGUAGE_STANDARD = gnu99; 288 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 289 | GCC_WARN_UNDECLARED_SELECTOR = YES; 290 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 291 | GCC_WARN_UNUSED_FUNCTION = YES; 292 | GCC_WARN_UNUSED_VARIABLE = YES; 293 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 294 | SDKROOT = iphoneos; 295 | VALIDATE_PRODUCT = YES; 296 | }; 297 | name = Release; 298 | }; 299 | 5E141AEE17A9AC33007C6139 /* Debug */ = { 300 | isa = XCBuildConfiguration; 301 | buildSettings = { 302 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 303 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 304 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 305 | GCC_PREFIX_HEADER = "UICollectionView-Spring-Demo/UICollectionView-Spring-Demo-Prefix.pch"; 306 | INFOPLIST_FILE = "UICollectionView-Spring-Demo/UICollectionView-Spring-Demo-Info.plist"; 307 | PRODUCT_NAME = "$(TARGET_NAME)"; 308 | WRAPPER_EXTENSION = app; 309 | }; 310 | name = Debug; 311 | }; 312 | 5E141AEF17A9AC33007C6139 /* Release */ = { 313 | isa = XCBuildConfiguration; 314 | buildSettings = { 315 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 316 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 317 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 318 | GCC_PREFIX_HEADER = "UICollectionView-Spring-Demo/UICollectionView-Spring-Demo-Prefix.pch"; 319 | INFOPLIST_FILE = "UICollectionView-Spring-Demo/UICollectionView-Spring-Demo-Info.plist"; 320 | PRODUCT_NAME = "$(TARGET_NAME)"; 321 | WRAPPER_EXTENSION = app; 322 | }; 323 | name = Release; 324 | }; 325 | /* End XCBuildConfiguration section */ 326 | 327 | /* Begin XCConfigurationList section */ 328 | 5E141ABC17A9AC32007C6139 /* Build configuration list for PBXProject "UICollectionView-Spring-Demo" */ = { 329 | isa = XCConfigurationList; 330 | buildConfigurations = ( 331 | 5E141AEB17A9AC33007C6139 /* Debug */, 332 | 5E141AEC17A9AC33007C6139 /* Release */, 333 | ); 334 | defaultConfigurationIsVisible = 0; 335 | defaultConfigurationName = Release; 336 | }; 337 | 5E141AED17A9AC33007C6139 /* Build configuration list for PBXNativeTarget "UICollectionView-Spring-Demo" */ = { 338 | isa = XCConfigurationList; 339 | buildConfigurations = ( 340 | 5E141AEE17A9AC33007C6139 /* Debug */, 341 | 5E141AEF17A9AC33007C6139 /* Release */, 342 | ); 343 | defaultConfigurationIsVisible = 0; 344 | defaultConfigurationName = Release; 345 | }; 346 | /* End XCConfigurationList section */ 347 | }; 348 | rootObject = 5E141AB917A9AC32007C6139 /* Project object */; 349 | } 350 | -------------------------------------------------------------------------------- /UICollectionView-Spring-Demo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /UICollectionView-Spring-Demo.xcodeproj/xcuserdata/ash.xcuserdatad/xcschemes/UICollectionView-Spring-Demo.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 49 | 50 | 51 | 52 | 61 | 62 | 68 | 69 | 70 | 71 | 72 | 73 | 79 | 80 | 86 | 87 | 88 | 89 | 91 | 92 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /UICollectionView-Spring-Demo.xcodeproj/xcuserdata/ash.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | UICollectionView-Spring-Demo.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 5E141AC017A9AC32007C6139 16 | 17 | primary 18 | 19 | 20 | 5E141ADB17A9AC33007C6139 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /UICollectionView-Spring-Demo/Images.xcassets/AppIcon.appiconset/AppIcon29x29@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeehanLax/UICollectionView-Spring-Demo/565d65e8492fdbee576f96d8f795e55dc2e815a1/UICollectionView-Spring-Demo/Images.xcassets/AppIcon.appiconset/AppIcon29x29@2x.png -------------------------------------------------------------------------------- /UICollectionView-Spring-Demo/Images.xcassets/AppIcon.appiconset/AppIcon40x40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeehanLax/UICollectionView-Spring-Demo/565d65e8492fdbee576f96d8f795e55dc2e815a1/UICollectionView-Spring-Demo/Images.xcassets/AppIcon.appiconset/AppIcon40x40@2x.png -------------------------------------------------------------------------------- /UICollectionView-Spring-Demo/Images.xcassets/AppIcon.appiconset/AppIcon60x60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeehanLax/UICollectionView-Spring-Demo/565d65e8492fdbee576f96d8f795e55dc2e815a1/UICollectionView-Spring-Demo/Images.xcassets/AppIcon.appiconset/AppIcon60x60@2x.png -------------------------------------------------------------------------------- /UICollectionView-Spring-Demo/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "29x29", 5 | "idiom" : "iphone", 6 | "filename" : "AppIcon29x29@2x.png", 7 | "scale" : "2x" 8 | }, 9 | { 10 | "size" : "40x40", 11 | "idiom" : "iphone", 12 | "filename" : "AppIcon40x40@2x.png", 13 | "scale" : "2x" 14 | }, 15 | { 16 | "size" : "60x60", 17 | "idiom" : "iphone", 18 | "filename" : "AppIcon60x60@2x.png", 19 | "scale" : "2x" 20 | } 21 | ], 22 | "info" : { 23 | "version" : 1, 24 | "author" : "xcode" 25 | } 26 | } -------------------------------------------------------------------------------- /UICollectionView-Spring-Demo/Images.xcassets/Horizontal-TabIcon.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "2x", 6 | "filename" : "Horizontal-TabIcon@2x.png" 7 | } 8 | ], 9 | "info" : { 10 | "version" : 1, 11 | "author" : "xcode" 12 | } 13 | } -------------------------------------------------------------------------------- /UICollectionView-Spring-Demo/Images.xcassets/Horizontal-TabIcon.imageset/Horizontal-TabIcon@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeehanLax/UICollectionView-Spring-Demo/565d65e8492fdbee576f96d8f795e55dc2e815a1/UICollectionView-Spring-Demo/Images.xcassets/Horizontal-TabIcon.imageset/Horizontal-TabIcon@2x.png -------------------------------------------------------------------------------- /UICollectionView-Spring-Demo/Images.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "iphone", 6 | "extent" : "full-screen", 7 | "minimum-system-version" : "7.0", 8 | "scale" : "2x" 9 | }, 10 | { 11 | "orientation" : "portrait", 12 | "idiom" : "iphone", 13 | "subtype" : "retina4", 14 | "extent" : "full-screen", 15 | "minimum-system-version" : "7.0", 16 | "scale" : "2x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /UICollectionView-Spring-Demo/Images.xcassets/Vertical-TabIcon.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "2x", 6 | "filename" : "Vertical-TabIcon@2x.png" 7 | } 8 | ], 9 | "info" : { 10 | "version" : 1, 11 | "author" : "xcode" 12 | } 13 | } -------------------------------------------------------------------------------- /UICollectionView-Spring-Demo/Images.xcassets/Vertical-TabIcon.imageset/Vertical-TabIcon@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeehanLax/UICollectionView-Spring-Demo/565d65e8492fdbee576f96d8f795e55dc2e815a1/UICollectionView-Spring-Demo/Images.xcassets/Vertical-TabIcon.imageset/Vertical-TabIcon@2x.png -------------------------------------------------------------------------------- /UICollectionView-Spring-Demo/Storyboard.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 58 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 152 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | The MIT License (MIT) 377 | 378 | Copyright (c) 2013 Teehan+Lax 379 | 380 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 381 | 382 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 383 | 384 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | -------------------------------------------------------------------------------- /UICollectionView-Spring-Demo/TLAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // TLAppDelegate.h 3 | // UICollectionView-Spring-Demo 4 | // 5 | // Created by Ash Furrow on 2013-07-31. 6 | // Copyright (c) 2013 Teehan+Lax. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface TLAppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /UICollectionView-Spring-Demo/TLAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // TLAppDelegate.m 3 | // UICollectionView-Spring-Demo 4 | // 5 | // Created by Ash Furrow on 2013-07-31. 6 | // Copyright (c) 2013 Teehan+Lax. All rights reserved. 7 | // 8 | 9 | #import "TLAppDelegate.h" 10 | 11 | @implementation TLAppDelegate 12 | 13 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 14 | return YES; 15 | } 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /UICollectionView-Spring-Demo/TLSpringFlowLayout.h: -------------------------------------------------------------------------------- 1 | // 2 | // TLSpringFlowLayout.h 3 | // UICollectionView-Spring-Demo 4 | // 5 | // Created by Ash Furrow on 2013-07-31. 6 | // Copyright (c) 2013 Teehan+Lax. All rights reserved. 7 | // 8 | 9 | 10 | #if !__has_feature(objc_modules) 11 | // Objective-C Modules are recommended over traditional import statements for numerous benefits 12 | #import 13 | #else 14 | @import UIKit; 15 | #endif 16 | 17 | #ifndef __IPHONE_7_0 18 | #error TLSpringFlowLayout requires APIs only available in iOS SDK 7.0 and later 19 | #endif 20 | 21 | 22 | /// The default resistance factor that determines the bounce of the collection. Default is 900.0f. 23 | #define kScrollResistanceFactorDefault 900.0f; 24 | 25 | 26 | /// A UICollectionViewFlowLayout subclass that, when implemented, creates a dynamic / bouncing scroll effect for UICollectionViews. 27 | @interface TLSpringFlowLayout : UICollectionViewFlowLayout 28 | 29 | 30 | /// The scrolling resistance factor determines how much bounce / resistance the collection has. A higher number is less bouncy, a lower number is more bouncy. The default is 900.0f. 31 | @property (nonatomic, assign) CGFloat scrollResistanceFactor; 32 | 33 | /// The dynamic animator used to animate the collection's bounce 34 | @property (nonatomic, strong, readonly) UIDynamicAnimator *dynamicAnimator; 35 | 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /UICollectionView-Spring-Demo/TLSpringFlowLayout.m: -------------------------------------------------------------------------------- 1 | // 2 | // TLSpringFlowLayout.m 3 | // UICollectionView-Spring-Demo 4 | // 5 | // Created by Ash Furrow on 2013-07-31. 6 | // Copyright (c) 2013 Teehan+Lax. All rights reserved. 7 | // 8 | 9 | #import "TLSpringFlowLayout.h" 10 | 11 | @interface TLSpringFlowLayout () 12 | 13 | /// The dynamic animator used to animate the collection's bounce 14 | @property (nonatomic, strong, readwrite) UIDynamicAnimator *dynamicAnimator; 15 | 16 | // Needed for tiling 17 | @property (nonatomic, strong) NSMutableSet *visibleIndexPathsSet; 18 | @property (nonatomic, strong) NSMutableSet *visibleHeaderAndFooterSet; 19 | @property (nonatomic, assign) CGFloat latestDelta; 20 | @property (nonatomic, assign) UIInterfaceOrientation interfaceOrientation; 21 | 22 | @end 23 | 24 | @implementation TLSpringFlowLayout 25 | 26 | - (instancetype)init { 27 | self = [super init]; 28 | if (self){ 29 | [self setup]; 30 | } 31 | return self; 32 | } 33 | 34 | - (instancetype)initWithCoder:(NSCoder *)aDecoder { 35 | self = [super initWithCoder:aDecoder]; 36 | if (self){ 37 | [self setup]; 38 | } 39 | return self; 40 | } 41 | 42 | - (void)setup { 43 | _dynamicAnimator = [[UIDynamicAnimator alloc] initWithCollectionViewLayout:self]; 44 | _visibleIndexPathsSet = [NSMutableSet set]; 45 | _visibleHeaderAndFooterSet = [[NSMutableSet alloc] init]; 46 | } 47 | 48 | - (void)prepareLayout { 49 | [super prepareLayout]; 50 | 51 | if ([[UIApplication sharedApplication] statusBarOrientation] != self.interfaceOrientation) { 52 | [self.dynamicAnimator removeAllBehaviors]; 53 | self.visibleIndexPathsSet = [NSMutableSet set]; 54 | } 55 | 56 | self.interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation]; 57 | 58 | // Need to overflow our actual visible rect slightly to avoid flickering. 59 | CGRect visibleRect = CGRectInset((CGRect){.origin = self.collectionView.bounds.origin, .size = self.collectionView.frame.size}, -100, -100); 60 | 61 | NSArray *itemsInVisibleRectArray = [super layoutAttributesForElementsInRect:visibleRect]; 62 | 63 | NSSet *itemsIndexPathsInVisibleRectSet = [NSSet setWithArray:[itemsInVisibleRectArray valueForKey:@"indexPath"]]; 64 | 65 | // Step 1: Remove any behaviours that are no longer visible. 66 | NSArray *noLongerVisibleBehaviours = [self.dynamicAnimator.behaviors filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(UIAttachmentBehavior *behaviour, NSDictionary *bindings) { 67 | return [itemsIndexPathsInVisibleRectSet containsObject:[[[behaviour items] firstObject] indexPath]] == NO; 68 | }]]; 69 | 70 | [noLongerVisibleBehaviours enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) { 71 | [self.dynamicAnimator removeBehavior:obj]; 72 | [self.visibleIndexPathsSet removeObject:[[[obj items] firstObject] indexPath]]; 73 | [self.visibleHeaderAndFooterSet removeObject:[[[obj items] firstObject] indexPath]]; 74 | }]; 75 | 76 | // Step 2: Add any newly visible behaviours. 77 | // A "newly visible" item is one that is in the itemsInVisibleRect(Set|Array) but not in the visibleIndexPathsSet 78 | NSArray *newlyVisibleItems = [itemsInVisibleRectArray filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(UICollectionViewLayoutAttributes *item, NSDictionary *bindings) { 79 | return (item.representedElementCategory == UICollectionElementCategoryCell ? 80 | [self.visibleIndexPathsSet containsObject:item.indexPath] : [self.visibleHeaderAndFooterSet containsObject:item.indexPath]) == NO; 81 | }]]; 82 | 83 | CGPoint touchLocation = [self.collectionView.panGestureRecognizer locationInView:self.collectionView]; 84 | 85 | [newlyVisibleItems enumerateObjectsUsingBlock:^(UICollectionViewLayoutAttributes *item, NSUInteger idx, BOOL *stop) { 86 | CGPoint center = item.center; 87 | UIAttachmentBehavior *springBehaviour = [[UIAttachmentBehavior alloc] initWithItem:item attachedToAnchor:center]; 88 | 89 | springBehaviour.length = 1.0f; 90 | springBehaviour.damping = 0.8f; 91 | springBehaviour.frequency = 1.0f; 92 | 93 | // If our touchLocation is not (0,0), we'll need to adjust our item's center "in flight" 94 | if (!CGPointEqualToPoint(CGPointZero, touchLocation)) { 95 | if (self.scrollDirection == UICollectionViewScrollDirectionVertical) { 96 | CGFloat distanceFromTouch = fabsf(touchLocation.y - springBehaviour.anchorPoint.y); 97 | 98 | CGFloat scrollResistance; 99 | if (self.scrollResistanceFactor) scrollResistance = distanceFromTouch / self.scrollResistanceFactor; 100 | else scrollResistance = distanceFromTouch / kScrollResistanceFactorDefault; 101 | 102 | if (self.latestDelta < 0) center.y += MAX(self.latestDelta, self.latestDelta*scrollResistance); 103 | else center.y += MIN(self.latestDelta, self.latestDelta*scrollResistance); 104 | 105 | item.center = center; 106 | 107 | } else { 108 | CGFloat distanceFromTouch = fabsf(touchLocation.x - springBehaviour.anchorPoint.x); 109 | 110 | CGFloat scrollResistance; 111 | if (self.scrollResistanceFactor) scrollResistance = distanceFromTouch / self.scrollResistanceFactor; 112 | else scrollResistance = distanceFromTouch / kScrollResistanceFactorDefault; 113 | 114 | if (self.latestDelta < 0) center.x += MAX(self.latestDelta, self.latestDelta*scrollResistance); 115 | else center.x += MIN(self.latestDelta, self.latestDelta*scrollResistance); 116 | 117 | item.center = center; 118 | } 119 | } 120 | 121 | [self.dynamicAnimator addBehavior:springBehaviour]; 122 | if(item.representedElementCategory == UICollectionElementCategoryCell) 123 | { 124 | [self.visibleIndexPathsSet addObject:item.indexPath]; 125 | } 126 | else 127 | { 128 | [self.visibleHeaderAndFooterSet addObject:item.indexPath]; 129 | } 130 | }]; 131 | } 132 | 133 | - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect { 134 | return [self.dynamicAnimator itemsInRect:rect]; 135 | } 136 | 137 | - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath { 138 | UICollectionViewLayoutAttributes *dynamicLayoutAttributes = [self.dynamicAnimator layoutAttributesForCellAtIndexPath:indexPath]; 139 | // Check if dynamic animator has layout attributes for a layout, otherwise use the flow layouts properties. This will prevent crashing when you add items later in a performBatchUpdates block (e.g. triggered by NSFetchedResultsController update) 140 | return (dynamicLayoutAttributes)?dynamicLayoutAttributes:[super layoutAttributesForItemAtIndexPath:indexPath]; 141 | } 142 | 143 | - (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds { 144 | UIScrollView *scrollView = self.collectionView; 145 | 146 | CGFloat delta; 147 | if (self.scrollDirection == UICollectionViewScrollDirectionVertical) delta = newBounds.origin.y - scrollView.bounds.origin.y; 148 | else delta = newBounds.origin.x - scrollView.bounds.origin.x; 149 | 150 | self.latestDelta = delta; 151 | 152 | CGPoint touchLocation = [self.collectionView.panGestureRecognizer locationInView:self.collectionView]; 153 | 154 | [self.dynamicAnimator.behaviors enumerateObjectsUsingBlock:^(UIAttachmentBehavior *springBehaviour, NSUInteger idx, BOOL *stop) { 155 | if (self.scrollDirection == UICollectionViewScrollDirectionVertical) { 156 | CGFloat distanceFromTouch = fabsf(touchLocation.y - springBehaviour.anchorPoint.y); 157 | 158 | CGFloat scrollResistance; 159 | if (self.scrollResistanceFactor) scrollResistance = distanceFromTouch / self.scrollResistanceFactor; 160 | else scrollResistance = distanceFromTouch / kScrollResistanceFactorDefault; 161 | 162 | UICollectionViewLayoutAttributes *item = [springBehaviour.items firstObject]; 163 | CGPoint center = item.center; 164 | if (delta < 0) center.y += MAX(delta, delta*scrollResistance); 165 | else center.y += MIN(delta, delta*scrollResistance); 166 | 167 | item.center = center; 168 | 169 | [self.dynamicAnimator updateItemUsingCurrentState:item]; 170 | } else { 171 | CGFloat distanceFromTouch = fabsf(touchLocation.x - springBehaviour.anchorPoint.x); 172 | 173 | CGFloat scrollResistance; 174 | if (self.scrollResistanceFactor) scrollResistance = distanceFromTouch / self.scrollResistanceFactor; 175 | else scrollResistance = distanceFromTouch / kScrollResistanceFactorDefault; 176 | 177 | UICollectionViewLayoutAttributes *item = [springBehaviour.items firstObject]; 178 | CGPoint center = item.center; 179 | if (delta < 0) center.x += MAX(delta, delta*scrollResistance); 180 | else center.x += MIN(delta, delta*scrollResistance); 181 | 182 | item.center = center; 183 | 184 | [self.dynamicAnimator updateItemUsingCurrentState:item]; 185 | } 186 | }]; 187 | 188 | return NO; 189 | } 190 | 191 | - (void)prepareForCollectionViewUpdates:(NSArray *)updateItems { 192 | [super prepareForCollectionViewUpdates:updateItems]; 193 | 194 | [updateItems enumerateObjectsUsingBlock:^(UICollectionViewUpdateItem *updateItem, NSUInteger idx, BOOL *stop) { 195 | if (updateItem.updateAction == UICollectionUpdateActionInsert) { 196 | if([self.dynamicAnimator layoutAttributesForCellAtIndexPath:updateItem.indexPathAfterUpdate]) 197 | { 198 | return; 199 | } 200 | 201 | UICollectionViewLayoutAttributes *attributes = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:updateItem.indexPathAfterUpdate]; 202 | 203 | //attributes.frame = CGRectMake(10, updateItem.indexPathAfterUpdate.item * 310, 300, 44); // or some other initial frame 204 | 205 | UIAttachmentBehavior *springBehaviour = [[UIAttachmentBehavior alloc] initWithItem:attributes attachedToAnchor:attributes.center]; 206 | 207 | springBehaviour.length = 1.0f; 208 | springBehaviour.damping = 0.8f; 209 | springBehaviour.frequency = 1.0f; 210 | [self.dynamicAnimator addBehavior:springBehaviour]; 211 | } 212 | }]; 213 | } 214 | 215 | @end 216 | -------------------------------------------------------------------------------- /UICollectionView-Spring-Demo/TLViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // TLViewController.h 3 | // UICollectionView-Spring-Demo 4 | // 5 | // Created by Ash Furrow on 2013-07-31. 6 | // Copyright (c) 2013 Teehan+Lax. All rights reserved. 7 | // 8 | 9 | @import UIKit; 10 | 11 | @interface TLViewController : UIViewController 12 | 13 | @property (weak, nonatomic) IBOutlet UIView *headerView; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /UICollectionView-Spring-Demo/TLViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // TLViewController.m 3 | // UICollectionView-Spring-Demo 4 | // 5 | // Created by Ash Furrow on 2013-07-31. 6 | // Copyright (c) 2013 Teehan+Lax. All rights reserved. 7 | // 8 | 9 | #import "TLViewController.h" 10 | #import "TLSpringFlowLayout.h" 11 | 12 | @implementation TLViewController 13 | 14 | static NSString * CellIdentifier = @"cellIdentifier"; 15 | 16 | - (void)viewDidLoad { 17 | [super viewDidLoad]; 18 | } 19 | 20 | - (void)viewWillAppear:(BOOL)animated { 21 | [super viewWillAppear:animated]; 22 | 23 | self.headerView.layer.shadowOpacity = 0.5; 24 | self.headerView.layer.shadowRadius = 3.8; 25 | self.headerView.layer.shadowOffset = CGSizeMake(0.6, 0.6); 26 | self.headerView.layer.shadowColor = [UIColor darkGrayColor].CGColor; 27 | } 28 | 29 | #pragma mark - UICollectionView Methods 30 | 31 | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { 32 | return 10000; 33 | } 34 | 35 | - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { 36 | UICollectionViewCell *otherCell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath]; 37 | return otherCell; 38 | } 39 | 40 | @end -------------------------------------------------------------------------------- /UICollectionView-Spring-Demo/UICollectionView-Spring-Demo-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | SpringCollection 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | com.teehanlax.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIMainStoryboardFile 28 | Storyboard 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UIStatusBarHidden 34 | 35 | UIStatusBarStyle 36 | UIStatusBarStyleDefault 37 | UISupportedInterfaceOrientations 38 | 39 | UIInterfaceOrientationPortrait 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /UICollectionView-Spring-Demo/UICollectionView-Spring-Demo-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #import 8 | 9 | #ifndef __IPHONE_7_0 10 | #warning "This project uses features only available in iOS SDK 7.0 and later." 11 | #endif 12 | 13 | #ifdef __OBJC__ 14 | @import UIKit; 15 | @import Foundation; 16 | @import CoreGraphics; 17 | #endif 18 | -------------------------------------------------------------------------------- /UICollectionView-Spring-Demo/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /UICollectionView-Spring-Demo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // UICollectionView-Spring-Demo 4 | // 5 | // Created by Ash Furrow on 2013-07-31. 6 | // Copyright (c) 2013 Teehan+Lax. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "TLAppDelegate.h" 12 | 13 | int main(int argc, char * argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([TLAppDelegate class])); 17 | } 18 | } 19 | --------------------------------------------------------------------------------