├── .gitignore ├── LICENSE ├── README.md ├── VVSpringCollectionViewDemo.xcodeproj └── project.pbxproj ├── VVSpringCollectionViewDemo ├── AppDelegate.h ├── AppDelegate.m ├── Base.lproj │ └── Main_iPhone.storyboard ├── Images.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── LaunchImage.launchimage │ │ └── Contents.json ├── UIColor+VVRandomColor.h ├── UIColor+VVRandomColor.m ├── VVSpringCollectionViewDemo-Info.plist ├── VVSpringCollectionViewDemo-Prefix.pch ├── ViewController.h ├── ViewController.m ├── en.lproj │ └── InfoPlist.strings └── main.m ├── VVSpringCollectionViewDemoTests ├── VVSpringCollectionViewDemoTests-Info.plist ├── VVSpringCollectionViewDemoTests.m └── en.lproj │ └── InfoPlist.strings ├── VVSpringCollectionViewFlowLayout ├── VVSpringCollectionViewFlowLayout.h └── VVSpringCollectionViewFlowLayout.m └── spring-collection-view-over-ios7.gif /.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 Wei Wang 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 | VVSpringCollectionViewFlowLayout 2 | ================================ 3 | 4 | A spring-like collection view layout. The same effect like iOS7's Message.app. 5 | 6 | ![demo](https://raw.github.com/onevcat/VVSpringCollectionViewFlowLayout/master/spring-collection-view-over-ios7.gif) 7 | 8 | Copy files under `VVSpringCollectionViewFlowLayout` to your project and then init or set a collection view with `VVSpringCollectionViewFlowLayout` instance. 9 | 10 | ```objc 11 | VVSpringCollectionViewFlowLayout *layout = [[VVSpringCollectionViewFlowLayout alloc] init]; 12 | UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:layout]; 13 | ``` 14 | 15 | See more in the demo. 16 | 17 | This project is for my blog post: [http://onevcat.com/2013/09/spring-list-like-ios7-message](http://onevcat.com/2013/09/spring-list-like-ios7-message) 18 | -------------------------------------------------------------------------------- /VVSpringCollectionViewDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | D12612E817D4C6410031B304 /* VVSpringCollectionViewFlowLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = D12612E717D4C6410031B304 /* VVSpringCollectionViewFlowLayout.m */; }; 11 | D1A750D017D3136C00159617 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D1A750CF17D3136C00159617 /* Foundation.framework */; }; 12 | D1A750D217D3136C00159617 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D1A750D117D3136C00159617 /* CoreGraphics.framework */; }; 13 | D1A750D417D3136C00159617 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D1A750D317D3136C00159617 /* UIKit.framework */; }; 14 | D1A750DA17D3136C00159617 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = D1A750D817D3136C00159617 /* InfoPlist.strings */; }; 15 | D1A750DC17D3136C00159617 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = D1A750DB17D3136C00159617 /* main.m */; }; 16 | D1A750E017D3136C00159617 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = D1A750DF17D3136C00159617 /* AppDelegate.m */; }; 17 | D1A750E317D3136C00159617 /* Main_iPhone.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D1A750E117D3136C00159617 /* Main_iPhone.storyboard */; }; 18 | D1A750E917D3136C00159617 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D1A750E817D3136C00159617 /* ViewController.m */; }; 19 | D1A750EB17D3136C00159617 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D1A750EA17D3136C00159617 /* Images.xcassets */; }; 20 | D1A750F217D3136C00159617 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D1A750F117D3136C00159617 /* XCTest.framework */; }; 21 | D1A750F317D3136C00159617 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D1A750CF17D3136C00159617 /* Foundation.framework */; }; 22 | D1A750F417D3136C00159617 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D1A750D317D3136C00159617 /* UIKit.framework */; }; 23 | D1A750FC17D3136C00159617 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = D1A750FA17D3136C00159617 /* InfoPlist.strings */; }; 24 | D1A750FE17D3136C00159617 /* VVSpringCollectionViewDemoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D1A750FD17D3136C00159617 /* VVSpringCollectionViewDemoTests.m */; }; 25 | D1A7511117D3228900159617 /* UIColor+VVRandomColor.m in Sources */ = {isa = PBXBuildFile; fileRef = D1A7511017D3228900159617 /* UIColor+VVRandomColor.m */; }; 26 | /* End PBXBuildFile section */ 27 | 28 | /* Begin PBXContainerItemProxy section */ 29 | D1A750F517D3136C00159617 /* PBXContainerItemProxy */ = { 30 | isa = PBXContainerItemProxy; 31 | containerPortal = D1A750C417D3136C00159617 /* Project object */; 32 | proxyType = 1; 33 | remoteGlobalIDString = D1A750CB17D3136C00159617; 34 | remoteInfo = VVSpringCollectionViewDemo; 35 | }; 36 | /* End PBXContainerItemProxy section */ 37 | 38 | /* Begin PBXFileReference section */ 39 | D12612E617D4C6410031B304 /* VVSpringCollectionViewFlowLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VVSpringCollectionViewFlowLayout.h; sourceTree = ""; }; 40 | D12612E717D4C6410031B304 /* VVSpringCollectionViewFlowLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VVSpringCollectionViewFlowLayout.m; sourceTree = ""; }; 41 | D1A750CC17D3136C00159617 /* VVSpringCollectionViewDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = VVSpringCollectionViewDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 42 | D1A750CF17D3136C00159617 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 43 | D1A750D117D3136C00159617 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 44 | D1A750D317D3136C00159617 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 45 | D1A750D717D3136C00159617 /* VVSpringCollectionViewDemo-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "VVSpringCollectionViewDemo-Info.plist"; sourceTree = ""; }; 46 | D1A750D917D3136C00159617 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 47 | D1A750DB17D3136C00159617 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 48 | D1A750DD17D3136C00159617 /* VVSpringCollectionViewDemo-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "VVSpringCollectionViewDemo-Prefix.pch"; sourceTree = ""; }; 49 | D1A750DE17D3136C00159617 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 50 | D1A750DF17D3136C00159617 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 51 | D1A750E217D3136C00159617 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main_iPhone.storyboard; sourceTree = ""; }; 52 | D1A750E717D3136C00159617 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 53 | D1A750E817D3136C00159617 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 54 | D1A750EA17D3136C00159617 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 55 | D1A750F017D3136C00159617 /* VVSpringCollectionViewDemoTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = VVSpringCollectionViewDemoTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 56 | D1A750F117D3136C00159617 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 57 | D1A750F917D3136C00159617 /* VVSpringCollectionViewDemoTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "VVSpringCollectionViewDemoTests-Info.plist"; sourceTree = ""; }; 58 | D1A750FB17D3136C00159617 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 59 | D1A750FD17D3136C00159617 /* VVSpringCollectionViewDemoTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VVSpringCollectionViewDemoTests.m; sourceTree = ""; }; 60 | D1A7510F17D3228900159617 /* UIColor+VVRandomColor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIColor+VVRandomColor.h"; sourceTree = ""; }; 61 | D1A7511017D3228900159617 /* UIColor+VVRandomColor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIColor+VVRandomColor.m"; sourceTree = ""; }; 62 | /* End PBXFileReference section */ 63 | 64 | /* Begin PBXFrameworksBuildPhase section */ 65 | D1A750C917D3136C00159617 /* Frameworks */ = { 66 | isa = PBXFrameworksBuildPhase; 67 | buildActionMask = 2147483647; 68 | files = ( 69 | D1A750D217D3136C00159617 /* CoreGraphics.framework in Frameworks */, 70 | D1A750D417D3136C00159617 /* UIKit.framework in Frameworks */, 71 | D1A750D017D3136C00159617 /* Foundation.framework in Frameworks */, 72 | ); 73 | runOnlyForDeploymentPostprocessing = 0; 74 | }; 75 | D1A750ED17D3136C00159617 /* Frameworks */ = { 76 | isa = PBXFrameworksBuildPhase; 77 | buildActionMask = 2147483647; 78 | files = ( 79 | D1A750F217D3136C00159617 /* XCTest.framework in Frameworks */, 80 | D1A750F417D3136C00159617 /* UIKit.framework in Frameworks */, 81 | D1A750F317D3136C00159617 /* Foundation.framework in Frameworks */, 82 | ); 83 | runOnlyForDeploymentPostprocessing = 0; 84 | }; 85 | /* End PBXFrameworksBuildPhase section */ 86 | 87 | /* Begin PBXGroup section */ 88 | D12612E517D4C6410031B304 /* VVSpringCollectionViewFlowLayout */ = { 89 | isa = PBXGroup; 90 | children = ( 91 | D12612E617D4C6410031B304 /* VVSpringCollectionViewFlowLayout.h */, 92 | D12612E717D4C6410031B304 /* VVSpringCollectionViewFlowLayout.m */, 93 | ); 94 | path = VVSpringCollectionViewFlowLayout; 95 | sourceTree = ""; 96 | }; 97 | D1A750C317D3136C00159617 = { 98 | isa = PBXGroup; 99 | children = ( 100 | D12612E517D4C6410031B304 /* VVSpringCollectionViewFlowLayout */, 101 | D1A750D517D3136C00159617 /* VVSpringCollectionViewDemo */, 102 | D1A750F717D3136C00159617 /* VVSpringCollectionViewDemoTests */, 103 | D1A750CE17D3136C00159617 /* Frameworks */, 104 | D1A750CD17D3136C00159617 /* Products */, 105 | ); 106 | sourceTree = ""; 107 | }; 108 | D1A750CD17D3136C00159617 /* Products */ = { 109 | isa = PBXGroup; 110 | children = ( 111 | D1A750CC17D3136C00159617 /* VVSpringCollectionViewDemo.app */, 112 | D1A750F017D3136C00159617 /* VVSpringCollectionViewDemoTests.xctest */, 113 | ); 114 | name = Products; 115 | sourceTree = ""; 116 | }; 117 | D1A750CE17D3136C00159617 /* Frameworks */ = { 118 | isa = PBXGroup; 119 | children = ( 120 | D1A750CF17D3136C00159617 /* Foundation.framework */, 121 | D1A750D117D3136C00159617 /* CoreGraphics.framework */, 122 | D1A750D317D3136C00159617 /* UIKit.framework */, 123 | D1A750F117D3136C00159617 /* XCTest.framework */, 124 | ); 125 | name = Frameworks; 126 | sourceTree = ""; 127 | }; 128 | D1A750D517D3136C00159617 /* VVSpringCollectionViewDemo */ = { 129 | isa = PBXGroup; 130 | children = ( 131 | D1A750DE17D3136C00159617 /* AppDelegate.h */, 132 | D1A750DF17D3136C00159617 /* AppDelegate.m */, 133 | D1A750E117D3136C00159617 /* Main_iPhone.storyboard */, 134 | D1A750E717D3136C00159617 /* ViewController.h */, 135 | D1A750E817D3136C00159617 /* ViewController.m */, 136 | D1A7510F17D3228900159617 /* UIColor+VVRandomColor.h */, 137 | D1A7511017D3228900159617 /* UIColor+VVRandomColor.m */, 138 | D1A750EA17D3136C00159617 /* Images.xcassets */, 139 | D1A750D617D3136C00159617 /* Supporting Files */, 140 | ); 141 | path = VVSpringCollectionViewDemo; 142 | sourceTree = ""; 143 | }; 144 | D1A750D617D3136C00159617 /* Supporting Files */ = { 145 | isa = PBXGroup; 146 | children = ( 147 | D1A750D717D3136C00159617 /* VVSpringCollectionViewDemo-Info.plist */, 148 | D1A750D817D3136C00159617 /* InfoPlist.strings */, 149 | D1A750DB17D3136C00159617 /* main.m */, 150 | D1A750DD17D3136C00159617 /* VVSpringCollectionViewDemo-Prefix.pch */, 151 | ); 152 | name = "Supporting Files"; 153 | sourceTree = ""; 154 | }; 155 | D1A750F717D3136C00159617 /* VVSpringCollectionViewDemoTests */ = { 156 | isa = PBXGroup; 157 | children = ( 158 | D1A750FD17D3136C00159617 /* VVSpringCollectionViewDemoTests.m */, 159 | D1A750F817D3136C00159617 /* Supporting Files */, 160 | ); 161 | path = VVSpringCollectionViewDemoTests; 162 | sourceTree = ""; 163 | }; 164 | D1A750F817D3136C00159617 /* Supporting Files */ = { 165 | isa = PBXGroup; 166 | children = ( 167 | D1A750F917D3136C00159617 /* VVSpringCollectionViewDemoTests-Info.plist */, 168 | D1A750FA17D3136C00159617 /* InfoPlist.strings */, 169 | ); 170 | name = "Supporting Files"; 171 | sourceTree = ""; 172 | }; 173 | /* End PBXGroup section */ 174 | 175 | /* Begin PBXNativeTarget section */ 176 | D1A750CB17D3136C00159617 /* VVSpringCollectionViewDemo */ = { 177 | isa = PBXNativeTarget; 178 | buildConfigurationList = D1A7510117D3136C00159617 /* Build configuration list for PBXNativeTarget "VVSpringCollectionViewDemo" */; 179 | buildPhases = ( 180 | D1A750C817D3136C00159617 /* Sources */, 181 | D1A750C917D3136C00159617 /* Frameworks */, 182 | D1A750CA17D3136C00159617 /* Resources */, 183 | ); 184 | buildRules = ( 185 | ); 186 | dependencies = ( 187 | ); 188 | name = VVSpringCollectionViewDemo; 189 | productName = VVSpringCollectionViewDemo; 190 | productReference = D1A750CC17D3136C00159617 /* VVSpringCollectionViewDemo.app */; 191 | productType = "com.apple.product-type.application"; 192 | }; 193 | D1A750EF17D3136C00159617 /* VVSpringCollectionViewDemoTests */ = { 194 | isa = PBXNativeTarget; 195 | buildConfigurationList = D1A7510417D3136C00159617 /* Build configuration list for PBXNativeTarget "VVSpringCollectionViewDemoTests" */; 196 | buildPhases = ( 197 | D1A750EC17D3136C00159617 /* Sources */, 198 | D1A750ED17D3136C00159617 /* Frameworks */, 199 | D1A750EE17D3136C00159617 /* Resources */, 200 | ); 201 | buildRules = ( 202 | ); 203 | dependencies = ( 204 | D1A750F617D3136C00159617 /* PBXTargetDependency */, 205 | ); 206 | name = VVSpringCollectionViewDemoTests; 207 | productName = VVSpringCollectionViewDemoTests; 208 | productReference = D1A750F017D3136C00159617 /* VVSpringCollectionViewDemoTests.xctest */; 209 | productType = "com.apple.product-type.bundle.unit-test"; 210 | }; 211 | /* End PBXNativeTarget section */ 212 | 213 | /* Begin PBXProject section */ 214 | D1A750C417D3136C00159617 /* Project object */ = { 215 | isa = PBXProject; 216 | attributes = { 217 | LastUpgradeCheck = 0500; 218 | ORGANIZATIONNAME = "王 巍"; 219 | TargetAttributes = { 220 | D1A750EF17D3136C00159617 = { 221 | TestTargetID = D1A750CB17D3136C00159617; 222 | }; 223 | }; 224 | }; 225 | buildConfigurationList = D1A750C717D3136C00159617 /* Build configuration list for PBXProject "VVSpringCollectionViewDemo" */; 226 | compatibilityVersion = "Xcode 3.2"; 227 | developmentRegion = English; 228 | hasScannedForEncodings = 0; 229 | knownRegions = ( 230 | en, 231 | Base, 232 | ); 233 | mainGroup = D1A750C317D3136C00159617; 234 | productRefGroup = D1A750CD17D3136C00159617 /* Products */; 235 | projectDirPath = ""; 236 | projectRoot = ""; 237 | targets = ( 238 | D1A750CB17D3136C00159617 /* VVSpringCollectionViewDemo */, 239 | D1A750EF17D3136C00159617 /* VVSpringCollectionViewDemoTests */, 240 | ); 241 | }; 242 | /* End PBXProject section */ 243 | 244 | /* Begin PBXResourcesBuildPhase section */ 245 | D1A750CA17D3136C00159617 /* Resources */ = { 246 | isa = PBXResourcesBuildPhase; 247 | buildActionMask = 2147483647; 248 | files = ( 249 | D1A750EB17D3136C00159617 /* Images.xcassets in Resources */, 250 | D1A750E317D3136C00159617 /* Main_iPhone.storyboard in Resources */, 251 | D1A750DA17D3136C00159617 /* InfoPlist.strings in Resources */, 252 | ); 253 | runOnlyForDeploymentPostprocessing = 0; 254 | }; 255 | D1A750EE17D3136C00159617 /* Resources */ = { 256 | isa = PBXResourcesBuildPhase; 257 | buildActionMask = 2147483647; 258 | files = ( 259 | D1A750FC17D3136C00159617 /* InfoPlist.strings in Resources */, 260 | ); 261 | runOnlyForDeploymentPostprocessing = 0; 262 | }; 263 | /* End PBXResourcesBuildPhase section */ 264 | 265 | /* Begin PBXSourcesBuildPhase section */ 266 | D1A750C817D3136C00159617 /* Sources */ = { 267 | isa = PBXSourcesBuildPhase; 268 | buildActionMask = 2147483647; 269 | files = ( 270 | D1A7511117D3228900159617 /* UIColor+VVRandomColor.m in Sources */, 271 | D1A750E917D3136C00159617 /* ViewController.m in Sources */, 272 | D1A750E017D3136C00159617 /* AppDelegate.m in Sources */, 273 | D1A750DC17D3136C00159617 /* main.m in Sources */, 274 | D12612E817D4C6410031B304 /* VVSpringCollectionViewFlowLayout.m in Sources */, 275 | ); 276 | runOnlyForDeploymentPostprocessing = 0; 277 | }; 278 | D1A750EC17D3136C00159617 /* Sources */ = { 279 | isa = PBXSourcesBuildPhase; 280 | buildActionMask = 2147483647; 281 | files = ( 282 | D1A750FE17D3136C00159617 /* VVSpringCollectionViewDemoTests.m in Sources */, 283 | ); 284 | runOnlyForDeploymentPostprocessing = 0; 285 | }; 286 | /* End PBXSourcesBuildPhase section */ 287 | 288 | /* Begin PBXTargetDependency section */ 289 | D1A750F617D3136C00159617 /* PBXTargetDependency */ = { 290 | isa = PBXTargetDependency; 291 | target = D1A750CB17D3136C00159617 /* VVSpringCollectionViewDemo */; 292 | targetProxy = D1A750F517D3136C00159617 /* PBXContainerItemProxy */; 293 | }; 294 | /* End PBXTargetDependency section */ 295 | 296 | /* Begin PBXVariantGroup section */ 297 | D1A750D817D3136C00159617 /* InfoPlist.strings */ = { 298 | isa = PBXVariantGroup; 299 | children = ( 300 | D1A750D917D3136C00159617 /* en */, 301 | ); 302 | name = InfoPlist.strings; 303 | sourceTree = ""; 304 | }; 305 | D1A750E117D3136C00159617 /* Main_iPhone.storyboard */ = { 306 | isa = PBXVariantGroup; 307 | children = ( 308 | D1A750E217D3136C00159617 /* Base */, 309 | ); 310 | name = Main_iPhone.storyboard; 311 | sourceTree = ""; 312 | }; 313 | D1A750FA17D3136C00159617 /* InfoPlist.strings */ = { 314 | isa = PBXVariantGroup; 315 | children = ( 316 | D1A750FB17D3136C00159617 /* en */, 317 | ); 318 | name = InfoPlist.strings; 319 | sourceTree = ""; 320 | }; 321 | /* End PBXVariantGroup section */ 322 | 323 | /* Begin XCBuildConfiguration section */ 324 | D1A750FF17D3136C00159617 /* Debug */ = { 325 | isa = XCBuildConfiguration; 326 | buildSettings = { 327 | ALWAYS_SEARCH_USER_PATHS = NO; 328 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 329 | CLANG_CXX_LIBRARY = "libc++"; 330 | CLANG_ENABLE_MODULES = YES; 331 | CLANG_ENABLE_OBJC_ARC = YES; 332 | CLANG_WARN_BOOL_CONVERSION = YES; 333 | CLANG_WARN_CONSTANT_CONVERSION = YES; 334 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 335 | CLANG_WARN_EMPTY_BODY = YES; 336 | CLANG_WARN_ENUM_CONVERSION = YES; 337 | CLANG_WARN_INT_CONVERSION = YES; 338 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 339 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 340 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 341 | COPY_PHASE_STRIP = NO; 342 | GCC_C_LANGUAGE_STANDARD = gnu99; 343 | GCC_DYNAMIC_NO_PIC = NO; 344 | GCC_OPTIMIZATION_LEVEL = 0; 345 | GCC_PREPROCESSOR_DEFINITIONS = ( 346 | "DEBUG=1", 347 | "$(inherited)", 348 | ); 349 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 350 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 351 | GCC_WARN_UNDECLARED_SELECTOR = YES; 352 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 353 | GCC_WARN_UNUSED_FUNCTION = YES; 354 | GCC_WARN_UNUSED_VARIABLE = YES; 355 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 356 | ONLY_ACTIVE_ARCH = YES; 357 | SDKROOT = iphoneos; 358 | TARGETED_DEVICE_FAMILY = "1,2"; 359 | }; 360 | name = Debug; 361 | }; 362 | D1A7510017D3136C00159617 /* Release */ = { 363 | isa = XCBuildConfiguration; 364 | buildSettings = { 365 | ALWAYS_SEARCH_USER_PATHS = NO; 366 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 367 | CLANG_CXX_LIBRARY = "libc++"; 368 | CLANG_ENABLE_MODULES = YES; 369 | CLANG_ENABLE_OBJC_ARC = YES; 370 | CLANG_WARN_BOOL_CONVERSION = YES; 371 | CLANG_WARN_CONSTANT_CONVERSION = YES; 372 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 373 | CLANG_WARN_EMPTY_BODY = YES; 374 | CLANG_WARN_ENUM_CONVERSION = YES; 375 | CLANG_WARN_INT_CONVERSION = YES; 376 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 377 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 378 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 379 | COPY_PHASE_STRIP = YES; 380 | ENABLE_NS_ASSERTIONS = NO; 381 | GCC_C_LANGUAGE_STANDARD = gnu99; 382 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 383 | GCC_WARN_UNDECLARED_SELECTOR = YES; 384 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 385 | GCC_WARN_UNUSED_FUNCTION = YES; 386 | GCC_WARN_UNUSED_VARIABLE = YES; 387 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 388 | SDKROOT = iphoneos; 389 | TARGETED_DEVICE_FAMILY = "1,2"; 390 | VALIDATE_PRODUCT = YES; 391 | }; 392 | name = Release; 393 | }; 394 | D1A7510217D3136C00159617 /* Debug */ = { 395 | isa = XCBuildConfiguration; 396 | buildSettings = { 397 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 398 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 399 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 400 | GCC_PREFIX_HEADER = "VVSpringCollectionViewDemo/VVSpringCollectionViewDemo-Prefix.pch"; 401 | INFOPLIST_FILE = "VVSpringCollectionViewDemo/VVSpringCollectionViewDemo-Info.plist"; 402 | PRODUCT_NAME = "$(TARGET_NAME)"; 403 | TARGETED_DEVICE_FAMILY = 1; 404 | WRAPPER_EXTENSION = app; 405 | }; 406 | name = Debug; 407 | }; 408 | D1A7510317D3136C00159617 /* Release */ = { 409 | isa = XCBuildConfiguration; 410 | buildSettings = { 411 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 412 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 413 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 414 | GCC_PREFIX_HEADER = "VVSpringCollectionViewDemo/VVSpringCollectionViewDemo-Prefix.pch"; 415 | INFOPLIST_FILE = "VVSpringCollectionViewDemo/VVSpringCollectionViewDemo-Info.plist"; 416 | PRODUCT_NAME = "$(TARGET_NAME)"; 417 | TARGETED_DEVICE_FAMILY = 1; 418 | WRAPPER_EXTENSION = app; 419 | }; 420 | name = Release; 421 | }; 422 | D1A7510517D3136C00159617 /* Debug */ = { 423 | isa = XCBuildConfiguration; 424 | buildSettings = { 425 | BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/VVSpringCollectionViewDemo.app/VVSpringCollectionViewDemo"; 426 | FRAMEWORK_SEARCH_PATHS = ( 427 | "$(SDKROOT)/Developer/Library/Frameworks", 428 | "$(inherited)", 429 | "$(DEVELOPER_FRAMEWORKS_DIR)", 430 | ); 431 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 432 | GCC_PREFIX_HEADER = "VVSpringCollectionViewDemo/VVSpringCollectionViewDemo-Prefix.pch"; 433 | GCC_PREPROCESSOR_DEFINITIONS = ( 434 | "DEBUG=1", 435 | "$(inherited)", 436 | ); 437 | INFOPLIST_FILE = "VVSpringCollectionViewDemoTests/VVSpringCollectionViewDemoTests-Info.plist"; 438 | PRODUCT_NAME = "$(TARGET_NAME)"; 439 | TEST_HOST = "$(BUNDLE_LOADER)"; 440 | WRAPPER_EXTENSION = xctest; 441 | }; 442 | name = Debug; 443 | }; 444 | D1A7510617D3136C00159617 /* Release */ = { 445 | isa = XCBuildConfiguration; 446 | buildSettings = { 447 | BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/VVSpringCollectionViewDemo.app/VVSpringCollectionViewDemo"; 448 | FRAMEWORK_SEARCH_PATHS = ( 449 | "$(SDKROOT)/Developer/Library/Frameworks", 450 | "$(inherited)", 451 | "$(DEVELOPER_FRAMEWORKS_DIR)", 452 | ); 453 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 454 | GCC_PREFIX_HEADER = "VVSpringCollectionViewDemo/VVSpringCollectionViewDemo-Prefix.pch"; 455 | INFOPLIST_FILE = "VVSpringCollectionViewDemoTests/VVSpringCollectionViewDemoTests-Info.plist"; 456 | PRODUCT_NAME = "$(TARGET_NAME)"; 457 | TEST_HOST = "$(BUNDLE_LOADER)"; 458 | WRAPPER_EXTENSION = xctest; 459 | }; 460 | name = Release; 461 | }; 462 | /* End XCBuildConfiguration section */ 463 | 464 | /* Begin XCConfigurationList section */ 465 | D1A750C717D3136C00159617 /* Build configuration list for PBXProject "VVSpringCollectionViewDemo" */ = { 466 | isa = XCConfigurationList; 467 | buildConfigurations = ( 468 | D1A750FF17D3136C00159617 /* Debug */, 469 | D1A7510017D3136C00159617 /* Release */, 470 | ); 471 | defaultConfigurationIsVisible = 0; 472 | defaultConfigurationName = Release; 473 | }; 474 | D1A7510117D3136C00159617 /* Build configuration list for PBXNativeTarget "VVSpringCollectionViewDemo" */ = { 475 | isa = XCConfigurationList; 476 | buildConfigurations = ( 477 | D1A7510217D3136C00159617 /* Debug */, 478 | D1A7510317D3136C00159617 /* Release */, 479 | ); 480 | defaultConfigurationIsVisible = 0; 481 | defaultConfigurationName = Release; 482 | }; 483 | D1A7510417D3136C00159617 /* Build configuration list for PBXNativeTarget "VVSpringCollectionViewDemoTests" */ = { 484 | isa = XCConfigurationList; 485 | buildConfigurations = ( 486 | D1A7510517D3136C00159617 /* Debug */, 487 | D1A7510617D3136C00159617 /* Release */, 488 | ); 489 | defaultConfigurationIsVisible = 0; 490 | defaultConfigurationName = Release; 491 | }; 492 | /* End XCConfigurationList section */ 493 | }; 494 | rootObject = D1A750C417D3136C00159617 /* Project object */; 495 | } 496 | -------------------------------------------------------------------------------- /VVSpringCollectionViewDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // VVSpringCollectionViewDemo 4 | // 5 | // Created by 王 巍 on 13-9-1. 6 | // Copyright (c) 2013年 王 巍. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /VVSpringCollectionViewDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // VVSpringCollectionViewDemo 4 | // 5 | // Created by 王 巍 on 13-9-1. 6 | // Copyright (c) 2013年 王 巍. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @implementation AppDelegate 12 | 13 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 14 | { 15 | // Override point for customization after application launch. 16 | return YES; 17 | } 18 | 19 | - (void)applicationWillResignActive:(UIApplication *)application 20 | { 21 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 22 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 23 | } 24 | 25 | - (void)applicationDidEnterBackground:(UIApplication *)application 26 | { 27 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 28 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 29 | } 30 | 31 | - (void)applicationWillEnterForeground:(UIApplication *)application 32 | { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | - (void)applicationDidBecomeActive:(UIApplication *)application 37 | { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application 42 | { 43 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /VVSpringCollectionViewDemo/Base.lproj/Main_iPhone.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 | 40 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 63 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 83 | 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 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /VVSpringCollectionViewDemo/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "40x40", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "60x60", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "ipad", 20 | "size" : "29x29", 21 | "scale" : "1x" 22 | }, 23 | { 24 | "idiom" : "ipad", 25 | "size" : "29x29", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "ipad", 30 | "size" : "40x40", 31 | "scale" : "1x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "40x40", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "76x76", 41 | "scale" : "1x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "76x76", 46 | "scale" : "2x" 47 | } 48 | ], 49 | "info" : { 50 | "version" : 1, 51 | "author" : "xcode" 52 | } 53 | } -------------------------------------------------------------------------------- /VVSpringCollectionViewDemo/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 | "orientation" : "portrait", 20 | "idiom" : "ipad", 21 | "extent" : "full-screen", 22 | "minimum-system-version" : "7.0", 23 | "scale" : "1x" 24 | }, 25 | { 26 | "orientation" : "landscape", 27 | "idiom" : "ipad", 28 | "extent" : "full-screen", 29 | "minimum-system-version" : "7.0", 30 | "scale" : "1x" 31 | }, 32 | { 33 | "orientation" : "portrait", 34 | "idiom" : "ipad", 35 | "extent" : "full-screen", 36 | "minimum-system-version" : "7.0", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "orientation" : "landscape", 41 | "idiom" : "ipad", 42 | "extent" : "full-screen", 43 | "minimum-system-version" : "7.0", 44 | "scale" : "2x" 45 | } 46 | ], 47 | "info" : { 48 | "version" : 1, 49 | "author" : "xcode" 50 | } 51 | } -------------------------------------------------------------------------------- /VVSpringCollectionViewDemo/UIColor+VVRandomColor.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIColor+VVRandomColor.h 3 | // VVSpringCollectionViewDemo 4 | // 5 | // Created by 王 巍 on 13-9-1. 6 | // Copyright (c) 2013年 王 巍. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIColor (VVRandomColor) 12 | +(UIColor *) randomColor; 13 | @end 14 | -------------------------------------------------------------------------------- /VVSpringCollectionViewDemo/UIColor+VVRandomColor.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIColor+VVRandomColor.m 3 | // VVSpringCollectionViewDemo 4 | // 5 | // Created by 王 巍 on 13-9-1. 6 | // Copyright (c) 2013年 王 巍. All rights reserved. 7 | // 8 | 9 | #import "UIColor+VVRandomColor.h" 10 | 11 | @implementation UIColor (VVRandomColor) 12 | +(UIColor *) randomColor 13 | { 14 | CGFloat hue = ( arc4random() % 256 / 256.0 ); // 0.0 to 1.0 15 | CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from white 16 | CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from black 17 | return [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1]; 18 | } 19 | @end 20 | -------------------------------------------------------------------------------- /VVSpringCollectionViewDemo/VVSpringCollectionViewDemo-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | com.onevcat.${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 | Main_iPhone 29 | UIMainStoryboardFile~ipad 30 | Main_iPad 31 | UIRequiredDeviceCapabilities 32 | 33 | armv7 34 | 35 | UIStatusBarHidden 36 | 37 | UISupportedInterfaceOrientations 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationLandscapeLeft 41 | UIInterfaceOrientationLandscapeRight 42 | 43 | UISupportedInterfaceOrientations~ipad 44 | 45 | UIInterfaceOrientationPortrait 46 | UIInterfaceOrientationPortraitUpsideDown 47 | UIInterfaceOrientationLandscapeLeft 48 | UIInterfaceOrientationLandscapeRight 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /VVSpringCollectionViewDemo/VVSpringCollectionViewDemo-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_5_0 10 | #warning "This project uses features only available in iOS SDK 5.0 and later." 11 | #endif 12 | 13 | #ifdef __OBJC__ 14 | #import 15 | #import 16 | #endif 17 | -------------------------------------------------------------------------------- /VVSpringCollectionViewDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // VVSpringCollectionViewDemo 4 | // 5 | // Created by 王 巍 on 13-9-1. 6 | // Copyright (c) 2013年 王 巍. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /VVSpringCollectionViewDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // VVSpringCollectionViewDemo 4 | // 5 | // Created by 王 巍 on 13-9-1. 6 | // Copyright (c) 2013年 王 巍. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "VVSpringCollectionViewFlowLayout.h" 11 | #import "UIColor+VVRandomColor.h" 12 | 13 | @interface ViewController () 14 | @property (nonatomic, strong) VVSpringCollectionViewFlowLayout *layout; 15 | 16 | @property (weak, nonatomic) IBOutlet UILabel *lblDamping; 17 | @property (weak, nonatomic) IBOutlet UILabel *lblFreq; 18 | @property (weak, nonatomic) IBOutlet UILabel *lblResist; 19 | 20 | @property (weak, nonatomic) IBOutlet UISlider *sliderDamping; 21 | @property (weak, nonatomic) IBOutlet UISlider *sliderFreq; 22 | @property (weak, nonatomic) IBOutlet UISlider *sliderResist; 23 | 24 | @end 25 | 26 | static NSString *reuseId = @"collectionViewCellReuseId"; 27 | 28 | @implementation ViewController 29 | 30 | - (void)viewDidLoad 31 | { 32 | [super viewDidLoad]; 33 | // Do any additional setup after loading the view, typically from a nib. 34 | 35 | self.layout = [[VVSpringCollectionViewFlowLayout alloc] init]; 36 | self.layout.itemSize = CGSizeMake(self.view.frame.size.width, 44); 37 | UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:self.layout]; 38 | collectionView.backgroundColor = [UIColor clearColor]; 39 | 40 | [collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseId]; 41 | 42 | collectionView.dataSource = self; 43 | [self.view insertSubview:collectionView atIndex:0]; 44 | 45 | [self updateLabelNumber]; 46 | } 47 | 48 | - (void)didReceiveMemoryWarning 49 | { 50 | [super didReceiveMemoryWarning]; 51 | // Dispose of any resources that can be recreated. 52 | } 53 | 54 | #pragma mark - UICollectionViewDataSource 55 | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section 56 | { 57 | return 50; 58 | } 59 | 60 | - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 61 | { 62 | UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseId forIndexPath:indexPath]; 63 | cell.contentView.backgroundColor = [UIColor randomColor]; 64 | return cell; 65 | } 66 | 67 | #pragma mark - UI 68 | - (IBAction)dampingValueChanged:(id)sender { 69 | [self.layout setSpringDamping:[(UISlider *)sender value]]; 70 | [self updateLabelNumber]; 71 | } 72 | 73 | - (IBAction)freqValueChanged:(id)sender { 74 | [self.layout setSpringFrequency:[(UISlider *)sender value]]; 75 | [self updateLabelNumber]; 76 | } 77 | 78 | - (IBAction)resistValueChanged:(id)sender { 79 | [self.layout setResistanceFactor:[(UISlider *)sender value]]; 80 | [self updateLabelNumber]; 81 | } 82 | 83 | - (void) updateLabelNumber { 84 | self.lblDamping.text = [NSString stringWithFormat:@"%.1f",self.sliderDamping.value]; 85 | self.lblFreq.text = [NSString stringWithFormat:@"%.1f",self.sliderFreq.value]; 86 | self.lblResist.text = [NSString stringWithFormat:@"%d",(int)self.sliderResist.value]; 87 | } 88 | @end 89 | -------------------------------------------------------------------------------- /VVSpringCollectionViewDemo/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /VVSpringCollectionViewDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // VVSpringCollectionViewDemo 4 | // 5 | // Created by 王 巍 on 13-9-1. 6 | // Copyright (c) 2013年 王 巍. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "AppDelegate.h" 12 | 13 | int main(int argc, char * argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /VVSpringCollectionViewDemoTests/VVSpringCollectionViewDemoTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | com.onevcat.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /VVSpringCollectionViewDemoTests/VVSpringCollectionViewDemoTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // VVSpringCollectionViewDemoTests.m 3 | // VVSpringCollectionViewDemoTests 4 | // 5 | // Created by 王 巍 on 13-9-1. 6 | // Copyright (c) 2013年 王 巍. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface VVSpringCollectionViewDemoTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation VVSpringCollectionViewDemoTests 16 | 17 | - (void)setUp 18 | { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown 24 | { 25 | // Put teardown code here. This method is called after the invocation of each test method in the class. 26 | [super tearDown]; 27 | } 28 | 29 | - (void)testExample 30 | { 31 | XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__); 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /VVSpringCollectionViewDemoTests/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /VVSpringCollectionViewFlowLayout/VVSpringCollectionViewFlowLayout.h: -------------------------------------------------------------------------------- 1 | // 2 | // VVSpringCollectionViewFlowLayout.h 3 | // VVSpringCollectionViewDemo 4 | // 5 | // Created by 王 巍 on 13-9-1. 6 | // Copyright (c) 2013年 王 巍. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface VVSpringCollectionViewFlowLayout : UICollectionViewFlowLayout 12 | @property (nonatomic, assign) CGFloat springDamping; 13 | @property (nonatomic, assign) CGFloat springFrequency; 14 | @property (nonatomic, assign) CGFloat resistanceFactor; 15 | @end 16 | -------------------------------------------------------------------------------- /VVSpringCollectionViewFlowLayout/VVSpringCollectionViewFlowLayout.m: -------------------------------------------------------------------------------- 1 | // 2 | // VVSpringCollectionViewFlowLayout.m 3 | // VVSpringCollectionViewDemo 4 | // 5 | // Created by 王 巍 on 13-9-1. 6 | // Copyright (c) 2013年 王 巍. All rights reserved. 7 | // 8 | 9 | #import "VVSpringCollectionViewFlowLayout.h" 10 | 11 | @interface VVSpringCollectionViewFlowLayout() 12 | @property (nonatomic, strong) UIDynamicAnimator *animator; 13 | @end 14 | 15 | @implementation VVSpringCollectionViewFlowLayout 16 | 17 | -(id)init { 18 | if ([super init]) { 19 | _springDamping = 0.5; 20 | _springFrequency = 0.8; 21 | _resistanceFactor = 500; 22 | } 23 | return self; 24 | } 25 | 26 | -(void)setSpringDamping:(CGFloat)springDamping { 27 | if (springDamping >= 0 && _springDamping != springDamping) { 28 | _springDamping = springDamping; 29 | for (UIAttachmentBehavior *spring in _animator.behaviors) { 30 | spring.damping = _springDamping; 31 | } 32 | } 33 | } 34 | 35 | -(void)setSpringFrequency:(CGFloat)springFrequency { 36 | if (springFrequency >= 0 && _springFrequency != springFrequency) { 37 | _springFrequency = springFrequency; 38 | for (UIAttachmentBehavior *spring in _animator.behaviors) { 39 | spring.frequency = _springFrequency; 40 | } 41 | } 42 | } 43 | 44 | -(void)prepareLayout { 45 | [super prepareLayout]; 46 | 47 | if (!_animator) { 48 | _animator = [[UIDynamicAnimator alloc] initWithCollectionViewLayout:self]; 49 | CGSize contentSize = [self collectionViewContentSize]; 50 | NSArray *items = [super layoutAttributesForElementsInRect:CGRectMake(0, 0, contentSize.width, contentSize.height)]; 51 | 52 | for (UICollectionViewLayoutAttributes *item in items) { 53 | UIAttachmentBehavior *spring = [[UIAttachmentBehavior alloc] initWithItem:item attachedToAnchor:item.center]; 54 | 55 | spring.length = 0; 56 | spring.damping = self.springDamping; 57 | spring.frequency = self.springFrequency; 58 | 59 | [_animator addBehavior:spring]; 60 | } 61 | } 62 | } 63 | 64 | -(NSArray *)layoutAttributesForElementsInRect:(CGRect)rect { 65 | return [_animator itemsInRect:rect]; 66 | } 67 | 68 | - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath { 69 | return [_animator layoutAttributesForCellAtIndexPath:indexPath]; 70 | } 71 | 72 | -(BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds { 73 | UIScrollView *scrollView = self.collectionView; 74 | CGFloat scrollDelta = newBounds.origin.y - scrollView.bounds.origin.y; 75 | CGPoint touchLocation = [scrollView.panGestureRecognizer locationInView:scrollView]; 76 | 77 | for (UIAttachmentBehavior *spring in _animator.behaviors) { 78 | CGPoint anchorPoint = spring.anchorPoint; 79 | CGFloat distanceFromTouch = fabsf(touchLocation.y - anchorPoint.y); 80 | CGFloat scrollResistance = distanceFromTouch / self.resistanceFactor; 81 | 82 | UICollectionViewLayoutAttributes *item = [spring.items firstObject]; 83 | CGPoint center = item.center; 84 | center.y += (scrollDelta > 0) ? MIN(scrollDelta, scrollDelta * scrollResistance) 85 | : MAX(scrollDelta, scrollDelta * scrollResistance); 86 | item.center = center; 87 | 88 | [_animator updateItemUsingCurrentState:item]; 89 | } 90 | return NO; 91 | } 92 | 93 | @end 94 | -------------------------------------------------------------------------------- /spring-collection-view-over-ios7.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onevcat/VVSpringCollectionViewFlowLayout/ea2c6ac1dc98dc22d44bf23a9e64b52ed41c8a03/spring-collection-view-over-ios7.gif --------------------------------------------------------------------------------