├── .gitignore ├── LICENSE ├── README.md ├── StackView.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── StackView ├── AppDelegate.h ├── AppDelegate.m ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard ├── CollectionViewCell │ ├── CardCell.h │ └── CardCell.m ├── Images.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── LaunchImage.launchimage │ │ └── Contents.json ├── Info.plist ├── StackedCollectionVIew │ ├── JGStackedCollectionView.h │ ├── JGStackedCollectionView.m │ └── Layouts │ │ ├── JGCardLayout.h │ │ ├── JGCardLayout.m │ │ ├── JGStackedLayout.h │ │ └── JGStackedLayout.m ├── ViewController.h ├── ViewController.m ├── main.m └── mainImage.png └── StackViewTests ├── Info.plist └── StackViewTests.m /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | build/* 3 | *.pbxuser 4 | !default.pbxuser 5 | *.mode1v3 6 | !default.mode1v3 7 | *.mode2v3 8 | !default.mode2v3 9 | *.perspectivev3 10 | !default.perspectivev3 11 | *.xcworkspace 12 | !default.xcworkspace 13 | xcuserdata 14 | profile 15 | *.moved-aside 16 | DerivedData 17 | .DS_Store -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all 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, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | JGStackCollectionView 2 | ======================== 3 | 4 | A iOS safari like stack view made using UICollectionView. 5 | 6 | ![alt tag](https://github.com/JayGajjar/JGStackCollectionView/blob/master/StackView/mainImage.png) 7 | 8 | # Installation 9 | Copy all the files form StackedCollectionVIew folder. Assign class JGStackedCollectionView to UICollectionView from storyboard 10 | 11 | # Usage 12 | Simply use it as normal collection view by calling its delegate and datasource methods 13 | 14 | # Demo 15 | JGStackCollectionView includes a sample project and revelent classes. 16 | 17 | # Compatibility 18 | - This project uses ARC. 19 | - This project was tested with iOS 7 & 8. 20 | 21 | # License 22 | JGStackCollectionView is available under the MIT license. See the [LICENSE](LICENSE) file for more info. 23 | -------------------------------------------------------------------------------- /StackView.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 6965C7331A77B85A00A04211 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 6965C7321A77B85A00A04211 /* main.m */; }; 11 | 6965C7361A77B85A00A04211 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6965C7351A77B85A00A04211 /* AppDelegate.m */; }; 12 | 6965C7391A77B85A00A04211 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6965C7381A77B85A00A04211 /* ViewController.m */; }; 13 | 6965C73C1A77B85A00A04211 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6965C73A1A77B85A00A04211 /* Main.storyboard */; }; 14 | 6965C73E1A77B85A00A04211 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6965C73D1A77B85A00A04211 /* Images.xcassets */; }; 15 | 6965C7411A77B85A00A04211 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6965C73F1A77B85A00A04211 /* LaunchScreen.xib */; }; 16 | 6965C74D1A77B85A00A04211 /* StackViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6965C74C1A77B85A00A04211 /* StackViewTests.m */; }; 17 | 6965C75E1A77B8D400A04211 /* JGCardLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 6965C7591A77B8D400A04211 /* JGCardLayout.m */; }; 18 | 6965C75F1A77B8D400A04211 /* JGStackedLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 6965C75B1A77B8D400A04211 /* JGStackedLayout.m */; }; 19 | 6965C7601A77B8D400A04211 /* JGStackedCollectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = 6965C75D1A77B8D400A04211 /* JGStackedCollectionView.m */; }; 20 | 6965C7641A77B90D00A04211 /* CardCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 6965C7631A77B90D00A04211 /* CardCell.m */; }; 21 | 697130E01A78A96B0048F7AC /* mainImage.png in Resources */ = {isa = PBXBuildFile; fileRef = 697130DF1A78A96B0048F7AC /* mainImage.png */; }; 22 | /* End PBXBuildFile section */ 23 | 24 | /* Begin PBXContainerItemProxy section */ 25 | 6965C7471A77B85A00A04211 /* PBXContainerItemProxy */ = { 26 | isa = PBXContainerItemProxy; 27 | containerPortal = 6965C7251A77B85A00A04211 /* Project object */; 28 | proxyType = 1; 29 | remoteGlobalIDString = 6965C72C1A77B85A00A04211; 30 | remoteInfo = StackView; 31 | }; 32 | /* End PBXContainerItemProxy section */ 33 | 34 | /* Begin PBXFileReference section */ 35 | 6965C72D1A77B85A00A04211 /* StackView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = StackView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 36 | 6965C7311A77B85A00A04211 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 37 | 6965C7321A77B85A00A04211 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 38 | 6965C7341A77B85A00A04211 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 39 | 6965C7351A77B85A00A04211 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 40 | 6965C7371A77B85A00A04211 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 41 | 6965C7381A77B85A00A04211 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 42 | 6965C73B1A77B85A00A04211 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 43 | 6965C73D1A77B85A00A04211 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 44 | 6965C7401A77B85A00A04211 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 45 | 6965C7461A77B85A00A04211 /* StackViewTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = StackViewTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 46 | 6965C74B1A77B85A00A04211 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 47 | 6965C74C1A77B85A00A04211 /* StackViewTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = StackViewTests.m; sourceTree = ""; }; 48 | 6965C7581A77B8D400A04211 /* JGCardLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JGCardLayout.h; sourceTree = ""; }; 49 | 6965C7591A77B8D400A04211 /* JGCardLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JGCardLayout.m; sourceTree = ""; }; 50 | 6965C75A1A77B8D400A04211 /* JGStackedLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JGStackedLayout.h; sourceTree = ""; }; 51 | 6965C75B1A77B8D400A04211 /* JGStackedLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JGStackedLayout.m; sourceTree = ""; }; 52 | 6965C75C1A77B8D400A04211 /* JGStackedCollectionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JGStackedCollectionView.h; sourceTree = ""; }; 53 | 6965C75D1A77B8D400A04211 /* JGStackedCollectionView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JGStackedCollectionView.m; sourceTree = ""; }; 54 | 6965C7621A77B90D00A04211 /* CardCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CardCell.h; sourceTree = ""; }; 55 | 6965C7631A77B90D00A04211 /* CardCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CardCell.m; sourceTree = ""; }; 56 | 697130DF1A78A96B0048F7AC /* mainImage.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = mainImage.png; sourceTree = ""; }; 57 | /* End PBXFileReference section */ 58 | 59 | /* Begin PBXFrameworksBuildPhase section */ 60 | 6965C72A1A77B85A00A04211 /* Frameworks */ = { 61 | isa = PBXFrameworksBuildPhase; 62 | buildActionMask = 2147483647; 63 | files = ( 64 | ); 65 | runOnlyForDeploymentPostprocessing = 0; 66 | }; 67 | 6965C7431A77B85A00A04211 /* Frameworks */ = { 68 | isa = PBXFrameworksBuildPhase; 69 | buildActionMask = 2147483647; 70 | files = ( 71 | ); 72 | runOnlyForDeploymentPostprocessing = 0; 73 | }; 74 | /* End PBXFrameworksBuildPhase section */ 75 | 76 | /* Begin PBXGroup section */ 77 | 6965C7241A77B85A00A04211 = { 78 | isa = PBXGroup; 79 | children = ( 80 | 6965C72F1A77B85A00A04211 /* StackView */, 81 | 6965C7491A77B85A00A04211 /* StackViewTests */, 82 | 6965C72E1A77B85A00A04211 /* Products */, 83 | ); 84 | sourceTree = ""; 85 | }; 86 | 6965C72E1A77B85A00A04211 /* Products */ = { 87 | isa = PBXGroup; 88 | children = ( 89 | 6965C72D1A77B85A00A04211 /* StackView.app */, 90 | 6965C7461A77B85A00A04211 /* StackViewTests.xctest */, 91 | ); 92 | name = Products; 93 | sourceTree = ""; 94 | }; 95 | 6965C72F1A77B85A00A04211 /* StackView */ = { 96 | isa = PBXGroup; 97 | children = ( 98 | 697130DF1A78A96B0048F7AC /* mainImage.png */, 99 | 6965C7611A77B90D00A04211 /* CollectionViewCell */, 100 | 6965C7561A77B8D400A04211 /* JGStackedCollectionVIew */, 101 | 6965C7341A77B85A00A04211 /* AppDelegate.h */, 102 | 6965C7351A77B85A00A04211 /* AppDelegate.m */, 103 | 6965C7371A77B85A00A04211 /* ViewController.h */, 104 | 6965C7381A77B85A00A04211 /* ViewController.m */, 105 | 6965C73A1A77B85A00A04211 /* Main.storyboard */, 106 | 6965C73D1A77B85A00A04211 /* Images.xcassets */, 107 | 6965C73F1A77B85A00A04211 /* LaunchScreen.xib */, 108 | 6965C7301A77B85A00A04211 /* Supporting Files */, 109 | ); 110 | path = StackView; 111 | sourceTree = ""; 112 | }; 113 | 6965C7301A77B85A00A04211 /* Supporting Files */ = { 114 | isa = PBXGroup; 115 | children = ( 116 | 6965C7311A77B85A00A04211 /* Info.plist */, 117 | 6965C7321A77B85A00A04211 /* main.m */, 118 | ); 119 | name = "Supporting Files"; 120 | sourceTree = ""; 121 | }; 122 | 6965C7491A77B85A00A04211 /* StackViewTests */ = { 123 | isa = PBXGroup; 124 | children = ( 125 | 6965C74C1A77B85A00A04211 /* StackViewTests.m */, 126 | 6965C74A1A77B85A00A04211 /* Supporting Files */, 127 | ); 128 | path = StackViewTests; 129 | sourceTree = ""; 130 | }; 131 | 6965C74A1A77B85A00A04211 /* Supporting Files */ = { 132 | isa = PBXGroup; 133 | children = ( 134 | 6965C74B1A77B85A00A04211 /* Info.plist */, 135 | ); 136 | name = "Supporting Files"; 137 | sourceTree = ""; 138 | }; 139 | 6965C7561A77B8D400A04211 /* JGStackedCollectionVIew */ = { 140 | isa = PBXGroup; 141 | children = ( 142 | 6965C7571A77B8D400A04211 /* Layouts */, 143 | 6965C75C1A77B8D400A04211 /* JGStackedCollectionView.h */, 144 | 6965C75D1A77B8D400A04211 /* JGStackedCollectionView.m */, 145 | ); 146 | name = JGStackedCollectionVIew; 147 | path = StackedCollectionVIew; 148 | sourceTree = ""; 149 | }; 150 | 6965C7571A77B8D400A04211 /* Layouts */ = { 151 | isa = PBXGroup; 152 | children = ( 153 | 6965C7581A77B8D400A04211 /* JGCardLayout.h */, 154 | 6965C7591A77B8D400A04211 /* JGCardLayout.m */, 155 | 6965C75A1A77B8D400A04211 /* JGStackedLayout.h */, 156 | 6965C75B1A77B8D400A04211 /* JGStackedLayout.m */, 157 | ); 158 | path = Layouts; 159 | sourceTree = ""; 160 | }; 161 | 6965C7611A77B90D00A04211 /* CollectionViewCell */ = { 162 | isa = PBXGroup; 163 | children = ( 164 | 6965C7621A77B90D00A04211 /* CardCell.h */, 165 | 6965C7631A77B90D00A04211 /* CardCell.m */, 166 | ); 167 | path = CollectionViewCell; 168 | sourceTree = ""; 169 | }; 170 | /* End PBXGroup section */ 171 | 172 | /* Begin PBXNativeTarget section */ 173 | 6965C72C1A77B85A00A04211 /* StackView */ = { 174 | isa = PBXNativeTarget; 175 | buildConfigurationList = 6965C7501A77B85A00A04211 /* Build configuration list for PBXNativeTarget "StackView" */; 176 | buildPhases = ( 177 | 6965C7291A77B85A00A04211 /* Sources */, 178 | 6965C72A1A77B85A00A04211 /* Frameworks */, 179 | 6965C72B1A77B85A00A04211 /* Resources */, 180 | ); 181 | buildRules = ( 182 | ); 183 | dependencies = ( 184 | ); 185 | name = StackView; 186 | productName = StackView; 187 | productReference = 6965C72D1A77B85A00A04211 /* StackView.app */; 188 | productType = "com.apple.product-type.application"; 189 | }; 190 | 6965C7451A77B85A00A04211 /* StackViewTests */ = { 191 | isa = PBXNativeTarget; 192 | buildConfigurationList = 6965C7531A77B85A00A04211 /* Build configuration list for PBXNativeTarget "StackViewTests" */; 193 | buildPhases = ( 194 | 6965C7421A77B85A00A04211 /* Sources */, 195 | 6965C7431A77B85A00A04211 /* Frameworks */, 196 | 6965C7441A77B85A00A04211 /* Resources */, 197 | ); 198 | buildRules = ( 199 | ); 200 | dependencies = ( 201 | 6965C7481A77B85A00A04211 /* PBXTargetDependency */, 202 | ); 203 | name = StackViewTests; 204 | productName = StackViewTests; 205 | productReference = 6965C7461A77B85A00A04211 /* StackViewTests.xctest */; 206 | productType = "com.apple.product-type.bundle.unit-test"; 207 | }; 208 | /* End PBXNativeTarget section */ 209 | 210 | /* Begin PBXProject section */ 211 | 6965C7251A77B85A00A04211 /* Project object */ = { 212 | isa = PBXProject; 213 | attributes = { 214 | LastUpgradeCheck = 0610; 215 | ORGANIZATIONNAME = UltraSonic; 216 | TargetAttributes = { 217 | 6965C72C1A77B85A00A04211 = { 218 | CreatedOnToolsVersion = 6.1; 219 | }; 220 | 6965C7451A77B85A00A04211 = { 221 | CreatedOnToolsVersion = 6.1; 222 | TestTargetID = 6965C72C1A77B85A00A04211; 223 | }; 224 | }; 225 | }; 226 | buildConfigurationList = 6965C7281A77B85A00A04211 /* Build configuration list for PBXProject "StackView" */; 227 | compatibilityVersion = "Xcode 3.2"; 228 | developmentRegion = English; 229 | hasScannedForEncodings = 0; 230 | knownRegions = ( 231 | en, 232 | Base, 233 | ); 234 | mainGroup = 6965C7241A77B85A00A04211; 235 | productRefGroup = 6965C72E1A77B85A00A04211 /* Products */; 236 | projectDirPath = ""; 237 | projectRoot = ""; 238 | targets = ( 239 | 6965C72C1A77B85A00A04211 /* StackView */, 240 | 6965C7451A77B85A00A04211 /* StackViewTests */, 241 | ); 242 | }; 243 | /* End PBXProject section */ 244 | 245 | /* Begin PBXResourcesBuildPhase section */ 246 | 6965C72B1A77B85A00A04211 /* Resources */ = { 247 | isa = PBXResourcesBuildPhase; 248 | buildActionMask = 2147483647; 249 | files = ( 250 | 697130E01A78A96B0048F7AC /* mainImage.png in Resources */, 251 | 6965C73C1A77B85A00A04211 /* Main.storyboard in Resources */, 252 | 6965C7411A77B85A00A04211 /* LaunchScreen.xib in Resources */, 253 | 6965C73E1A77B85A00A04211 /* Images.xcassets in Resources */, 254 | ); 255 | runOnlyForDeploymentPostprocessing = 0; 256 | }; 257 | 6965C7441A77B85A00A04211 /* Resources */ = { 258 | isa = PBXResourcesBuildPhase; 259 | buildActionMask = 2147483647; 260 | files = ( 261 | ); 262 | runOnlyForDeploymentPostprocessing = 0; 263 | }; 264 | /* End PBXResourcesBuildPhase section */ 265 | 266 | /* Begin PBXSourcesBuildPhase section */ 267 | 6965C7291A77B85A00A04211 /* Sources */ = { 268 | isa = PBXSourcesBuildPhase; 269 | buildActionMask = 2147483647; 270 | files = ( 271 | 6965C7391A77B85A00A04211 /* ViewController.m in Sources */, 272 | 6965C7641A77B90D00A04211 /* CardCell.m in Sources */, 273 | 6965C7361A77B85A00A04211 /* AppDelegate.m in Sources */, 274 | 6965C7601A77B8D400A04211 /* JGStackedCollectionView.m in Sources */, 275 | 6965C75E1A77B8D400A04211 /* JGCardLayout.m in Sources */, 276 | 6965C75F1A77B8D400A04211 /* JGStackedLayout.m in Sources */, 277 | 6965C7331A77B85A00A04211 /* main.m in Sources */, 278 | ); 279 | runOnlyForDeploymentPostprocessing = 0; 280 | }; 281 | 6965C7421A77B85A00A04211 /* Sources */ = { 282 | isa = PBXSourcesBuildPhase; 283 | buildActionMask = 2147483647; 284 | files = ( 285 | 6965C74D1A77B85A00A04211 /* StackViewTests.m in Sources */, 286 | ); 287 | runOnlyForDeploymentPostprocessing = 0; 288 | }; 289 | /* End PBXSourcesBuildPhase section */ 290 | 291 | /* Begin PBXTargetDependency section */ 292 | 6965C7481A77B85A00A04211 /* PBXTargetDependency */ = { 293 | isa = PBXTargetDependency; 294 | target = 6965C72C1A77B85A00A04211 /* StackView */; 295 | targetProxy = 6965C7471A77B85A00A04211 /* PBXContainerItemProxy */; 296 | }; 297 | /* End PBXTargetDependency section */ 298 | 299 | /* Begin PBXVariantGroup section */ 300 | 6965C73A1A77B85A00A04211 /* Main.storyboard */ = { 301 | isa = PBXVariantGroup; 302 | children = ( 303 | 6965C73B1A77B85A00A04211 /* Base */, 304 | ); 305 | name = Main.storyboard; 306 | sourceTree = ""; 307 | }; 308 | 6965C73F1A77B85A00A04211 /* LaunchScreen.xib */ = { 309 | isa = PBXVariantGroup; 310 | children = ( 311 | 6965C7401A77B85A00A04211 /* Base */, 312 | ); 313 | name = LaunchScreen.xib; 314 | sourceTree = ""; 315 | }; 316 | /* End PBXVariantGroup section */ 317 | 318 | /* Begin XCBuildConfiguration section */ 319 | 6965C74E1A77B85A00A04211 /* Debug */ = { 320 | isa = XCBuildConfiguration; 321 | buildSettings = { 322 | ALWAYS_SEARCH_USER_PATHS = NO; 323 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 324 | CLANG_CXX_LIBRARY = "libc++"; 325 | CLANG_ENABLE_MODULES = YES; 326 | CLANG_ENABLE_OBJC_ARC = YES; 327 | CLANG_WARN_BOOL_CONVERSION = YES; 328 | CLANG_WARN_CONSTANT_CONVERSION = YES; 329 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 330 | CLANG_WARN_EMPTY_BODY = YES; 331 | CLANG_WARN_ENUM_CONVERSION = YES; 332 | CLANG_WARN_INT_CONVERSION = YES; 333 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 334 | CLANG_WARN_UNREACHABLE_CODE = YES; 335 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 336 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 337 | COPY_PHASE_STRIP = NO; 338 | ENABLE_STRICT_OBJC_MSGSEND = YES; 339 | GCC_C_LANGUAGE_STANDARD = gnu99; 340 | GCC_DYNAMIC_NO_PIC = NO; 341 | GCC_OPTIMIZATION_LEVEL = 0; 342 | GCC_PREPROCESSOR_DEFINITIONS = ( 343 | "DEBUG=1", 344 | "$(inherited)", 345 | ); 346 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 347 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 348 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 349 | GCC_WARN_UNDECLARED_SELECTOR = YES; 350 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 351 | GCC_WARN_UNUSED_FUNCTION = YES; 352 | GCC_WARN_UNUSED_VARIABLE = YES; 353 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 354 | MTL_ENABLE_DEBUG_INFO = YES; 355 | ONLY_ACTIVE_ARCH = YES; 356 | SDKROOT = iphoneos; 357 | }; 358 | name = Debug; 359 | }; 360 | 6965C74F1A77B85A00A04211 /* Release */ = { 361 | isa = XCBuildConfiguration; 362 | buildSettings = { 363 | ALWAYS_SEARCH_USER_PATHS = NO; 364 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 365 | CLANG_CXX_LIBRARY = "libc++"; 366 | CLANG_ENABLE_MODULES = YES; 367 | CLANG_ENABLE_OBJC_ARC = YES; 368 | CLANG_WARN_BOOL_CONVERSION = YES; 369 | CLANG_WARN_CONSTANT_CONVERSION = YES; 370 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 371 | CLANG_WARN_EMPTY_BODY = YES; 372 | CLANG_WARN_ENUM_CONVERSION = YES; 373 | CLANG_WARN_INT_CONVERSION = YES; 374 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 375 | CLANG_WARN_UNREACHABLE_CODE = YES; 376 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 377 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 378 | COPY_PHASE_STRIP = YES; 379 | ENABLE_NS_ASSERTIONS = NO; 380 | ENABLE_STRICT_OBJC_MSGSEND = YES; 381 | GCC_C_LANGUAGE_STANDARD = gnu99; 382 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 383 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 384 | GCC_WARN_UNDECLARED_SELECTOR = YES; 385 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 386 | GCC_WARN_UNUSED_FUNCTION = YES; 387 | GCC_WARN_UNUSED_VARIABLE = YES; 388 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 389 | MTL_ENABLE_DEBUG_INFO = NO; 390 | SDKROOT = iphoneos; 391 | VALIDATE_PRODUCT = YES; 392 | }; 393 | name = Release; 394 | }; 395 | 6965C7511A77B85A00A04211 /* Debug */ = { 396 | isa = XCBuildConfiguration; 397 | buildSettings = { 398 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 399 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 400 | INFOPLIST_FILE = StackView/Info.plist; 401 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 402 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 403 | PRODUCT_NAME = "$(TARGET_NAME)"; 404 | }; 405 | name = Debug; 406 | }; 407 | 6965C7521A77B85A00A04211 /* Release */ = { 408 | isa = XCBuildConfiguration; 409 | buildSettings = { 410 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 411 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 412 | INFOPLIST_FILE = StackView/Info.plist; 413 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 414 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 415 | PRODUCT_NAME = "$(TARGET_NAME)"; 416 | }; 417 | name = Release; 418 | }; 419 | 6965C7541A77B85A00A04211 /* Debug */ = { 420 | isa = XCBuildConfiguration; 421 | buildSettings = { 422 | BUNDLE_LOADER = "$(TEST_HOST)"; 423 | FRAMEWORK_SEARCH_PATHS = ( 424 | "$(SDKROOT)/Developer/Library/Frameworks", 425 | "$(inherited)", 426 | ); 427 | GCC_PREPROCESSOR_DEFINITIONS = ( 428 | "DEBUG=1", 429 | "$(inherited)", 430 | ); 431 | INFOPLIST_FILE = StackViewTests/Info.plist; 432 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 433 | PRODUCT_NAME = "$(TARGET_NAME)"; 434 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/StackView.app/StackView"; 435 | }; 436 | name = Debug; 437 | }; 438 | 6965C7551A77B85A00A04211 /* Release */ = { 439 | isa = XCBuildConfiguration; 440 | buildSettings = { 441 | BUNDLE_LOADER = "$(TEST_HOST)"; 442 | FRAMEWORK_SEARCH_PATHS = ( 443 | "$(SDKROOT)/Developer/Library/Frameworks", 444 | "$(inherited)", 445 | ); 446 | INFOPLIST_FILE = StackViewTests/Info.plist; 447 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 448 | PRODUCT_NAME = "$(TARGET_NAME)"; 449 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/StackView.app/StackView"; 450 | }; 451 | name = Release; 452 | }; 453 | /* End XCBuildConfiguration section */ 454 | 455 | /* Begin XCConfigurationList section */ 456 | 6965C7281A77B85A00A04211 /* Build configuration list for PBXProject "StackView" */ = { 457 | isa = XCConfigurationList; 458 | buildConfigurations = ( 459 | 6965C74E1A77B85A00A04211 /* Debug */, 460 | 6965C74F1A77B85A00A04211 /* Release */, 461 | ); 462 | defaultConfigurationIsVisible = 0; 463 | defaultConfigurationName = Release; 464 | }; 465 | 6965C7501A77B85A00A04211 /* Build configuration list for PBXNativeTarget "StackView" */ = { 466 | isa = XCConfigurationList; 467 | buildConfigurations = ( 468 | 6965C7511A77B85A00A04211 /* Debug */, 469 | 6965C7521A77B85A00A04211 /* Release */, 470 | ); 471 | defaultConfigurationIsVisible = 0; 472 | defaultConfigurationName = Release; 473 | }; 474 | 6965C7531A77B85A00A04211 /* Build configuration list for PBXNativeTarget "StackViewTests" */ = { 475 | isa = XCConfigurationList; 476 | buildConfigurations = ( 477 | 6965C7541A77B85A00A04211 /* Debug */, 478 | 6965C7551A77B85A00A04211 /* Release */, 479 | ); 480 | defaultConfigurationIsVisible = 0; 481 | defaultConfigurationName = Release; 482 | }; 483 | /* End XCConfigurationList section */ 484 | }; 485 | rootObject = 6965C7251A77B85A00A04211 /* Project object */; 486 | } 487 | -------------------------------------------------------------------------------- /StackView.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /StackView/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // StackView 4 | // 5 | // Created by Jay on 27/01/15. 6 | // Copyright (c) 2015 UltraSonic. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /StackView/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // StackView 4 | // 5 | // Created by Jay on 27/01/15. 6 | // Copyright (c) 2015 UltraSonic. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // 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. 25 | // 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. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // 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. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // 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. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 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 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /StackView/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /StackView/Base.lproj/Main.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 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 65 | 66 | 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 | -------------------------------------------------------------------------------- /StackView/CollectionViewCell/CardCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // CardCell.h 3 | // StackView 4 | // 5 | // Created by Jay on 20/01/15. 6 | // Copyright (c) 2015 ccc. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CardCell : UICollectionViewCell 12 | @property (weak, nonatomic) IBOutlet UILabel *title; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /StackView/CollectionViewCell/CardCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // CardCell.m 3 | // StackView 4 | // 5 | // Created by Jay on 20/01/15. 6 | // Copyright (c) 2015 ccc. All rights reserved. 7 | // 8 | 9 | #import "CardCell.h" 10 | 11 | @implementation CardCell 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /StackView/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" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /StackView/Images.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "iphone", 6 | "minimum-system-version" : "7.0", 7 | "scale" : "2x" 8 | }, 9 | { 10 | "orientation" : "portrait", 11 | "idiom" : "iphone", 12 | "minimum-system-version" : "7.0", 13 | "subtype" : "retina4", 14 | "scale" : "2x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /StackView/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /StackView/StackedCollectionVIew/JGStackedCollectionView.h: -------------------------------------------------------------------------------- 1 | // 2 | // JGStackedCollectionView.h 3 | // 4 | // Created by Jay on 27/01/15. 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #import 25 | 26 | @interface JGStackedCollectionView : UICollectionView 27 | 28 | @property (nonatomic,strong) id stackDelegate; 29 | @property (nonatomic,strong) id stackDataSource; 30 | 31 | @property (nonatomic,strong) NSMutableArray *collDataSource; 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /StackView/StackedCollectionVIew/JGStackedCollectionView.m: -------------------------------------------------------------------------------- 1 | // 2 | // JGStackedCollectionView.m 3 | // 4 | // Created by Jay on 27/01/15. 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | 25 | #import "JGStackedCollectionView.h" 26 | #import "JGCardLayout.h" 27 | #import "JGStackedLayout.h" 28 | 29 | @interface JGStackedCollectionView (){ 30 | UILongPressGestureRecognizer *longPressGesture; 31 | NSIndexPath *movingIndexPath; 32 | UIView *movingView; 33 | JGStackedLayout *stackedLayout; 34 | CGPoint initialPoint; 35 | // Delegate to respond back 36 | id stackDataSource; 37 | id stackDelegate; 38 | BOOL isScrolling; 39 | 40 | } 41 | 42 | @end 43 | 44 | @implementation JGStackedCollectionView 45 | 46 | /* 47 | // Only override drawRect: if you perform custom drawing. 48 | // An empty implementation adversely affects performance during animation. 49 | - (void)drawRect:(CGRect)rect { 50 | // Drawing code 51 | } 52 | */ 53 | 54 | -(id)initWithCoder:(NSCoder *)aDecoder{ 55 | if (self = [super initWithCoder:aDecoder]) { 56 | [self initVals]; 57 | } 58 | return self; 59 | } 60 | 61 | -(instancetype)init{ 62 | if (self = [super init]) { 63 | [self initVals]; 64 | } 65 | 66 | return self; 67 | } 68 | 69 | -(void)initVals{ 70 | stackedLayout = (JGStackedLayout *)self.collectionViewLayout; 71 | } 72 | 73 | 74 | #pragma mark - UICollectionView 75 | - (void)setDelegate:(id)delegate { 76 | // The order here is important, as there seem to be some observing done on setDelegate: 77 | if (delegate == self) { 78 | _stackDelegate = nil; 79 | } else { 80 | _stackDelegate = delegate; 81 | } 82 | [super setDelegate:self]; 83 | } 84 | 85 | - (id)delegate { 86 | return _stackDelegate; 87 | } 88 | 89 | - (void)setDataSource:(id)dataSource { 90 | // The order here is important, as there seem to be some observing done on setDelegate: 91 | if (dataSource == self) { 92 | _stackDataSource = nil; 93 | } else { 94 | _stackDataSource = dataSource; 95 | } 96 | [super setDataSource:self]; 97 | } 98 | 99 | - (id)dataSource { 100 | return _stackDataSource; 101 | } 102 | 103 | - (BOOL)respondsToSelector:(SEL)aSelector { 104 | return [super respondsToSelector:aSelector] || [_stackDelegate respondsToSelector:aSelector] || [_stackDataSource respondsToSelector:aSelector]; 105 | } 106 | 107 | - (void)forwardInvocation:(NSInvocation *)anInvocation { 108 | if ([_stackDelegate respondsToSelector:[anInvocation selector]]) { 109 | [anInvocation invokeWithTarget:_stackDelegate]; 110 | } else if ([_stackDataSource respondsToSelector:[anInvocation selector]]) { 111 | [anInvocation invokeWithTarget:_stackDataSource]; 112 | } else { 113 | [super forwardInvocation:anInvocation]; 114 | } 115 | } 116 | 117 | #pragma mark - UICollectionViewDataSource 118 | - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { 119 | UICollectionViewCell * cell = nil; 120 | if ([_stackDataSource respondsToSelector:@selector(collectionView:cellForItemAtIndexPath:)]) { 121 | cell = [_stackDataSource collectionView:collectionView cellForItemAtIndexPath:indexPath]; 122 | } 123 | 124 | longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)]; 125 | longPressGesture.delaysTouchesBegan = YES; 126 | longPressGesture.delaysTouchesEnded = YES; 127 | longPressGesture.allowableMovement = 50; 128 | //longPressGesture.delegate = self; 129 | [cell.contentView addGestureRecognizer:longPressGesture]; 130 | 131 | return cell; 132 | } 133 | 134 | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { 135 | return [_stackDataSource collectionView:collectionView numberOfItemsInSection:section]; 136 | } 137 | 138 | 139 | #pragma mark - Pan Gesture 140 | - (void)handleLongPress:(UILongPressGestureRecognizer *)recognizer{ 141 | static CGPoint startCenter; 142 | static CGPoint startLocation; 143 | 144 | CGPoint velocity = [recognizer locationInView:self]; 145 | double dx = velocity.x - initialPoint.x; 146 | 147 | //NSLog(@"Vel X: %f | W: %f",dx ,self.frame.size.width/3); 148 | if(dx > 0 || dx < 0) 149 | { 150 | 151 | switch (recognizer.state) { 152 | 153 | case UIGestureRecognizerStateBegan: { 154 | initialPoint = [recognizer locationInView:self]; // _initial is instance var of type CGPoint 155 | 156 | startLocation = [recognizer locationInView:self]; 157 | 158 | NSIndexPath *indexPath = [self indexPathForItemAtPoint:startLocation]; 159 | 160 | if (indexPath) { 161 | 162 | UICollectionViewCell *movingCell = [self cellForItemAtIndexPath:indexPath]; 163 | 164 | 165 | movingView = [[UIView alloc] initWithFrame:movingCell.frame]; 166 | 167 | startCenter = movingView.center; 168 | 169 | UIImageView *movingImageView = [[UIImageView alloc] initWithImage:[self screenshotImageOfItem:movingCell]]; 170 | 171 | movingImageView.alpha = 0.0f; 172 | 173 | [movingView addSubview:movingImageView]; 174 | 175 | UICollectionViewLayoutAttributes *movingCellAttributes = [self layoutAttributesForItemAtIndexPath:indexPath]; 176 | movingView.layer.transform = movingCellAttributes.transform3D; 177 | 178 | 179 | if (indexPath.row == [_stackDataSource collectionView:self numberOfItemsInSection:0]-1) { 180 | [self addSubview:movingView]; 181 | }else{ 182 | [self insertSubview:movingView belowSubview:movingCell]; 183 | } 184 | 185 | 186 | movingIndexPath = indexPath; 187 | movingImageView.alpha = 1.0f; 188 | 189 | stackedLayout.movingIndexPath = movingIndexPath; 190 | [stackedLayout invalidateLayout]; 191 | } 192 | 193 | break; 194 | } 195 | 196 | case UIGestureRecognizerStateChanged: { 197 | 198 | if (movingIndexPath) { 199 | 200 | CGPoint currentLocation = [recognizer locationInView:self]; 201 | CGPoint currentCenter = startCenter; 202 | 203 | //currentCenter.y += (currentLocation.y - startLocation.y); 204 | currentCenter.x += (currentLocation.x - startLocation.x); 205 | 206 | movingView.center = currentCenter; 207 | movingView.alpha = 1-fabs((currentLocation.x - startLocation.x)/self.frame.size.width); 208 | movingView.transform = CGAffineTransformMakeScale(1-fabs((currentLocation.x - startLocation.x)/self.frame.size.width), 1-fabs((currentLocation.x - startLocation.x)/self.frame.size.width)); 209 | 210 | UICollectionViewLayoutAttributes *movingCellAttributes = [self layoutAttributesForItemAtIndexPath:movingIndexPath]; 211 | movingView.layer.transform = movingCellAttributes.transform3D; 212 | 213 | } 214 | 215 | break; 216 | } 217 | 218 | case UIGestureRecognizerStateEnded: 219 | case UIGestureRecognizerStateCancelled: { 220 | 221 | CGPoint currentLocation = [recognizer locationInView:self]; 222 | 223 | if(dx > 0) 224 | { 225 | //NSLog(@"gesture went right"); 226 | if (currentLocation.x > self.frame.size.width/3) { 227 | [self removeItemAtIndexpath:movingIndexPath]; 228 | [self animateMovingViewInside:NO InDirectionLeft:NO]; 229 | }else{ 230 | [self animateMovingViewInside:YES InDirectionLeft:NO]; 231 | } 232 | } 233 | else 234 | { 235 | //NSLog(@"gesture went left"); 236 | if (currentLocation.x < self.frame.size.width/3) { 237 | [self removeItemAtIndexpath:movingIndexPath]; 238 | [self animateMovingViewInside:NO InDirectionLeft:YES]; 239 | }else{ 240 | [self animateMovingViewInside:YES InDirectionLeft:YES]; 241 | } 242 | } 243 | } 244 | 245 | default: 246 | { 247 | 248 | } 249 | break; 250 | } 251 | } 252 | } 253 | 254 | #pragma mark - Helpers 255 | - (UIImage *)screenshotImageOfItem:(UICollectionViewCell *)item { 256 | 257 | UIGraphicsBeginImageContextWithOptions(item.bounds.size, item.isOpaque, 0.0f); 258 | 259 | [item.layer renderInContext:UIGraphicsGetCurrentContext()]; 260 | 261 | UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 262 | 263 | UIGraphicsEndImageContext(); 264 | 265 | return image; 266 | } 267 | 268 | -(void)animateMovingViewInside:(BOOL)inside InDirectionLeft:(BOOL) isLeft{ 269 | CGFloat tx,ty; 270 | CGRect movingFrame; 271 | 272 | UICollectionViewLayoutAttributes *layoutAttributes = [stackedLayout layoutAttributesForItemAtIndexPath:movingIndexPath]; 273 | if (inside) { 274 | tx = 1.0f; 275 | ty = 1.0f; 276 | movingFrame = layoutAttributes.frame; 277 | }else{ 278 | tx = 0; 279 | ty = 0; 280 | if (isLeft) { 281 | movingFrame = CGRectMake(0, layoutAttributes.frame.origin.y, layoutAttributes.frame.size.width, layoutAttributes.frame.size.height); 282 | }else{ 283 | movingFrame = CGRectMake(self.frame.size.width, layoutAttributes.frame.origin.y, layoutAttributes.frame.size.width, layoutAttributes.frame.size.height); 284 | } 285 | } 286 | 287 | if (movingIndexPath) { 288 | movingIndexPath = nil; 289 | 290 | __weak typeof(self) weakSelf = self; 291 | 292 | [UIView animateWithDuration:0.3 293 | delay:0.0 294 | options:UIViewAnimationOptionBeginFromCurrentState 295 | animations:^ (void) { 296 | 297 | __strong typeof(self) strongSelf = weakSelf; 298 | 299 | if (strongSelf) { 300 | 301 | movingView.transform = CGAffineTransformMakeScale(tx, ty); 302 | movingView.frame = movingFrame; 303 | } 304 | } 305 | completion:^ (BOOL finished) { 306 | 307 | __strong typeof(self) strongSelf = weakSelf; 308 | 309 | if (strongSelf) { 310 | 311 | [movingView removeFromSuperview]; 312 | movingView = nil; 313 | 314 | stackedLayout.movingIndexPath = nil; 315 | [stackedLayout invalidateLayout]; 316 | } 317 | }]; 318 | } 319 | } 320 | 321 | #pragma mark - CollectionView CRUD 322 | -(void)insertItem{ 323 | [_collDataSource addObject:[NSString stringWithFormat:@"%lu",_collDataSource.count+1]]; 324 | [self insertItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:_collDataSource.count-1 inSection:0]]]; 325 | } 326 | 327 | -(void)removeItemAtIndexpath:(NSIndexPath *)index{ 328 | [_collDataSource removeObjectAtIndex:index.row]; 329 | [self deleteItemsAtIndexPaths:@[index]]; 330 | } 331 | 332 | #pragma mark - GestureRecognizerDelegate protocol 333 | 334 | -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{ 335 | if ([gestureRecognizer isEqual:longPressGesture] && isScrolling == NO) { 336 | return NO; 337 | } 338 | return YES; 339 | } 340 | -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{ 341 | return YES; 342 | } 343 | 344 | #pragma mark - UIScrollView Delegates 345 | -(void)scrollViewDidScroll:(UIScrollView *)scrollView{ 346 | isScrolling = YES; 347 | } 348 | 349 | -(void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{ 350 | isScrolling = NO; 351 | } 352 | 353 | -(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{ 354 | isScrolling = NO; 355 | } 356 | @end 357 | -------------------------------------------------------------------------------- /StackView/StackedCollectionVIew/Layouts/JGCardLayout.h: -------------------------------------------------------------------------------- 1 | // 2 | // JGCardLayout.h 3 | // 4 | // Created by Jay on 27/01/15. 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #import 25 | 26 | @interface JGCardLayout : UICollectionViewLayout 27 | 28 | @property (assign, nonatomic) UIEdgeInsets layoutMargin; 29 | @property (assign, nonatomic) CGSize itemSize; 30 | 31 | - (instancetype)initWithItemIndex:(NSInteger)itemIndex; 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /StackView/StackedCollectionVIew/Layouts/JGCardLayout.m: -------------------------------------------------------------------------------- 1 | // 2 | // JGCardLayout.m 3 | // 4 | // Created by Jay on 27/01/15. 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #import "JGCardLayout.h" 25 | 26 | @interface JGCardLayout () 27 | 28 | @property (assign, nonatomic) NSInteger itemIndex; 29 | 30 | @property (nonatomic, strong) NSDictionary *layoutAttributes; 31 | 32 | @end 33 | 34 | @implementation JGCardLayout 35 | 36 | - (instancetype)initWithItemIndex:(NSInteger)itemIndex { 37 | 38 | self = [super init]; 39 | 40 | if (self) { 41 | 42 | self.layoutMargin = UIEdgeInsetsMake(0, 0.0, 0.0, 0.0); 43 | self.itemIndex = itemIndex; 44 | } 45 | 46 | return self; 47 | } 48 | 49 | #pragma mark - Accessors 50 | 51 | - (void)setLayoutMargin:(UIEdgeInsets)margins { 52 | 53 | if (!UIEdgeInsetsEqualToEdgeInsets(margins, self.layoutMargin)) { 54 | 55 | _layoutMargin = margins; 56 | 57 | [self invalidateLayout]; 58 | } 59 | } 60 | 61 | - (void)setItemSize:(CGSize)itemSize { 62 | 63 | if (!CGSizeEqualToSize(itemSize, self.itemSize)) { 64 | 65 | _itemSize = itemSize; 66 | 67 | [self invalidateLayout]; 68 | } 69 | } 70 | 71 | #pragma mark - Layout computation 72 | 73 | - (CGSize)collectionViewContentSize { 74 | 75 | CGSize contentSize = self.collectionView.bounds.size; 76 | 77 | contentSize.height -= self.collectionView.contentInset.top + self.collectionView.contentInset.bottom; 78 | 79 | return contentSize; 80 | } 81 | 82 | - (void)prepareLayout { 83 | 84 | CGSize itemSize = self.itemSize; 85 | 86 | if (CGSizeEqualToSize(itemSize, CGSizeZero)) { 87 | 88 | itemSize = CGSizeMake(CGRectGetWidth(self.collectionView.bounds) - self.layoutMargin.left - self.layoutMargin.right, CGRectGetHeight(self.collectionView.bounds) - self.layoutMargin.top - self.layoutMargin.bottom - self.collectionView.contentInset.top - self.collectionView.contentInset.bottom); 89 | } 90 | 91 | NSMutableDictionary *layoutAttributes = [NSMutableDictionary dictionary]; 92 | NSInteger itemCount = [self.collectionView numberOfItemsInSection:0]; 93 | 94 | for (NSInteger item = 0; item < itemCount; item++) { 95 | 96 | NSIndexPath *indexPath = [NSIndexPath indexPathForItem:item inSection:0]; 97 | UICollectionViewLayoutAttributes *attributes = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath]; 98 | 99 | if (item < self.itemIndex) { 100 | attributes.frame = CGRectMake(self.layoutMargin.left, self.layoutMargin.top, itemSize.width, itemSize.height); 101 | if (item < self.itemIndex - 1) attributes.hidden = YES; 102 | 103 | } else if (item == self.itemIndex) { 104 | attributes.frame = CGRectMake(self.layoutMargin.left, self.layoutMargin.top, itemSize.width, itemSize.height); 105 | 106 | } else if (item > self.itemIndex + 1) { 107 | attributes.frame = CGRectMake(self.layoutMargin.left, self.collectionViewContentSize.height, itemSize.width, itemSize.height); 108 | attributes.hidden = YES; 109 | 110 | } else { 111 | NSInteger count = MIN(1, itemCount - self.itemIndex) - (item - self.itemIndex); 112 | attributes.frame = CGRectMake(self.layoutMargin.left, self.layoutMargin.top + itemSize.height - count , itemSize.width, itemSize.height); 113 | } 114 | 115 | attributes.zIndex = item; 116 | 117 | layoutAttributes[indexPath] = attributes; 118 | } 119 | 120 | self.layoutAttributes = layoutAttributes; 121 | } 122 | 123 | - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect { 124 | 125 | NSMutableArray *layoutAttributes = [NSMutableArray array]; 126 | 127 | [self.layoutAttributes enumerateKeysAndObjectsUsingBlock:^(NSIndexPath *indexPath, UICollectionViewLayoutAttributes *attributes, BOOL *stop) { 128 | 129 | if (CGRectIntersectsRect(rect, attributes.frame)) { 130 | 131 | [layoutAttributes addObject:attributes]; 132 | } 133 | }]; 134 | 135 | return layoutAttributes; 136 | } 137 | 138 | - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath { 139 | 140 | return self.layoutAttributes[indexPath]; 141 | } 142 | 143 | @end 144 | -------------------------------------------------------------------------------- /StackView/StackedCollectionVIew/Layouts/JGStackedLayout.h: -------------------------------------------------------------------------------- 1 | // 2 | // JGStackLayout.m 3 | // 4 | // Created by Jay on 27/01/15. 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #import 25 | 26 | @interface JGStackedLayout : UICollectionViewLayout 27 | 28 | @property (assign, nonatomic) UIEdgeInsets layoutMargin; 29 | @property (assign, nonatomic) CGSize itemSize; 30 | @property (assign, nonatomic) CGFloat topReveal; 31 | @property (assign, nonatomic) CGFloat bounceFactor; 32 | @property (assign, nonatomic) BOOL overwriteContentOffset; 33 | @property (assign, nonatomic) CGPoint contentOffset; 34 | @property (strong, nonatomic) NSIndexPath *movingIndexPath; 35 | @end 36 | -------------------------------------------------------------------------------- /StackView/StackedCollectionVIew/Layouts/JGStackedLayout.m: -------------------------------------------------------------------------------- 1 | // 2 | // JGStackLayout.m 3 | // 4 | // Created by Jay on 27/01/15. 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #import "JGStackedLayout.h" 25 | 26 | @interface JGStackedLayout () 27 | 28 | @property (nonatomic, strong) NSDictionary *layoutAttributes; 29 | 30 | @end 31 | 32 | @implementation JGStackedLayout 33 | @synthesize itemSize; 34 | - (instancetype)init { 35 | 36 | self = [super init]; 37 | 38 | if (self) [self initLayout]; 39 | 40 | return self; 41 | } 42 | 43 | - (instancetype)initWithCoder:(NSCoder *)aDecoder { 44 | 45 | self = [super initWithCoder:aDecoder]; 46 | 47 | if (self) [self initLayout]; 48 | 49 | return self; 50 | } 51 | 52 | - (void)initLayout { 53 | 54 | self.layoutMargin = UIEdgeInsetsMake(20.0, 20.0, 20.0, 20.0); 55 | self.topReveal = 120; 56 | self.bounceFactor = 0.2; 57 | } 58 | 59 | #pragma mark - Accessors 60 | 61 | - (void)setLayoutMargin:(UIEdgeInsets)margins { 62 | 63 | if (!UIEdgeInsetsEqualToEdgeInsets(margins, self.layoutMargin)) { 64 | 65 | _layoutMargin = margins; 66 | 67 | [self invalidateLayout]; 68 | } 69 | } 70 | 71 | - (void)setTopReveal:(CGFloat)topReveal { 72 | 73 | if (topReveal != self.topReveal) { 74 | 75 | _topReveal = topReveal; 76 | 77 | [self invalidateLayout]; 78 | } 79 | } 80 | 81 | - (void)setItemSize:(CGSize)itemSizee { 82 | 83 | if (!CGSizeEqualToSize(itemSizee, self.itemSize)) { 84 | 85 | itemSize = itemSizee; 86 | 87 | [self invalidateLayout]; 88 | } 89 | } 90 | 91 | - (void)setBounceFactor:(CGFloat)bounceFactor { 92 | 93 | if (bounceFactor != self.bounceFactor) { 94 | 95 | _bounceFactor = bounceFactor; 96 | 97 | [self invalidateLayout]; 98 | } 99 | } 100 | 101 | #pragma mark - Layout computation 102 | 103 | - (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds { 104 | 105 | return YES; 106 | } 107 | 108 | - (CGSize)collectionViewContentSize { 109 | CGSize contentSize = CGSizeMake(CGRectGetWidth(self.collectionView.bounds), [self.collectionView numberOfItemsInSection:0]* CGRectGetHeight(self.collectionView.bounds) - self.layoutMargin.top - self.layoutMargin.bottom - self.collectionView.contentInset.top - self.collectionView.contentInset.bottom-200); 110 | 111 | contentSize = CGSizeMake(CGRectGetWidth(self.collectionView.bounds),2000); 112 | 113 | CGSize itemSizee = self.itemSize; 114 | 115 | if (CGSizeEqualToSize(itemSizee, CGSizeZero)) { 116 | 117 | itemSizee = CGSizeMake(CGRectGetWidth(self.collectionView.bounds) - self.layoutMargin.left - self.layoutMargin.right, CGRectGetHeight(self.collectionView.bounds) - self.layoutMargin.top - self.layoutMargin.bottom - self.collectionView.contentInset.top - self.collectionView.contentInset.bottom-200); 118 | } 119 | CGFloat itemReveal = self.topReveal; 120 | NSInteger itemCount = [self.collectionView numberOfItemsInSection:0]; 121 | contentSize = CGSizeMake(CGRectGetWidth(self.collectionView.bounds), ((self.layoutMargin.top - self.layoutMargin.bottom - self.collectionView.contentInset.top - self.collectionView.contentInset.bottom) + itemReveal * itemCount )); 122 | 123 | if (contentSize.height < CGRectGetHeight(self.collectionView.bounds)) { 124 | 125 | contentSize.height = CGRectGetHeight(self.collectionView.bounds) - self.collectionView.contentInset.top - self.collectionView.contentInset.bottom; 126 | 127 | // Adding an extra point of content height 128 | // enables scrolling/bouncing 129 | contentSize.height += 1.0; 130 | } 131 | return contentSize; 132 | } 133 | 134 | - (void)prepareLayout { 135 | [self collectionViewContentSize]; 136 | 137 | CGFloat itemReveal = self.topReveal; 138 | CGSize itemSizee = self.itemSize; 139 | 140 | if (CGSizeEqualToSize(itemSizee, CGSizeZero)) { 141 | 142 | itemSizee = CGSizeMake(CGRectGetWidth(self.collectionView.bounds) - self.layoutMargin.left - self.layoutMargin.right, CGRectGetHeight(self.collectionView.bounds) - self.layoutMargin.top - self.layoutMargin.bottom - self.collectionView.contentInset.top - self.collectionView.contentInset.bottom-200); 143 | } 144 | 145 | CGPoint contentOffset = self.overwriteContentOffset ? self.contentOffset : self.collectionView.contentOffset; 146 | 147 | self.overwriteContentOffset = NO; 148 | 149 | NSMutableDictionary *layoutAttributes = [NSMutableDictionary dictionary]; 150 | NSInteger itemCount = [self.collectionView numberOfItemsInSection:0]; 151 | 152 | for (NSInteger item = 0; item < itemCount; item++) { 153 | NSIndexPath *indexPath = [NSIndexPath indexPathForItem:item inSection:0]; 154 | UICollectionViewLayoutAttributes *attributes = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath]; 155 | 156 | // Cards overlap each other 157 | // via z depth 158 | // 159 | attributes.zIndex = item; 160 | 161 | // The moving item is hidden 162 | // 163 | attributes.hidden = [attributes.indexPath isEqual:self.movingIndexPath]; 164 | 165 | // By default all items are layed 166 | // out evenly with each revealing 167 | // only top part ... 168 | // 169 | attributes.frame = CGRectMake(self.layoutMargin.left, self.layoutMargin.top + itemReveal * item, itemSizee.width, itemSizee.height); 170 | 171 | NSLog(@"FRame : %@",NSStringFromCGRect(attributes.frame)); 172 | 173 | if (contentOffset.y + self.collectionView.contentInset.top < 0.0) { 174 | //if (item <= 4) 175 | { 176 | float y = (0.0009 * (contentOffset.y + self.collectionView.contentInset.top) * ((item <= 0)?1:item)) - 0.2; 177 | if (y > 1) { 178 | y = 1; 179 | } 180 | 181 | CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity; 182 | rotationAndPerspectiveTransform.m34 = 1.0 / -1000.0; 183 | rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, M_PI * y, 1.0f, 0.0f, 0.0f); 184 | attributes.transform3D = rotationAndPerspectiveTransform; 185 | } 186 | 187 | }else{ 188 | //if (item <= 4) 189 | { 190 | CGFloat y = -0.2; 191 | CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity; 192 | rotationAndPerspectiveTransform.m34 = 1.0 / -1000.0; 193 | rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, M_PI * y, 1.0f, 0.0f, 0.0f); 194 | attributes.transform3D = rotationAndPerspectiveTransform; 195 | } 196 | 197 | } 198 | layoutAttributes[indexPath] = attributes; 199 | } 200 | 201 | self.layoutAttributes = layoutAttributes; 202 | } 203 | 204 | - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect { 205 | NSMutableArray *layoutAttributes = [NSMutableArray array]; 206 | 207 | [self.layoutAttributes enumerateKeysAndObjectsUsingBlock:^(NSIndexPath *indexPath, UICollectionViewLayoutAttributes *attributes, BOOL *stop) { 208 | 209 | if (CGRectIntersectsRect(rect, attributes.frame)) { 210 | 211 | [layoutAttributes addObject:attributes]; 212 | } 213 | }]; 214 | 215 | return layoutAttributes; 216 | } 217 | 218 | - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath { 219 | 220 | return self.layoutAttributes[indexPath]; 221 | } 222 | @end 223 | -------------------------------------------------------------------------------- /StackView/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // StackView 4 | // 5 | // Created by Jay on 20/01/15. 6 | // Copyright (c) 2015 ccc. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "JGStackedCollectionView.h" 11 | 12 | @interface ViewController : UIViewController 13 | - (IBAction)addButtonAction:(id)sender; 14 | @property (weak, nonatomic) IBOutlet JGStackedCollectionView *collView; 15 | 16 | 17 | @end 18 | 19 | -------------------------------------------------------------------------------- /StackView/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // StackView 4 | // 5 | // Created by Jay on 20/01/15. 6 | // Copyright (c) 2015 ccc. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "CardCell.h" 11 | #import "JGStackedLayout.h" 12 | #import "JGCardLayout.h" 13 | 14 | #define MOVE_ZOOM 0.95 15 | 16 | 17 | @interface UIColor (randomColor) 18 | 19 | + (UIColor *)randomColor; 20 | 21 | @end 22 | 23 | @implementation UIColor (randomColor) 24 | 25 | + (UIColor *)randomColor { 26 | 27 | CGFloat comps[3]; 28 | 29 | for (int i = 0; i < 3; i++) { 30 | 31 | NSUInteger r = arc4random_uniform(256); 32 | comps[i] = (CGFloat)r/255.f; 33 | } 34 | 35 | return [UIColor colorWithRed:comps[0] green:comps[1] blue:comps[2] alpha:1.0]; 36 | } 37 | 38 | @end 39 | 40 | @interface ViewController (){ 41 | NSMutableArray *dataSource; 42 | JGStackedLayout *stackedLayout; 43 | } 44 | 45 | @end 46 | 47 | @implementation ViewController 48 | 49 | - (void)viewDidLoad { 50 | [super viewDidLoad]; 51 | // Do any additional setup after loading the view, typically from a nib. 52 | dataSource = [@[@"1",@"2",@"3",@"4",] mutableCopy]; 53 | stackedLayout = (JGStackedLayout *)self.collView.collectionViewLayout; 54 | self.collView.collDataSource = dataSource; 55 | } 56 | 57 | - (void)didReceiveMemoryWarning { 58 | [super didReceiveMemoryWarning]; 59 | // Dispose of any resources that can be recreated. 60 | } 61 | 62 | 63 | #pragma mark - UICollectionView Data Source Methods 64 | // Default is one 65 | - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView 66 | { 67 | return 1; 68 | } 69 | 70 | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section 71 | { 72 | return dataSource.count; 73 | } 74 | 75 | - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ 76 | // we're going to use a custom UICollectionViewCell, which will hold an image and its label 77 | // 78 | CardCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CardCell" forIndexPath:indexPath]; 79 | cell.title.text = [NSString stringWithFormat:@"Card : %@",dataSource[indexPath.row]]; 80 | cell.contentView.backgroundColor = [UIColor randomColor]; 81 | 82 | return cell; 83 | } 84 | 85 | -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ 86 | if ([collectionView.collectionViewLayout isKindOfClass:[JGStackedLayout class]]) { 87 | JGCardLayout *cardLayout = [[JGCardLayout alloc] initWithItemIndex:indexPath.item]; 88 | [self.collView setCollectionViewLayout:cardLayout animated:YES]; 89 | }else{ 90 | [self.collView setCollectionViewLayout:stackedLayout animated:YES]; 91 | } 92 | } 93 | 94 | - (IBAction)addButtonAction:(id)sender { 95 | [self insertItem]; 96 | } 97 | 98 | #pragma mark - CollectionView CRUD 99 | -(void)insertItem{ 100 | [dataSource addObject:[NSString stringWithFormat:@"%d",dataSource.count+1]]; 101 | [self.collView insertItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:dataSource.count-1 inSection:0]]]; 102 | } 103 | 104 | -(void)removeItemAtIndexpath:(NSIndexPath *)index{ 105 | [dataSource removeObjectAtIndex:index.row]; 106 | [self.collView deleteItemsAtIndexPaths:@[index]]; 107 | } 108 | @end 109 | -------------------------------------------------------------------------------- /StackView/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // StackView 4 | // 5 | // Created by Jay on 27/01/15. 6 | // Copyright (c) 2015 UltraSonic. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /StackView/mainImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JayGajjar/JGStackCollectionView/2ea593be67370aeae3c2fba5f301cccd24ce92c1/StackView/mainImage.png -------------------------------------------------------------------------------- /StackViewTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /StackViewTests/StackViewTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // StackViewTests.m 3 | // StackViewTests 4 | // 5 | // Created by Jay on 27/01/15. 6 | // Copyright (c) 2015 UltraSonic. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface StackViewTests : XCTestCase 13 | 14 | @end 15 | 16 | @implementation StackViewTests 17 | 18 | - (void)setUp { 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 | // Put teardown code here. This method is called after the invocation of each test method in the class. 25 | [super tearDown]; 26 | } 27 | 28 | - (void)testExample { 29 | // This is an example of a functional test case. 30 | XCTAssert(YES, @"Pass"); 31 | } 32 | 33 | - (void)testPerformanceExample { 34 | // This is an example of a performance test case. 35 | [self measureBlock:^{ 36 | // Put the code you want to measure the time of here. 37 | }]; 38 | } 39 | 40 | @end 41 | --------------------------------------------------------------------------------