├── .gitignore ├── CollectionViewSnapSample.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── CollectionViewSnapSample ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard ├── CSSAppDelegate.h ├── CSSAppDelegate.m ├── CSSCollectionViewCell.h ├── CSSCollectionViewCell.m ├── CSSCollectionViewController.h ├── CSSCollectionViewController.m ├── CSSCollectionViewFlowLayout.h ├── CSSCollectionViewFlowLayout.m ├── Images.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Info.plist └── main.m ├── CollectionViewSnapSampleTests ├── CollectionViewSnapSampleTests.m └── Info.plist ├── README.md └── preview.gif /.gitignore: -------------------------------------------------------------------------------- 1 | # OS X 2 | .DS_Store 3 | 4 | # Xcode 5 | build/ 6 | *.pbxuser 7 | !default.pbxuser 8 | *.mode1v3 9 | !default.mode1v3 10 | *.mode2v3 11 | !default.mode2v3 12 | *.perspectivev3 13 | !default.perspectivev3 14 | xcuserdata 15 | *.xccheckout 16 | profile 17 | *.moved-aside 18 | DerivedData 19 | *.hmap 20 | *.ipa 21 | 22 | # CocoaPods 23 | Pods 24 | 25 | # Documents 26 | docs -------------------------------------------------------------------------------- /CollectionViewSnapSample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | C93245681B95F5C600FC3E13 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = C93245671B95F5C600FC3E13 /* main.m */; }; 11 | C932456B1B95F5C600FC3E13 /* CSSAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = C932456A1B95F5C600FC3E13 /* CSSAppDelegate.m */; }; 12 | C93245711B95F5C600FC3E13 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C932456F1B95F5C600FC3E13 /* Main.storyboard */; }; 13 | C93245731B95F5C600FC3E13 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C93245721B95F5C600FC3E13 /* Images.xcassets */; }; 14 | C93245761B95F5C600FC3E13 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = C93245741B95F5C600FC3E13 /* LaunchScreen.xib */; }; 15 | C93245821B95F5C600FC3E13 /* CollectionViewSnapSampleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C93245811B95F5C600FC3E13 /* CollectionViewSnapSampleTests.m */; }; 16 | C932458D1B95F61100FC3E13 /* CSSCollectionViewFlowLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = C932458C1B95F61100FC3E13 /* CSSCollectionViewFlowLayout.m */; }; 17 | C93245901B95F65800FC3E13 /* CSSCollectionViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C932458F1B95F65800FC3E13 /* CSSCollectionViewController.m */; }; 18 | C93245931B95F95100FC3E13 /* CSSCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = C93245921B95F95100FC3E13 /* CSSCollectionViewCell.m */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXContainerItemProxy section */ 22 | C932457C1B95F5C600FC3E13 /* PBXContainerItemProxy */ = { 23 | isa = PBXContainerItemProxy; 24 | containerPortal = C932455A1B95F5C600FC3E13 /* Project object */; 25 | proxyType = 1; 26 | remoteGlobalIDString = C93245611B95F5C600FC3E13; 27 | remoteInfo = CollectionViewSnapSample; 28 | }; 29 | /* End PBXContainerItemProxy section */ 30 | 31 | /* Begin PBXFileReference section */ 32 | C93245621B95F5C600FC3E13 /* CollectionViewSnapSample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CollectionViewSnapSample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 33 | C93245661B95F5C600FC3E13 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 34 | C93245671B95F5C600FC3E13 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 35 | C93245691B95F5C600FC3E13 /* CSSAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CSSAppDelegate.h; sourceTree = ""; }; 36 | C932456A1B95F5C600FC3E13 /* CSSAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CSSAppDelegate.m; sourceTree = ""; }; 37 | C93245701B95F5C600FC3E13 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 38 | C93245721B95F5C600FC3E13 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 39 | C93245751B95F5C600FC3E13 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 40 | C932457B1B95F5C600FC3E13 /* CollectionViewSnapSampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CollectionViewSnapSampleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 41 | C93245801B95F5C600FC3E13 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 42 | C93245811B95F5C600FC3E13 /* CollectionViewSnapSampleTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CollectionViewSnapSampleTests.m; sourceTree = ""; }; 43 | C932458B1B95F61100FC3E13 /* CSSCollectionViewFlowLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSCollectionViewFlowLayout.h; sourceTree = ""; }; 44 | C932458C1B95F61100FC3E13 /* CSSCollectionViewFlowLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSSCollectionViewFlowLayout.m; sourceTree = ""; }; 45 | C932458E1B95F65800FC3E13 /* CSSCollectionViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSCollectionViewController.h; sourceTree = ""; }; 46 | C932458F1B95F65800FC3E13 /* CSSCollectionViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSSCollectionViewController.m; sourceTree = ""; }; 47 | C93245911B95F95100FC3E13 /* CSSCollectionViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSCollectionViewCell.h; sourceTree = ""; }; 48 | C93245921B95F95100FC3E13 /* CSSCollectionViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSSCollectionViewCell.m; sourceTree = ""; }; 49 | /* End PBXFileReference section */ 50 | 51 | /* Begin PBXFrameworksBuildPhase section */ 52 | C932455F1B95F5C600FC3E13 /* Frameworks */ = { 53 | isa = PBXFrameworksBuildPhase; 54 | buildActionMask = 2147483647; 55 | files = ( 56 | ); 57 | runOnlyForDeploymentPostprocessing = 0; 58 | }; 59 | C93245781B95F5C600FC3E13 /* Frameworks */ = { 60 | isa = PBXFrameworksBuildPhase; 61 | buildActionMask = 2147483647; 62 | files = ( 63 | ); 64 | runOnlyForDeploymentPostprocessing = 0; 65 | }; 66 | /* End PBXFrameworksBuildPhase section */ 67 | 68 | /* Begin PBXGroup section */ 69 | C93245591B95F5C600FC3E13 = { 70 | isa = PBXGroup; 71 | children = ( 72 | C93245641B95F5C600FC3E13 /* CollectionViewSnapSample */, 73 | C932457E1B95F5C600FC3E13 /* CollectionViewSnapSampleTests */, 74 | C93245631B95F5C600FC3E13 /* Products */, 75 | ); 76 | sourceTree = ""; 77 | }; 78 | C93245631B95F5C600FC3E13 /* Products */ = { 79 | isa = PBXGroup; 80 | children = ( 81 | C93245621B95F5C600FC3E13 /* CollectionViewSnapSample.app */, 82 | C932457B1B95F5C600FC3E13 /* CollectionViewSnapSampleTests.xctest */, 83 | ); 84 | name = Products; 85 | sourceTree = ""; 86 | }; 87 | C93245641B95F5C600FC3E13 /* CollectionViewSnapSample */ = { 88 | isa = PBXGroup; 89 | children = ( 90 | C932456F1B95F5C600FC3E13 /* Main.storyboard */, 91 | C93245691B95F5C600FC3E13 /* CSSAppDelegate.h */, 92 | C932456A1B95F5C600FC3E13 /* CSSAppDelegate.m */, 93 | C932458E1B95F65800FC3E13 /* CSSCollectionViewController.h */, 94 | C932458F1B95F65800FC3E13 /* CSSCollectionViewController.m */, 95 | C932458B1B95F61100FC3E13 /* CSSCollectionViewFlowLayout.h */, 96 | C932458C1B95F61100FC3E13 /* CSSCollectionViewFlowLayout.m */, 97 | C93245911B95F95100FC3E13 /* CSSCollectionViewCell.h */, 98 | C93245921B95F95100FC3E13 /* CSSCollectionViewCell.m */, 99 | C93245651B95F5C600FC3E13 /* Supporting Files */, 100 | ); 101 | path = CollectionViewSnapSample; 102 | sourceTree = ""; 103 | }; 104 | C93245651B95F5C600FC3E13 /* Supporting Files */ = { 105 | isa = PBXGroup; 106 | children = ( 107 | C93245721B95F5C600FC3E13 /* Images.xcassets */, 108 | C93245741B95F5C600FC3E13 /* LaunchScreen.xib */, 109 | C93245661B95F5C600FC3E13 /* Info.plist */, 110 | C93245671B95F5C600FC3E13 /* main.m */, 111 | ); 112 | name = "Supporting Files"; 113 | sourceTree = ""; 114 | }; 115 | C932457E1B95F5C600FC3E13 /* CollectionViewSnapSampleTests */ = { 116 | isa = PBXGroup; 117 | children = ( 118 | C93245811B95F5C600FC3E13 /* CollectionViewSnapSampleTests.m */, 119 | C932457F1B95F5C600FC3E13 /* Supporting Files */, 120 | ); 121 | path = CollectionViewSnapSampleTests; 122 | sourceTree = ""; 123 | }; 124 | C932457F1B95F5C600FC3E13 /* Supporting Files */ = { 125 | isa = PBXGroup; 126 | children = ( 127 | C93245801B95F5C600FC3E13 /* Info.plist */, 128 | ); 129 | name = "Supporting Files"; 130 | sourceTree = ""; 131 | }; 132 | /* End PBXGroup section */ 133 | 134 | /* Begin PBXNativeTarget section */ 135 | C93245611B95F5C600FC3E13 /* CollectionViewSnapSample */ = { 136 | isa = PBXNativeTarget; 137 | buildConfigurationList = C93245851B95F5C600FC3E13 /* Build configuration list for PBXNativeTarget "CollectionViewSnapSample" */; 138 | buildPhases = ( 139 | C932455E1B95F5C600FC3E13 /* Sources */, 140 | C932455F1B95F5C600FC3E13 /* Frameworks */, 141 | C93245601B95F5C600FC3E13 /* Resources */, 142 | ); 143 | buildRules = ( 144 | ); 145 | dependencies = ( 146 | ); 147 | name = CollectionViewSnapSample; 148 | productName = CollectionViewSnapSample; 149 | productReference = C93245621B95F5C600FC3E13 /* CollectionViewSnapSample.app */; 150 | productType = "com.apple.product-type.application"; 151 | }; 152 | C932457A1B95F5C600FC3E13 /* CollectionViewSnapSampleTests */ = { 153 | isa = PBXNativeTarget; 154 | buildConfigurationList = C93245881B95F5C600FC3E13 /* Build configuration list for PBXNativeTarget "CollectionViewSnapSampleTests" */; 155 | buildPhases = ( 156 | C93245771B95F5C600FC3E13 /* Sources */, 157 | C93245781B95F5C600FC3E13 /* Frameworks */, 158 | C93245791B95F5C600FC3E13 /* Resources */, 159 | ); 160 | buildRules = ( 161 | ); 162 | dependencies = ( 163 | C932457D1B95F5C600FC3E13 /* PBXTargetDependency */, 164 | ); 165 | name = CollectionViewSnapSampleTests; 166 | productName = CollectionViewSnapSampleTests; 167 | productReference = C932457B1B95F5C600FC3E13 /* CollectionViewSnapSampleTests.xctest */; 168 | productType = "com.apple.product-type.bundle.unit-test"; 169 | }; 170 | /* End PBXNativeTarget section */ 171 | 172 | /* Begin PBXProject section */ 173 | C932455A1B95F5C600FC3E13 /* Project object */ = { 174 | isa = PBXProject; 175 | attributes = { 176 | CLASSPREFIX = CSS; 177 | LastUpgradeCheck = 0640; 178 | ORGANIZATIONNAME = "平屋真吾"; 179 | TargetAttributes = { 180 | C93245611B95F5C600FC3E13 = { 181 | CreatedOnToolsVersion = 6.4; 182 | }; 183 | C932457A1B95F5C600FC3E13 = { 184 | CreatedOnToolsVersion = 6.4; 185 | TestTargetID = C93245611B95F5C600FC3E13; 186 | }; 187 | }; 188 | }; 189 | buildConfigurationList = C932455D1B95F5C600FC3E13 /* Build configuration list for PBXProject "CollectionViewSnapSample" */; 190 | compatibilityVersion = "Xcode 3.2"; 191 | developmentRegion = English; 192 | hasScannedForEncodings = 0; 193 | knownRegions = ( 194 | en, 195 | Base, 196 | ); 197 | mainGroup = C93245591B95F5C600FC3E13; 198 | productRefGroup = C93245631B95F5C600FC3E13 /* Products */; 199 | projectDirPath = ""; 200 | projectRoot = ""; 201 | targets = ( 202 | C93245611B95F5C600FC3E13 /* CollectionViewSnapSample */, 203 | C932457A1B95F5C600FC3E13 /* CollectionViewSnapSampleTests */, 204 | ); 205 | }; 206 | /* End PBXProject section */ 207 | 208 | /* Begin PBXResourcesBuildPhase section */ 209 | C93245601B95F5C600FC3E13 /* Resources */ = { 210 | isa = PBXResourcesBuildPhase; 211 | buildActionMask = 2147483647; 212 | files = ( 213 | C93245711B95F5C600FC3E13 /* Main.storyboard in Resources */, 214 | C93245761B95F5C600FC3E13 /* LaunchScreen.xib in Resources */, 215 | C93245731B95F5C600FC3E13 /* Images.xcassets in Resources */, 216 | ); 217 | runOnlyForDeploymentPostprocessing = 0; 218 | }; 219 | C93245791B95F5C600FC3E13 /* Resources */ = { 220 | isa = PBXResourcesBuildPhase; 221 | buildActionMask = 2147483647; 222 | files = ( 223 | ); 224 | runOnlyForDeploymentPostprocessing = 0; 225 | }; 226 | /* End PBXResourcesBuildPhase section */ 227 | 228 | /* Begin PBXSourcesBuildPhase section */ 229 | C932455E1B95F5C600FC3E13 /* Sources */ = { 230 | isa = PBXSourcesBuildPhase; 231 | buildActionMask = 2147483647; 232 | files = ( 233 | C93245901B95F65800FC3E13 /* CSSCollectionViewController.m in Sources */, 234 | C932456B1B95F5C600FC3E13 /* CSSAppDelegate.m in Sources */, 235 | C932458D1B95F61100FC3E13 /* CSSCollectionViewFlowLayout.m in Sources */, 236 | C93245681B95F5C600FC3E13 /* main.m in Sources */, 237 | C93245931B95F95100FC3E13 /* CSSCollectionViewCell.m in Sources */, 238 | ); 239 | runOnlyForDeploymentPostprocessing = 0; 240 | }; 241 | C93245771B95F5C600FC3E13 /* Sources */ = { 242 | isa = PBXSourcesBuildPhase; 243 | buildActionMask = 2147483647; 244 | files = ( 245 | C93245821B95F5C600FC3E13 /* CollectionViewSnapSampleTests.m in Sources */, 246 | ); 247 | runOnlyForDeploymentPostprocessing = 0; 248 | }; 249 | /* End PBXSourcesBuildPhase section */ 250 | 251 | /* Begin PBXTargetDependency section */ 252 | C932457D1B95F5C600FC3E13 /* PBXTargetDependency */ = { 253 | isa = PBXTargetDependency; 254 | target = C93245611B95F5C600FC3E13 /* CollectionViewSnapSample */; 255 | targetProxy = C932457C1B95F5C600FC3E13 /* PBXContainerItemProxy */; 256 | }; 257 | /* End PBXTargetDependency section */ 258 | 259 | /* Begin PBXVariantGroup section */ 260 | C932456F1B95F5C600FC3E13 /* Main.storyboard */ = { 261 | isa = PBXVariantGroup; 262 | children = ( 263 | C93245701B95F5C600FC3E13 /* Base */, 264 | ); 265 | name = Main.storyboard; 266 | sourceTree = ""; 267 | }; 268 | C93245741B95F5C600FC3E13 /* LaunchScreen.xib */ = { 269 | isa = PBXVariantGroup; 270 | children = ( 271 | C93245751B95F5C600FC3E13 /* Base */, 272 | ); 273 | name = LaunchScreen.xib; 274 | sourceTree = ""; 275 | }; 276 | /* End PBXVariantGroup section */ 277 | 278 | /* Begin XCBuildConfiguration section */ 279 | C93245831B95F5C600FC3E13 /* Debug */ = { 280 | isa = XCBuildConfiguration; 281 | buildSettings = { 282 | ALWAYS_SEARCH_USER_PATHS = NO; 283 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 284 | CLANG_CXX_LIBRARY = "libc++"; 285 | CLANG_ENABLE_MODULES = YES; 286 | CLANG_ENABLE_OBJC_ARC = YES; 287 | CLANG_WARN_BOOL_CONVERSION = YES; 288 | CLANG_WARN_CONSTANT_CONVERSION = YES; 289 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 290 | CLANG_WARN_EMPTY_BODY = YES; 291 | CLANG_WARN_ENUM_CONVERSION = YES; 292 | CLANG_WARN_INT_CONVERSION = YES; 293 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 294 | CLANG_WARN_UNREACHABLE_CODE = YES; 295 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 296 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 297 | COPY_PHASE_STRIP = NO; 298 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 299 | ENABLE_STRICT_OBJC_MSGSEND = YES; 300 | GCC_C_LANGUAGE_STANDARD = gnu99; 301 | GCC_DYNAMIC_NO_PIC = NO; 302 | GCC_NO_COMMON_BLOCKS = YES; 303 | GCC_OPTIMIZATION_LEVEL = 0; 304 | GCC_PREPROCESSOR_DEFINITIONS = ( 305 | "DEBUG=1", 306 | "$(inherited)", 307 | ); 308 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 309 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 310 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 311 | GCC_WARN_UNDECLARED_SELECTOR = YES; 312 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 313 | GCC_WARN_UNUSED_FUNCTION = YES; 314 | GCC_WARN_UNUSED_VARIABLE = YES; 315 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 316 | MTL_ENABLE_DEBUG_INFO = YES; 317 | ONLY_ACTIVE_ARCH = YES; 318 | SDKROOT = iphoneos; 319 | }; 320 | name = Debug; 321 | }; 322 | C93245841B95F5C600FC3E13 /* Release */ = { 323 | isa = XCBuildConfiguration; 324 | buildSettings = { 325 | ALWAYS_SEARCH_USER_PATHS = NO; 326 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 327 | CLANG_CXX_LIBRARY = "libc++"; 328 | CLANG_ENABLE_MODULES = YES; 329 | CLANG_ENABLE_OBJC_ARC = YES; 330 | CLANG_WARN_BOOL_CONVERSION = YES; 331 | CLANG_WARN_CONSTANT_CONVERSION = YES; 332 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 333 | CLANG_WARN_EMPTY_BODY = YES; 334 | CLANG_WARN_ENUM_CONVERSION = YES; 335 | CLANG_WARN_INT_CONVERSION = YES; 336 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 337 | CLANG_WARN_UNREACHABLE_CODE = YES; 338 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 339 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 340 | COPY_PHASE_STRIP = NO; 341 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 342 | ENABLE_NS_ASSERTIONS = NO; 343 | ENABLE_STRICT_OBJC_MSGSEND = YES; 344 | GCC_C_LANGUAGE_STANDARD = gnu99; 345 | GCC_NO_COMMON_BLOCKS = YES; 346 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 347 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 348 | GCC_WARN_UNDECLARED_SELECTOR = YES; 349 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 350 | GCC_WARN_UNUSED_FUNCTION = YES; 351 | GCC_WARN_UNUSED_VARIABLE = YES; 352 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 353 | MTL_ENABLE_DEBUG_INFO = NO; 354 | SDKROOT = iphoneos; 355 | VALIDATE_PRODUCT = YES; 356 | }; 357 | name = Release; 358 | }; 359 | C93245861B95F5C600FC3E13 /* Debug */ = { 360 | isa = XCBuildConfiguration; 361 | buildSettings = { 362 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 363 | INFOPLIST_FILE = CollectionViewSnapSample/Info.plist; 364 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 365 | PRODUCT_NAME = "$(TARGET_NAME)"; 366 | }; 367 | name = Debug; 368 | }; 369 | C93245871B95F5C600FC3E13 /* Release */ = { 370 | isa = XCBuildConfiguration; 371 | buildSettings = { 372 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 373 | INFOPLIST_FILE = CollectionViewSnapSample/Info.plist; 374 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 375 | PRODUCT_NAME = "$(TARGET_NAME)"; 376 | }; 377 | name = Release; 378 | }; 379 | C93245891B95F5C600FC3E13 /* Debug */ = { 380 | isa = XCBuildConfiguration; 381 | buildSettings = { 382 | BUNDLE_LOADER = "$(TEST_HOST)"; 383 | FRAMEWORK_SEARCH_PATHS = ( 384 | "$(SDKROOT)/Developer/Library/Frameworks", 385 | "$(inherited)", 386 | ); 387 | GCC_PREPROCESSOR_DEFINITIONS = ( 388 | "DEBUG=1", 389 | "$(inherited)", 390 | ); 391 | INFOPLIST_FILE = CollectionViewSnapSampleTests/Info.plist; 392 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 393 | PRODUCT_NAME = "$(TARGET_NAME)"; 394 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CollectionViewSnapSample.app/CollectionViewSnapSample"; 395 | }; 396 | name = Debug; 397 | }; 398 | C932458A1B95F5C600FC3E13 /* Release */ = { 399 | isa = XCBuildConfiguration; 400 | buildSettings = { 401 | BUNDLE_LOADER = "$(TEST_HOST)"; 402 | FRAMEWORK_SEARCH_PATHS = ( 403 | "$(SDKROOT)/Developer/Library/Frameworks", 404 | "$(inherited)", 405 | ); 406 | INFOPLIST_FILE = CollectionViewSnapSampleTests/Info.plist; 407 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 408 | PRODUCT_NAME = "$(TARGET_NAME)"; 409 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CollectionViewSnapSample.app/CollectionViewSnapSample"; 410 | }; 411 | name = Release; 412 | }; 413 | /* End XCBuildConfiguration section */ 414 | 415 | /* Begin XCConfigurationList section */ 416 | C932455D1B95F5C600FC3E13 /* Build configuration list for PBXProject "CollectionViewSnapSample" */ = { 417 | isa = XCConfigurationList; 418 | buildConfigurations = ( 419 | C93245831B95F5C600FC3E13 /* Debug */, 420 | C93245841B95F5C600FC3E13 /* Release */, 421 | ); 422 | defaultConfigurationIsVisible = 0; 423 | defaultConfigurationName = Release; 424 | }; 425 | C93245851B95F5C600FC3E13 /* Build configuration list for PBXNativeTarget "CollectionViewSnapSample" */ = { 426 | isa = XCConfigurationList; 427 | buildConfigurations = ( 428 | C93245861B95F5C600FC3E13 /* Debug */, 429 | C93245871B95F5C600FC3E13 /* Release */, 430 | ); 431 | defaultConfigurationIsVisible = 0; 432 | defaultConfigurationName = Release; 433 | }; 434 | C93245881B95F5C600FC3E13 /* Build configuration list for PBXNativeTarget "CollectionViewSnapSampleTests" */ = { 435 | isa = XCConfigurationList; 436 | buildConfigurations = ( 437 | C93245891B95F5C600FC3E13 /* Debug */, 438 | C932458A1B95F5C600FC3E13 /* Release */, 439 | ); 440 | defaultConfigurationIsVisible = 0; 441 | defaultConfigurationName = Release; 442 | }; 443 | /* End XCConfigurationList section */ 444 | }; 445 | rootObject = C932455A1B95F5C600FC3E13 /* Project object */; 446 | } 447 | -------------------------------------------------------------------------------- /CollectionViewSnapSample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CollectionViewSnapSample/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 | -------------------------------------------------------------------------------- /CollectionViewSnapSample/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 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /CollectionViewSnapSample/CSSAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // CollectionViewSnapSample 4 | // 5 | // Created by 平屋真吾 on 2015/09/02. 6 | // Copyright (c) 2015年 平屋真吾. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CSSAppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /CollectionViewSnapSample/CSSAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // CollectionViewSnapSample 4 | // 5 | // Created by 平屋真吾 on 2015/09/02. 6 | // Copyright (c) 2015年 平屋真吾. All rights reserved. 7 | // 8 | 9 | #import "CSSAppDelegate.h" 10 | 11 | @interface CSSAppDelegate () 12 | 13 | @end 14 | 15 | @implementation CSSAppDelegate 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 | -------------------------------------------------------------------------------- /CollectionViewSnapSample/CSSCollectionViewCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // CSSCollectionViewCell.h 3 | // CollectionViewSnapSample 4 | // 5 | // Created by 平屋真吾 on 2015/09/02. 6 | // Copyright (c) 2015年 平屋真吾. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CSSCollectionViewCell : UICollectionViewCell 12 | 13 | @property (weak, nonatomic) IBOutlet UILabel *label; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /CollectionViewSnapSample/CSSCollectionViewCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // CSSCollectionViewCell.m 3 | // CollectionViewSnapSample 4 | // 5 | // Created by 平屋真吾 on 2015/09/02. 6 | // Copyright (c) 2015年 平屋真吾. All rights reserved. 7 | // 8 | 9 | #import "CSSCollectionViewCell.h" 10 | 11 | @implementation CSSCollectionViewCell 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /CollectionViewSnapSample/CSSCollectionViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CSSCollectionViewController.h 3 | // CollectionViewSnapSample 4 | // 5 | // Created by 平屋真吾 on 2015/09/02. 6 | // Copyright (c) 2015年 平屋真吾. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CSSCollectionViewController : UICollectionViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /CollectionViewSnapSample/CSSCollectionViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // CSSCollectionViewController.m 3 | // CollectionViewSnapSample 4 | // 5 | // Created by 平屋真吾 on 2015/09/02. 6 | // Copyright (c) 2015年 平屋真吾. All rights reserved. 7 | // 8 | 9 | #import "CSSCollectionViewController.h" 10 | #import "CSSCollectionViewCell.h" 11 | 12 | static NSString * const kReuseIdentifier = @"Cell"; 13 | 14 | @interface CSSCollectionViewController () 15 | 16 | @property (nonatomic) NSArray *dataList; 17 | 18 | @end 19 | 20 | @implementation CSSCollectionViewController 21 | 22 | 23 | - (void)viewDidLoad 24 | { 25 | [super viewDidLoad]; 26 | 27 | [self prepare]; 28 | } 29 | 30 | - (void)didReceiveMemoryWarning 31 | { 32 | [super didReceiveMemoryWarning]; 33 | } 34 | 35 | #pragma mark - UICollectionViewDataSource 36 | 37 | - (NSInteger)collectionView:(UICollectionView *)collectionView 38 | numberOfItemsInSection:(NSInteger)section 39 | { 40 | return self.dataList.count; 41 | } 42 | 43 | - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView 44 | cellForItemAtIndexPath:(NSIndexPath *)indexPath 45 | { 46 | CSSCollectionViewCell *cell = 47 | (CSSCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:kReuseIdentifier 48 | forIndexPath:indexPath]; 49 | 50 | cell.label.text = [NSString stringWithFormat:@"No.%zd", indexPath.item + 1]; 51 | 52 | NSUInteger colorCode = [self.dataList[indexPath.item] integerValue]; 53 | cell.backgroundColor = [self colorWithRGBHex:colorCode]; 54 | 55 | return cell; 56 | } 57 | 58 | #pragma mark - Private 59 | 60 | - (void)prepare 61 | { 62 | self.collectionView.pagingEnabled = NO; 63 | self.collectionView.decelerationRate = UIScrollViewDecelerationRateFast; 64 | 65 | self.dataList = @[ 66 | @0xf39c12, 67 | @0x1abc9c, 68 | @0x2980b9, 69 | @0xf1c40f, 70 | @0x3498db, 71 | @0x9b59b6, 72 | @0xe74c3c, 73 | @0xe67e22, 74 | @0x2ecc71, 75 | @0x34495e, 76 | 77 | ]; 78 | } 79 | 80 | - (UIColor *)colorWithRGBHex:(NSUInteger)hex 81 | { 82 | return [UIColor colorWithRed:((hex & 0xFF0000) >> 16) / 255.0f 83 | green:((hex & 0x00FF00) >> 8) / 255.0f 84 | blue:((hex & 0x0000FF) >> 0) / 255.0f 85 | alpha:1.0f]; 86 | } 87 | 88 | @end 89 | -------------------------------------------------------------------------------- /CollectionViewSnapSample/CSSCollectionViewFlowLayout.h: -------------------------------------------------------------------------------- 1 | // 2 | // CSSCollectionViewFlowLayout.h 3 | // CollectionViewSnapSample 4 | // 5 | // Created by 平屋真吾 on 2015/09/02. 6 | // Copyright (c) 2015年 平屋真吾. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CSSCollectionViewFlowLayout : UICollectionViewFlowLayout 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /CollectionViewSnapSample/CSSCollectionViewFlowLayout.m: -------------------------------------------------------------------------------- 1 | // 2 | // CSSCollectionViewFlowLayout.m 3 | // CollectionViewSnapSample 4 | // 5 | // Created by 平屋真吾 on 2015/09/02. 6 | // Copyright (c) 2015年 平屋真吾. All rights reserved. 7 | // 8 | 9 | #import "CSSCollectionViewFlowLayout.h" 10 | 11 | static CGFloat const kMinimumInteritemSpacing = 20.0f; 12 | static CGFloat const kItemLength = 240.0f; 13 | static CGFloat const kFlickVelocityThreshold = 0.2; 14 | 15 | @implementation CSSCollectionViewFlowLayout 16 | 17 | #pragma mark - Life Cycle 18 | 19 | - (void)awakeFromNib 20 | { 21 | [super awakeFromNib]; 22 | 23 | [self prepare]; 24 | } 25 | 26 | #pragma mark - UICollectionViewLayout 27 | 28 | - (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset 29 | withScrollingVelocity:(CGPoint)velocity 30 | { 31 | CGFloat currentPage = self.collectionView.contentOffset.x / self.pageWidth; 32 | 33 | if (fabs(velocity.x) > kFlickVelocityThreshold) { 34 | CGFloat nextPage = (velocity.x > 0.0) ? ceil(currentPage) : floor(currentPage); 35 | return CGPointMake((nextPage * self.pageWidth), proposedContentOffset.y); 36 | } else { 37 | return CGPointMake((round(currentPage) * self.pageWidth), proposedContentOffset.y); 38 | } 39 | } 40 | 41 | #pragma mark - Private 42 | 43 | - (CGFloat)pageWidth 44 | { 45 | return self.itemSize.width + self.minimumLineSpacing; 46 | } 47 | 48 | - (void)prepare 49 | { 50 | self.itemSize = CGSizeMake(kItemLength, kItemLength); 51 | self.minimumLineSpacing = kMinimumInteritemSpacing; 52 | self.scrollDirection = UICollectionViewScrollDirectionHorizontal; 53 | 54 | CGFloat horizontalInset = ([UIScreen mainScreen].bounds.size.width - kItemLength) / 2; 55 | CGFloat verticalInset = ([UIScreen mainScreen].bounds.size.height - kItemLength) / 2; 56 | 57 | self.sectionInset = UIEdgeInsetsMake(verticalInset, 58 | horizontalInset, 59 | verticalInset, 60 | horizontalInset); 61 | } 62 | 63 | @end 64 | 65 | -------------------------------------------------------------------------------- /CollectionViewSnapSample/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 | } -------------------------------------------------------------------------------- /CollectionViewSnapSample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.sample.$(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 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /CollectionViewSnapSample/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // CollectionViewSnapSample 4 | // 5 | // Created by 平屋真吾 on 2015/09/02. 6 | // Copyright (c) 2015年 平屋真吾. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CSSAppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([CSSAppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /CollectionViewSnapSampleTests/CollectionViewSnapSampleTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // CollectionViewSnapSampleTests.m 3 | // CollectionViewSnapSampleTests 4 | // 5 | // Created by 平屋真吾 on 2015/09/02. 6 | // Copyright (c) 2015年 平屋真吾. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface CollectionViewSnapSampleTests : XCTestCase 13 | 14 | @end 15 | 16 | @implementation CollectionViewSnapSampleTests 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 | -------------------------------------------------------------------------------- /CollectionViewSnapSampleTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.sample.$(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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CollectionViewSnapSample 2 | 3 | ![](https://raw.githubusercontent.com/hirayaCM/CollectionViewSnapSample/master/preview.gif) 4 | 5 | - snap collection view items sample 6 | - Sample project for [this article](http://dev.classmethod.jp/smartphone/iphone/collection-view-layout-cell-snap/) 7 | 8 | ## development environment 9 | - OS X 10.10.5(14F27) 10 | - Xcode Version 6.4 (6E35b) / iOS SDK 8.4 11 | - development target: iOS 8.0 12 | -------------------------------------------------------------------------------- /preview.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shingohry/CollectionViewSnapSample/cba261a35f3881974de260e0c94e5ff2c9ce5d5f/preview.gif --------------------------------------------------------------------------------