├── .gitignore ├── .swift-version ├── Example ├── GravitySliderFlowLayout.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── xcshareddata │ │ └── xcschemes │ │ └── GravitySliderFlowLayout-Example.xcscheme └── GravitySliderFlowLayout │ ├── AppDelegate.swift │ ├── Base.lproj │ └── LaunchScreen.xib │ ├── Cells │ └── ProductCollectionViewCell.swift │ ├── Extensions │ └── UIColor.swift │ ├── Images.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ ├── beats_headphone.imageset │ │ ├── Contents.json │ │ └── slide 1.png │ ├── beats_headphones_white.imageset │ │ ├── Contents.json │ │ └── slide 2.png │ ├── beats_image.imageset │ │ ├── Contents.json │ │ └── slide 3.png │ └── plus_image.imageset │ │ ├── Contents.json │ │ ├── group-2@2x.png │ │ ├── group-2@3x.png │ │ └── plus_image.png │ ├── Info.plist │ ├── Main.storyboard │ └── ViewController.swift ├── GravitySliderFlowLayout.podspec ├── GravitySliderFlowLayout └── Classes │ └── GravitySliderFlowLayout.swift ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # OS X 2 | .DS_Store 3 | 4 | # Xcode 5 | Pods/ 6 | build/ 7 | *.pbxuser 8 | !default.pbxuser 9 | *.mode1v3 10 | !default.mode1v3 11 | *.mode2v3 12 | !default.mode2v3 13 | *.perspectivev3 14 | !default.perspectivev3 15 | xcuserdata/ 16 | *.xccheckout 17 | profile 18 | *.moved-aside 19 | DerivedData 20 | *.hmap 21 | *.ipa 22 | 23 | # Bundler 24 | .bundle 25 | 26 | Carthage 27 | # We recommend against adding the Pods directory to your .gitignore. However 28 | # you should judge for yourself, the pros and cons are mentioned at: 29 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 30 | # 31 | # Note: if you ignore the Pods directory, make sure to uncomment 32 | # `pod install` in .travis.yml 33 | # 34 | # Pods/ 35 | -------------------------------------------------------------------------------- /.swift-version: -------------------------------------------------------------------------------- 1 | 4.0 -------------------------------------------------------------------------------- /Example/GravitySliderFlowLayout.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 05D036881FA76085002C927B /* GravitySliderFlowLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05D036871FA76084002C927B /* GravitySliderFlowLayout.swift */; }; 11 | 05D6C0951F9F1757002174F6 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05D6C0941F9F1757002174F6 /* ViewController.swift */; }; 12 | 05D6C09A1F9F1777002174F6 /* ProductCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05D6C0991F9F1777002174F6 /* ProductCollectionViewCell.swift */; }; 13 | 05D6C09C1F9F17DF002174F6 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 05D6C09B1F9F17DF002174F6 /* Main.storyboard */; }; 14 | 05D6C09F1F9F17FF002174F6 /* UIColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05D6C09E1F9F17FF002174F6 /* UIColor.swift */; }; 15 | 607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD51AFB9204008FA782 /* AppDelegate.swift */; }; 16 | 607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDC1AFB9204008FA782 /* Images.xcassets */; }; 17 | 607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXFileReference section */ 21 | 05D036871FA76084002C927B /* GravitySliderFlowLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = GravitySliderFlowLayout.swift; path = ../../GravitySliderFlowLayout/Classes/GravitySliderFlowLayout.swift; sourceTree = ""; }; 22 | 05D6C0941F9F1757002174F6 /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 23 | 05D6C0991F9F1777002174F6 /* ProductCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProductCollectionViewCell.swift; sourceTree = ""; }; 24 | 05D6C09B1F9F17DF002174F6 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = ""; }; 25 | 05D6C09E1F9F17FF002174F6 /* UIColor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIColor.swift; sourceTree = ""; }; 26 | 607FACD01AFB9204008FA782 /* GravitySliderFlowLayout_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GravitySliderFlowLayout_Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; 27 | 607FACD41AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 28 | 607FACD51AFB9204008FA782 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 29 | 607FACDC1AFB9204008FA782 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 30 | 607FACDF1AFB9204008FA782 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 31 | /* End PBXFileReference section */ 32 | 33 | /* Begin PBXFrameworksBuildPhase section */ 34 | 607FACCD1AFB9204008FA782 /* Frameworks */ = { 35 | isa = PBXFrameworksBuildPhase; 36 | buildActionMask = 2147483647; 37 | files = ( 38 | ); 39 | runOnlyForDeploymentPostprocessing = 0; 40 | }; 41 | /* End PBXFrameworksBuildPhase section */ 42 | 43 | /* Begin PBXGroup section */ 44 | 05D036861FA76069002C927B /* Sources */ = { 45 | isa = PBXGroup; 46 | children = ( 47 | 05D036871FA76084002C927B /* GravitySliderFlowLayout.swift */, 48 | ); 49 | path = Sources; 50 | sourceTree = ""; 51 | }; 52 | 05D6C0981F9F1777002174F6 /* Cells */ = { 53 | isa = PBXGroup; 54 | children = ( 55 | 05D6C0991F9F1777002174F6 /* ProductCollectionViewCell.swift */, 56 | ); 57 | path = Cells; 58 | sourceTree = ""; 59 | }; 60 | 05D6C09D1F9F17FF002174F6 /* Extensions */ = { 61 | isa = PBXGroup; 62 | children = ( 63 | 05D6C09E1F9F17FF002174F6 /* UIColor.swift */, 64 | ); 65 | path = Extensions; 66 | sourceTree = ""; 67 | }; 68 | 4D6D43EF6F3A826E87754FAA /* Frameworks */ = { 69 | isa = PBXGroup; 70 | children = ( 71 | ); 72 | name = Frameworks; 73 | sourceTree = ""; 74 | }; 75 | 607FACC71AFB9204008FA782 = { 76 | isa = PBXGroup; 77 | children = ( 78 | 05D036861FA76069002C927B /* Sources */, 79 | 607FACD21AFB9204008FA782 /* Example for GravitySliderFlowLayout */, 80 | 607FACD11AFB9204008FA782 /* Products */, 81 | 4D6D43EF6F3A826E87754FAA /* Frameworks */, 82 | ); 83 | sourceTree = ""; 84 | }; 85 | 607FACD11AFB9204008FA782 /* Products */ = { 86 | isa = PBXGroup; 87 | children = ( 88 | 607FACD01AFB9204008FA782 /* GravitySliderFlowLayout_Example.app */, 89 | ); 90 | name = Products; 91 | sourceTree = ""; 92 | }; 93 | 607FACD21AFB9204008FA782 /* Example for GravitySliderFlowLayout */ = { 94 | isa = PBXGroup; 95 | children = ( 96 | 607FACD51AFB9204008FA782 /* AppDelegate.swift */, 97 | 05D6C0941F9F1757002174F6 /* ViewController.swift */, 98 | 607FACDC1AFB9204008FA782 /* Images.xcassets */, 99 | 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */, 100 | 05D6C09B1F9F17DF002174F6 /* Main.storyboard */, 101 | 05D6C09D1F9F17FF002174F6 /* Extensions */, 102 | 05D6C0981F9F1777002174F6 /* Cells */, 103 | 607FACD31AFB9204008FA782 /* Supporting Files */, 104 | ); 105 | name = "Example for GravitySliderFlowLayout"; 106 | path = GravitySliderFlowLayout; 107 | sourceTree = ""; 108 | }; 109 | 607FACD31AFB9204008FA782 /* Supporting Files */ = { 110 | isa = PBXGroup; 111 | children = ( 112 | 607FACD41AFB9204008FA782 /* Info.plist */, 113 | ); 114 | name = "Supporting Files"; 115 | sourceTree = ""; 116 | }; 117 | /* End PBXGroup section */ 118 | 119 | /* Begin PBXNativeTarget section */ 120 | 607FACCF1AFB9204008FA782 /* GravitySliderFlowLayout_Example */ = { 121 | isa = PBXNativeTarget; 122 | buildConfigurationList = 607FACEF1AFB9204008FA782 /* Build configuration list for PBXNativeTarget "GravitySliderFlowLayout_Example" */; 123 | buildPhases = ( 124 | 607FACCC1AFB9204008FA782 /* Sources */, 125 | 607FACCD1AFB9204008FA782 /* Frameworks */, 126 | 607FACCE1AFB9204008FA782 /* Resources */, 127 | ); 128 | buildRules = ( 129 | ); 130 | dependencies = ( 131 | ); 132 | name = GravitySliderFlowLayout_Example; 133 | productName = GravitySliderFlowLayout; 134 | productReference = 607FACD01AFB9204008FA782 /* GravitySliderFlowLayout_Example.app */; 135 | productType = "com.apple.product-type.application"; 136 | }; 137 | /* End PBXNativeTarget section */ 138 | 139 | /* Begin PBXProject section */ 140 | 607FACC81AFB9204008FA782 /* Project object */ = { 141 | isa = PBXProject; 142 | attributes = { 143 | LastSwiftUpdateCheck = 0830; 144 | LastUpgradeCheck = 0830; 145 | ORGANIZATIONNAME = CocoaPods; 146 | TargetAttributes = { 147 | 607FACCF1AFB9204008FA782 = { 148 | CreatedOnToolsVersion = 6.3.1; 149 | LastSwiftMigration = 0900; 150 | }; 151 | }; 152 | }; 153 | buildConfigurationList = 607FACCB1AFB9204008FA782 /* Build configuration list for PBXProject "GravitySliderFlowLayout" */; 154 | compatibilityVersion = "Xcode 3.2"; 155 | developmentRegion = English; 156 | hasScannedForEncodings = 0; 157 | knownRegions = ( 158 | en, 159 | Base, 160 | ); 161 | mainGroup = 607FACC71AFB9204008FA782; 162 | productRefGroup = 607FACD11AFB9204008FA782 /* Products */; 163 | projectDirPath = ""; 164 | projectRoot = ""; 165 | targets = ( 166 | 607FACCF1AFB9204008FA782 /* GravitySliderFlowLayout_Example */, 167 | ); 168 | }; 169 | /* End PBXProject section */ 170 | 171 | /* Begin PBXResourcesBuildPhase section */ 172 | 607FACCE1AFB9204008FA782 /* Resources */ = { 173 | isa = PBXResourcesBuildPhase; 174 | buildActionMask = 2147483647; 175 | files = ( 176 | 05D6C09C1F9F17DF002174F6 /* Main.storyboard in Resources */, 177 | 607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */, 178 | 607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */, 179 | ); 180 | runOnlyForDeploymentPostprocessing = 0; 181 | }; 182 | /* End PBXResourcesBuildPhase section */ 183 | 184 | /* Begin PBXSourcesBuildPhase section */ 185 | 607FACCC1AFB9204008FA782 /* Sources */ = { 186 | isa = PBXSourcesBuildPhase; 187 | buildActionMask = 2147483647; 188 | files = ( 189 | 05D6C0951F9F1757002174F6 /* ViewController.swift in Sources */, 190 | 05D6C09F1F9F17FF002174F6 /* UIColor.swift in Sources */, 191 | 05D036881FA76085002C927B /* GravitySliderFlowLayout.swift in Sources */, 192 | 05D6C09A1F9F1777002174F6 /* ProductCollectionViewCell.swift in Sources */, 193 | 607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */, 194 | ); 195 | runOnlyForDeploymentPostprocessing = 0; 196 | }; 197 | /* End PBXSourcesBuildPhase section */ 198 | 199 | /* Begin PBXVariantGroup section */ 200 | 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */ = { 201 | isa = PBXVariantGroup; 202 | children = ( 203 | 607FACDF1AFB9204008FA782 /* Base */, 204 | ); 205 | name = LaunchScreen.xib; 206 | sourceTree = ""; 207 | }; 208 | /* End PBXVariantGroup section */ 209 | 210 | /* Begin XCBuildConfiguration section */ 211 | 607FACED1AFB9204008FA782 /* Debug */ = { 212 | isa = XCBuildConfiguration; 213 | buildSettings = { 214 | ALWAYS_SEARCH_USER_PATHS = NO; 215 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 216 | CLANG_CXX_LIBRARY = "libc++"; 217 | CLANG_ENABLE_MODULES = YES; 218 | CLANG_ENABLE_OBJC_ARC = YES; 219 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 220 | CLANG_WARN_BOOL_CONVERSION = YES; 221 | CLANG_WARN_COMMA = YES; 222 | CLANG_WARN_CONSTANT_CONVERSION = YES; 223 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 224 | CLANG_WARN_EMPTY_BODY = YES; 225 | CLANG_WARN_ENUM_CONVERSION = YES; 226 | CLANG_WARN_INFINITE_RECURSION = YES; 227 | CLANG_WARN_INT_CONVERSION = YES; 228 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 229 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 230 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 231 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 232 | CLANG_WARN_STRICT_PROTOTYPES = YES; 233 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 234 | CLANG_WARN_UNREACHABLE_CODE = YES; 235 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 236 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 237 | COPY_PHASE_STRIP = NO; 238 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 239 | ENABLE_STRICT_OBJC_MSGSEND = YES; 240 | ENABLE_TESTABILITY = YES; 241 | GCC_C_LANGUAGE_STANDARD = gnu99; 242 | GCC_DYNAMIC_NO_PIC = NO; 243 | GCC_NO_COMMON_BLOCKS = YES; 244 | GCC_OPTIMIZATION_LEVEL = 0; 245 | GCC_PREPROCESSOR_DEFINITIONS = ( 246 | "DEBUG=1", 247 | "$(inherited)", 248 | ); 249 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 250 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 251 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 252 | GCC_WARN_UNDECLARED_SELECTOR = YES; 253 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 254 | GCC_WARN_UNUSED_FUNCTION = YES; 255 | GCC_WARN_UNUSED_VARIABLE = YES; 256 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 257 | MTL_ENABLE_DEBUG_INFO = YES; 258 | ONLY_ACTIVE_ARCH = YES; 259 | SDKROOT = iphoneos; 260 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 261 | }; 262 | name = Debug; 263 | }; 264 | 607FACEE1AFB9204008FA782 /* Release */ = { 265 | isa = XCBuildConfiguration; 266 | buildSettings = { 267 | ALWAYS_SEARCH_USER_PATHS = NO; 268 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 269 | CLANG_CXX_LIBRARY = "libc++"; 270 | CLANG_ENABLE_MODULES = YES; 271 | CLANG_ENABLE_OBJC_ARC = YES; 272 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 273 | CLANG_WARN_BOOL_CONVERSION = YES; 274 | CLANG_WARN_COMMA = YES; 275 | CLANG_WARN_CONSTANT_CONVERSION = YES; 276 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 277 | CLANG_WARN_EMPTY_BODY = YES; 278 | CLANG_WARN_ENUM_CONVERSION = YES; 279 | CLANG_WARN_INFINITE_RECURSION = YES; 280 | CLANG_WARN_INT_CONVERSION = YES; 281 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 282 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 283 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 284 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 285 | CLANG_WARN_STRICT_PROTOTYPES = YES; 286 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 287 | CLANG_WARN_UNREACHABLE_CODE = YES; 288 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 289 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 290 | COPY_PHASE_STRIP = NO; 291 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 292 | ENABLE_NS_ASSERTIONS = NO; 293 | ENABLE_STRICT_OBJC_MSGSEND = YES; 294 | GCC_C_LANGUAGE_STANDARD = gnu99; 295 | GCC_NO_COMMON_BLOCKS = YES; 296 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 297 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 298 | GCC_WARN_UNDECLARED_SELECTOR = YES; 299 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 300 | GCC_WARN_UNUSED_FUNCTION = YES; 301 | GCC_WARN_UNUSED_VARIABLE = YES; 302 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 303 | MTL_ENABLE_DEBUG_INFO = NO; 304 | SDKROOT = iphoneos; 305 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 306 | VALIDATE_PRODUCT = YES; 307 | }; 308 | name = Release; 309 | }; 310 | 607FACF01AFB9204008FA782 /* Debug */ = { 311 | isa = XCBuildConfiguration; 312 | buildSettings = { 313 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 314 | INFOPLIST_FILE = GravitySliderFlowLayout/Info.plist; 315 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 316 | MODULE_NAME = ExampleApp; 317 | PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)"; 318 | PRODUCT_NAME = "$(TARGET_NAME)"; 319 | SWIFT_SWIFT3_OBJC_INFERENCE = Default; 320 | SWIFT_VERSION = 4.0; 321 | }; 322 | name = Debug; 323 | }; 324 | 607FACF11AFB9204008FA782 /* Release */ = { 325 | isa = XCBuildConfiguration; 326 | buildSettings = { 327 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 328 | INFOPLIST_FILE = GravitySliderFlowLayout/Info.plist; 329 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 330 | MODULE_NAME = ExampleApp; 331 | PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)"; 332 | PRODUCT_NAME = "$(TARGET_NAME)"; 333 | SWIFT_SWIFT3_OBJC_INFERENCE = Default; 334 | SWIFT_VERSION = 4.0; 335 | }; 336 | name = Release; 337 | }; 338 | /* End XCBuildConfiguration section */ 339 | 340 | /* Begin XCConfigurationList section */ 341 | 607FACCB1AFB9204008FA782 /* Build configuration list for PBXProject "GravitySliderFlowLayout" */ = { 342 | isa = XCConfigurationList; 343 | buildConfigurations = ( 344 | 607FACED1AFB9204008FA782 /* Debug */, 345 | 607FACEE1AFB9204008FA782 /* Release */, 346 | ); 347 | defaultConfigurationIsVisible = 0; 348 | defaultConfigurationName = Release; 349 | }; 350 | 607FACEF1AFB9204008FA782 /* Build configuration list for PBXNativeTarget "GravitySliderFlowLayout_Example" */ = { 351 | isa = XCConfigurationList; 352 | buildConfigurations = ( 353 | 607FACF01AFB9204008FA782 /* Debug */, 354 | 607FACF11AFB9204008FA782 /* Release */, 355 | ); 356 | defaultConfigurationIsVisible = 0; 357 | defaultConfigurationName = Release; 358 | }; 359 | /* End XCConfigurationList section */ 360 | }; 361 | rootObject = 607FACC81AFB9204008FA782 /* Project object */; 362 | } 363 | -------------------------------------------------------------------------------- /Example/GravitySliderFlowLayout.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/GravitySliderFlowLayout.xcodeproj/xcshareddata/xcschemes/GravitySliderFlowLayout-Example.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 45 | 46 | 48 | 54 | 55 | 56 | 57 | 58 | 64 | 65 | 66 | 67 | 68 | 69 | 80 | 82 | 88 | 89 | 90 | 91 | 92 | 93 | 99 | 101 | 107 | 108 | 109 | 110 | 112 | 113 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /Example/GravitySliderFlowLayout/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // GravitySliderFlowLayout 4 | // 5 | // Created by ihahanov on 10/24/2017. 6 | // Copyright (c) 2017 ihahanov. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // 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. 24 | // 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. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // 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. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // 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. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Example/GravitySliderFlowLayout/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 | -------------------------------------------------------------------------------- /Example/GravitySliderFlowLayout/Cells/ProductCollectionViewCell.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ProductCollectionViewCell.swift 3 | // GravitySliderExample 4 | // 5 | // Created by Artem Tevosyan on 9/27/17. 6 | // Copyright © 2017 Artem Tevosyan. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ProductCollectionViewCell: UICollectionViewCell { 12 | 13 | @IBOutlet weak var newLabel: UILabel! 14 | @IBOutlet weak var productImage: UIImageView! 15 | } 16 | -------------------------------------------------------------------------------- /Example/GravitySliderFlowLayout/Extensions/UIColor.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIColor.swift 3 | // GravitySliderExample 4 | // 5 | // Created by Artem Tevosyan on 9/27/17. 6 | // Copyright © 2017 Artem Tevosyan. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | 12 | extension UIColor { 13 | convenience init(hex: String) { 14 | let scanner = Scanner(string: hex) 15 | scanner.scanLocation = 0 16 | 17 | var rgbValue: UInt64 = 0 18 | 19 | scanner.scanHexInt64(&rgbValue) 20 | 21 | let r = (rgbValue & 0xff0000) >> 16 22 | let g = (rgbValue & 0xff00) >> 8 23 | let b = rgbValue & 0xff 24 | 25 | self.init( 26 | red: CGFloat(r) / 0xff, 27 | green: CGFloat(g) / 0xff, 28 | blue: CGFloat(b) / 0xff, alpha: 1 29 | ) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Example/GravitySliderFlowLayout/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ios-marketing", 45 | "size" : "1024x1024", 46 | "scale" : "1x" 47 | } 48 | ], 49 | "info" : { 50 | "version" : 1, 51 | "author" : "xcode" 52 | } 53 | } -------------------------------------------------------------------------------- /Example/GravitySliderFlowLayout/Images.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Example/GravitySliderFlowLayout/Images.xcassets/beats_headphone.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "slide 1.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Example/GravitySliderFlowLayout/Images.xcassets/beats_headphone.imageset/slide 1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ApplikeySolutions/GravitySlider/f08e1e7199874238629c8614e5008c88e29f84e4/Example/GravitySliderFlowLayout/Images.xcassets/beats_headphone.imageset/slide 1.png -------------------------------------------------------------------------------- /Example/GravitySliderFlowLayout/Images.xcassets/beats_headphones_white.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "slide 2.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Example/GravitySliderFlowLayout/Images.xcassets/beats_headphones_white.imageset/slide 2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ApplikeySolutions/GravitySlider/f08e1e7199874238629c8614e5008c88e29f84e4/Example/GravitySliderFlowLayout/Images.xcassets/beats_headphones_white.imageset/slide 2.png -------------------------------------------------------------------------------- /Example/GravitySliderFlowLayout/Images.xcassets/beats_image.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "slide 3.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Example/GravitySliderFlowLayout/Images.xcassets/beats_image.imageset/slide 3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ApplikeySolutions/GravitySlider/f08e1e7199874238629c8614e5008c88e29f84e4/Example/GravitySliderFlowLayout/Images.xcassets/beats_image.imageset/slide 3.png -------------------------------------------------------------------------------- /Example/GravitySliderFlowLayout/Images.xcassets/plus_image.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "plus_image.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "group-2@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "group-2@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /Example/GravitySliderFlowLayout/Images.xcassets/plus_image.imageset/group-2@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ApplikeySolutions/GravitySlider/f08e1e7199874238629c8614e5008c88e29f84e4/Example/GravitySliderFlowLayout/Images.xcassets/plus_image.imageset/group-2@2x.png -------------------------------------------------------------------------------- /Example/GravitySliderFlowLayout/Images.xcassets/plus_image.imageset/group-2@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ApplikeySolutions/GravitySlider/f08e1e7199874238629c8614e5008c88e29f84e4/Example/GravitySliderFlowLayout/Images.xcassets/plus_image.imageset/group-2@3x.png -------------------------------------------------------------------------------- /Example/GravitySliderFlowLayout/Images.xcassets/plus_image.imageset/plus_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ApplikeySolutions/GravitySlider/f08e1e7199874238629c8614e5008c88e29f84e4/Example/GravitySliderFlowLayout/Images.xcassets/plus_image.imageset/plus_image.png -------------------------------------------------------------------------------- /Example/GravitySliderFlowLayout/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 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 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /Example/GravitySliderFlowLayout/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 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 77 | 86 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | -------------------------------------------------------------------------------- /Example/GravitySliderFlowLayout/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // GravitySliderExample 4 | // 5 | // Created by Artem Tevosyan on 9/27/17. 6 | // Copyright © 2017 Artem Tevosyan. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | @IBOutlet weak var priceButton: UIButton! 14 | @IBOutlet weak var pageControl: UIPageControl! 15 | @IBOutlet weak var collectionView: UICollectionView! 16 | @IBOutlet weak var productSubtitleLabel: UILabel! 17 | @IBOutlet weak var productTitleLabel: UILabel! 18 | 19 | let images = [#imageLiteral(resourceName: "beats_image"), #imageLiteral(resourceName: "beats_headphone"), #imageLiteral(resourceName: "beats_headphones_white")] 20 | let titles = ["Beats Solo", "Beats X - White", "Beats Studio"] 21 | let subtitles = ["Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", "For most people, buying a new computer\ndoes not have to be as stressful as\n buying a new car.", "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."] 22 | let prices = ["$30.00", "$19.00", "$60.00"] 23 | 24 | let collectionViewCellHeightCoefficient: CGFloat = 0.85 25 | let collectionViewCellWidthCoefficient: CGFloat = 0.55 26 | let priceButtonCornerRadius: CGFloat = 10 27 | let gradientFirstColor = UIColor(hex: "ff8181").cgColor 28 | let gradientSecondColor = UIColor(hex: "a81382").cgColor 29 | let cellsShadowColor = UIColor(hex: "2a002a").cgColor 30 | let productCellIdentifier = "ProductCollectionViewCell" 31 | 32 | private var itemsNumber = 1000 33 | 34 | override func viewDidLoad() { 35 | super.viewDidLoad() 36 | 37 | configureCollectionView() 38 | configurePriceButton() 39 | } 40 | 41 | private func configureCollectionView() { 42 | let gravitySliderLayout = GravitySliderFlowLayout(with: CGSize(width: collectionView.frame.size.height * collectionViewCellWidthCoefficient, height: collectionView.frame.size.height * collectionViewCellHeightCoefficient)) 43 | collectionView.collectionViewLayout = gravitySliderLayout 44 | collectionView.dataSource = self 45 | collectionView.delegate = self 46 | } 47 | 48 | private func configurePriceButton() { 49 | priceButton.layer.cornerRadius = priceButtonCornerRadius 50 | } 51 | 52 | private func configureProductCell(_ cell: ProductCollectionViewCell, for indexPath: IndexPath) { 53 | cell.clipsToBounds = false 54 | let gradientLayer = CAGradientLayer() 55 | gradientLayer.frame = cell.bounds 56 | gradientLayer.colors = [gradientFirstColor, gradientSecondColor] 57 | gradientLayer.cornerRadius = 21 58 | gradientLayer.masksToBounds = true 59 | cell.layer.insertSublayer(gradientLayer, at: 0) 60 | 61 | cell.layer.shadowColor = cellsShadowColor 62 | cell.layer.shadowOpacity = 0.2 63 | cell.layer.shadowRadius = 20 64 | cell.layer.shadowOffset = CGSize(width: 0.0, height: 30) 65 | 66 | cell.productImage.image = images[indexPath.row % images.count] 67 | 68 | cell.newLabel.layer.cornerRadius = 8 69 | cell.newLabel.clipsToBounds = true 70 | cell.newLabel.layer.borderColor = UIColor.white.cgColor 71 | cell.newLabel.layer.borderWidth = 1.0 72 | } 73 | 74 | private func animateChangingTitle(for indexPath: IndexPath) { 75 | UIView.transition(with: productTitleLabel, duration: 0.3, options: .transitionCrossDissolve, animations: { 76 | self.productTitleLabel.text = self.titles[indexPath.row % self.titles.count] 77 | }, completion: nil) 78 | UIView.transition(with: productSubtitleLabel, duration: 0.3, options: .transitionCrossDissolve, animations: { 79 | self.productSubtitleLabel.text = self.subtitles[indexPath.row % self.subtitles.count] 80 | }, completion: nil) 81 | UIView.transition(with: priceButton, duration: 0.3, options: .transitionCrossDissolve, animations: { 82 | self.priceButton.setTitle(self.prices[indexPath.row % self.prices.count], for: .normal) 83 | }, completion: nil) 84 | } 85 | 86 | @IBAction func didPressPriceButton(_ sender: Any) { 87 | 88 | } 89 | 90 | } 91 | 92 | extension ViewController: UICollectionViewDataSource { 93 | func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 94 | return itemsNumber 95 | } 96 | 97 | func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 98 | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: productCellIdentifier, for: indexPath) as! ProductCollectionViewCell 99 | self.configureProductCell(cell, for: indexPath) 100 | return cell 101 | } 102 | 103 | 104 | } 105 | 106 | extension ViewController: UICollectionViewDelegate { 107 | func scrollViewDidScroll(_ scrollView: UIScrollView) { 108 | let locationFirst = CGPoint(x: collectionView.center.x + scrollView.contentOffset.x, y: collectionView.center.y + scrollView.contentOffset.y) 109 | let locationSecond = CGPoint(x: collectionView.center.x + scrollView.contentOffset.x + 20, y: collectionView.center.y + scrollView.contentOffset.y) 110 | let locationThird = CGPoint(x: collectionView.center.x + scrollView.contentOffset.x - 20, y: collectionView.center.y + scrollView.contentOffset.y) 111 | 112 | if let indexPathFirst = collectionView.indexPathForItem(at: locationFirst), let indexPathSecond = collectionView.indexPathForItem(at: locationSecond), let indexPathThird = collectionView.indexPathForItem(at: locationThird), indexPathFirst.row == indexPathSecond.row && indexPathSecond.row == indexPathThird.row && indexPathFirst.row != pageControl.currentPage { 113 | pageControl.currentPage = indexPathFirst.row % images.count 114 | self.animateChangingTitle(for: indexPathFirst) 115 | } 116 | } 117 | } 118 | 119 | -------------------------------------------------------------------------------- /GravitySliderFlowLayout.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # Be sure to run `pod lib lint GravitySliderFlowLayout.podspec' to ensure this is a 3 | # valid spec before submitting. 4 | # 5 | # Any lines starting with a # are optional, but their use is encouraged 6 | # To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html 7 | # 8 | 9 | Pod::Spec.new do |s| 10 | s.name = 'GravitySliderFlowLayout' 11 | s.version = '1.0' 12 | s.summary = 'GravitySlider is a beautiful alternative to the standard UICollectionView flow layout.' 13 | s.description = <<-DESC 14 | GravitySlider is a lightweight animation flowlayot for UICollectionView completely written in Swift 4, compatible with iOS 11 and xCode 9. 15 | DESC 16 | 17 | s.homepage = 'https://github.com/ApplikeySolutions/GravitySlider' 18 | s.license = { :type => 'MIT', :file => 'LICENSE' } 19 | s.author = { 'Applikey Solutions' => 'welcome@applikeysolutions.com' } 20 | s.source = { :git => 'https://github.com/AppliKeySolutions/GravitySlider.git', :tag => s.version.to_s } 21 | 22 | s.ios.deployment_target = '9.0' 23 | 24 | s.source_files = 'GravitySliderFlowLayout/Classes/**/*' 25 | 26 | end 27 | -------------------------------------------------------------------------------- /GravitySliderFlowLayout/Classes/GravitySliderFlowLayout.swift: -------------------------------------------------------------------------------- 1 | // 2 | // GravitySliderFlowLayout.swift 3 | // GravitySliderExample 4 | // 5 | // Created by Artem Tevosyan on 9/27/17. 6 | // Copyright © 2017 Artem Tevosyan. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | 12 | open class GravitySliderFlowLayout: UICollectionViewFlowLayout { 13 | 14 | let lineSpacingArgument: CGFloat = -2.5 15 | private var lastCollectionViewSize: CGSize = CGSize.zero 16 | private var period: CGFloat { return (collectionView?.bounds.width ?? 0) * 0.86 } 17 | 18 | public init(with itemSize: CGSize) { 19 | super.init() 20 | self.scrollDirection = .horizontal 21 | self.itemSize = itemSize 22 | self.minimumLineSpacing = itemSize.width / lineSpacingArgument 23 | } 24 | 25 | public required init?(coder aDecoder: NSCoder) { 26 | super.init(coder: aDecoder) 27 | } 28 | 29 | func setup(for scrollDirection: UICollectionViewScrollDirection, with collectionViewSize: CGSize) { 30 | guard collectionViewSize != lastCollectionViewSize else { return } 31 | self.lastCollectionViewSize = collectionViewSize 32 | self.scrollDirection = scrollDirection 33 | switch scrollDirection { 34 | case .horizontal: sectionInset = UIEdgeInsets(top: 0.0, left: collectionViewSize.width / 2 - itemSize.width / 2, bottom: 0.0, right: collectionViewSize.width / 2 - itemSize.width / 2) 35 | case .vertical: break 36 | } 37 | } 38 | 39 | override open func prepare() { 40 | super.prepare() 41 | guard let collectionView = self.collectionView else { return } 42 | self.setup(for: self.scrollDirection, with: collectionView.bounds.size) 43 | } 44 | 45 | override open func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { 46 | var targetRect = CGRect() 47 | switch scrollDirection { 48 | case .horizontal: 49 | targetRect.origin = CGPoint(x: rect.origin.x - rect.width / 2, y: rect.origin.y) 50 | targetRect.size = CGSize(width: rect.width * 2, height: rect.height) 51 | guard let collectionView = collectionView, let attributes = super.layoutAttributesForElements(in: targetRect) else { return nil } 52 | for attribute in attributes { 53 | let cellX = collectionView.convert(attribute.center, to: nil).x 54 | let difference = collectionView.center.x - cellX 55 | let zIndexValue = -pow(abs(difference)/collectionView.frame.size.width, 2.0) + 1.0 56 | let scaleFactor = -pow((difference / 1.8)/collectionView.frame.size.width * 2.0, 2.0) + 1.0 57 | 58 | let numPeriods = floor(Double(cellX / period)) 59 | let adjustment = CGFloat(numPeriods) * period 60 | let relativeDistanceFromCenter = collectionView.center.x - (cellX - adjustment) 61 | let centerProximityMagnitude = sinDistributor(x: cellX, period: period, xOffset: collectionView.center.x) 62 | 63 | var transform = CATransform3DIdentity 64 | transform = CATransform3DTranslate(transform, relativeDistanceFromCenter - adjustment + centerProximityMagnitude * itemSize.width*0.6, 0.0, 0.0) 65 | transform = CATransform3DScale(transform, scaleFactor, scaleFactor, 1.0) 66 | 67 | let distanceFromCenter = fabs(collectionView.center.x - cellX) 68 | attribute.alpha = sqrtDistributor(x: distanceFromCenter, threshold: period*0.5, xOrigin: period*0.6) 69 | attribute.zIndex = Int(zIndexValue * 1000) 70 | attribute.transform3D = transform 71 | } 72 | return attributes 73 | case .vertical: 74 | return nil 75 | } 76 | } 77 | 78 | override open func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool { 79 | return true 80 | } 81 | 82 | override open func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint, 83 | withScrollingVelocity velocity: CGPoint) -> CGPoint { 84 | guard let collectionView = collectionView else { return CGPoint.zero} 85 | let latestOffset = super.targetContentOffset(forProposedContentOffset: proposedContentOffset, withScrollingVelocity: velocity) 86 | switch scrollDirection { 87 | case .horizontal: 88 | let difference = collectionView.frame.size.width / 2 - sectionInset.left - itemSize.width/2 89 | let inset = collectionView.contentInset.left 90 | let row: CGFloat = ((latestOffset.x - inset + difference) / (itemSize.width + minimumLineSpacing)).rounded() 91 | let calculatedOffset = row * itemSize.width + row * minimumLineSpacing + inset 92 | let targetOffset = CGPoint(x: ((row == 0 && proposedContentOffset.x < (calculatedOffset - difference)) || ((Int(row) == 93 | collectionView.numberOfItems(inSection: 0) - 1) && proposedContentOffset.x > (calculatedOffset - difference) )) ? 94 | proposedContentOffset.x : calculatedOffset - difference, y: latestOffset.y) 95 | return targetOffset 96 | case .vertical: 97 | return CGPoint.zero 98 | } 99 | } 100 | 101 | /** 102 | Distribution function that start as a square root function and levels off when reaches y = 1. 103 | - parameter x: X parameter of the function. Current layout implementation uses center.x coordinate of collectionView cells. 104 | - parameter threshold: The x coordinate where function gets value 1. 105 | - parameter xOrigin: x coordinate of the function origin. 106 | */ 107 | private func sqrtDistributor(x: CGFloat, threshold: CGFloat, xOrigin: CGFloat) -> CGFloat { 108 | var arg = (x - xOrigin)/(threshold - xOrigin) 109 | arg = arg <= 0 ? 0 : arg 110 | let y = sqrt(arg) 111 | return y > 1 ? 1 : y 112 | } 113 | 114 | /** 115 | - parameter x: X parameter of the function. Current layout implementation uses center.x coordinate of collectionView cells. 116 | - parameter period: The period of the function. 117 | - parameter xOffset: x coordinate where the function crosses 0 coordinate. 118 | */ 119 | private func sinDistributor(x: CGFloat, period: CGFloat, xOffset: CGFloat) -> CGFloat { 120 | let halfPeriod = period / 2 121 | return sin(x/(halfPeriod / CGFloat.pi) - xOffset/(halfPeriod / CGFloat.pi)) 122 | } 123 | } 124 | 125 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017 Applikey Solutions 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GravitySliderFlowLayout 2 | 3 | [![Version](https://img.shields.io/cocoapods/v/GravitySliderFlowLayout.svg?style=flat)](http://cocoapods.org/pods/GravitySliderFlowLayout) 4 | [![License](https://img.shields.io/cocoapods/l/GravitySliderFlowLayout.svg?style=flat)](http://cocoapods.org/pods/GravitySliderFlowLayout) 5 | [![Platform](https://img.shields.io/cocoapods/p/GravitySliderFlowLayout.svg?style=flat)](http://cocoapods.org/pods/GravitySliderFlowLayout) 6 | [![Twitter](https://img.shields.io/badge/contact-@Applikey_-blue.svg?style=flat)](https://twitter.com/Applikey_) 7 | ![Swift 3.0.x](https://img.shields.io/badge/Swift-3.0.x-orange.svg) 8 | 9 | Made by [Applikey Solutions](https://applikeysolutions.com) 10 | 11 | Find this [project on Dribbble](https://dribbble.com/shots/3845707-Gravity-Slider) 12 | 13 | ![GravitySliderFlowLayout](https://f.flockusercontent2.com/544bebf15076470414771a9d) 14 | 15 | # Table of Contents 16 | 1. [Purpose](#purpose) 17 | 2. [Supported OS & SDK Versions](#supported-os--sdk-versions) 18 | 3. [Installation](#installation) 19 | 4. [Usage](#usage) 20 | 5. [Demo](#demo) 21 | 6. [Release Notes](#release-notes) 22 | 7. [Contact Us](#contact-us) 23 | 8. [License](#license) 24 | 25 | # Purpose 26 | 27 | GravitySlider is a lightweight animation flowlayot for UICollectionView completely written in Swift 4, compatible with iOS 11 and xCode 9. 28 | 29 | 30 | # Supported OS & SDK Versions 31 | 32 | * Supported build target - iOS 9.0 33 | 34 | ## Installation 35 | 36 | GravitySliderFlowLayout is available through [CocoaPods](http://cocoapods.org). To install 37 | it, simply add the following line to your Podfile: 38 | 39 | ```ruby 40 | pod 'GravitySliderFlowLayout' 41 | ``` 42 | 43 | # Usage 44 | 45 | ```swift 46 | import GravitySliderFlowLayout 47 | 48 | let gravitySliderLayout = GravitySliderFlowLayout(with: CGSize(width: 50, height: 50)) 49 | collectionView.collectionViewLayout = gravitySliderLayout 50 | ``` 51 | 52 | # Demo 53 | ![example-plain](https://f.flockusercontent2.com/544bebf15076462334a6c0f7) 54 | 55 | # Release Notes 56 | 57 | Version 1.0 58 | 59 | - Release version. 60 | 61 | # Contact Us 62 | 63 | You can always contact us via github@applikeysolutions.com We are open for any inquiries regarding our libraries and controls, new open-source projects and other ways of contributing to the community. If you have used our component in your project we would be extremely happy if you write us your feedback and let us know about it! 64 | 65 | # License 66 | 67 | The MIT License (MIT) 68 | 69 | Copyright © 2017 Applikey Solutions 70 | 71 | Permission is hereby granted free of charge to any person obtaining a copy of this software and associated documentation files (the "Software") to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 72 | 73 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 74 | 75 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 76 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 77 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 78 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 79 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 80 | THE SOFTWARE. 81 | 82 | --------------------------------------------------------------------------------