├── .gitignore ├── AwsomeLayout.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── AwsomeLayout ├── AppDelegate.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Controller │ └── ViewController.swift ├── Info.plist └── Layouts │ └── CardLayout.swift └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | #Pods/ 27 | -------------------------------------------------------------------------------- /AwsomeLayout.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 743C4F6E1E67CEF3000A7E8F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 743C4F6D1E67CEF3000A7E8F /* AppDelegate.swift */; }; 11 | 743C4F701E67CEF3000A7E8F /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 743C4F6F1E67CEF3000A7E8F /* ViewController.swift */; }; 12 | 743C4F731E67CEF3000A7E8F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 743C4F711E67CEF3000A7E8F /* Main.storyboard */; }; 13 | 743C4F751E67CEF3000A7E8F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 743C4F741E67CEF3000A7E8F /* Assets.xcassets */; }; 14 | 743C4F781E67CEF3000A7E8F /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 743C4F761E67CEF3000A7E8F /* LaunchScreen.storyboard */; }; 15 | 743C4F801E67CF1F000A7E8F /* CardLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 743C4F7F1E67CF1F000A7E8F /* CardLayout.swift */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | 743C4F6A1E67CEF3000A7E8F /* AwsomeLayout.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AwsomeLayout.app; sourceTree = BUILT_PRODUCTS_DIR; }; 20 | 743C4F6D1E67CEF3000A7E8F /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 21 | 743C4F6F1E67CEF3000A7E8F /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 22 | 743C4F721E67CEF3000A7E8F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 23 | 743C4F741E67CEF3000A7E8F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 24 | 743C4F771E67CEF3000A7E8F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 25 | 743C4F791E67CEF3000A7E8F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 26 | 743C4F7F1E67CF1F000A7E8F /* CardLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CardLayout.swift; sourceTree = ""; }; 27 | /* End PBXFileReference section */ 28 | 29 | /* Begin PBXFrameworksBuildPhase section */ 30 | 743C4F671E67CEF3000A7E8F /* Frameworks */ = { 31 | isa = PBXFrameworksBuildPhase; 32 | buildActionMask = 2147483647; 33 | files = ( 34 | ); 35 | runOnlyForDeploymentPostprocessing = 0; 36 | }; 37 | /* End PBXFrameworksBuildPhase section */ 38 | 39 | /* Begin PBXGroup section */ 40 | 7417B55A1E7597B400BDC7F7 /* Controller */ = { 41 | isa = PBXGroup; 42 | children = ( 43 | 743C4F6F1E67CEF3000A7E8F /* ViewController.swift */, 44 | ); 45 | path = Controller; 46 | sourceTree = ""; 47 | }; 48 | 7417B55B1E7597B400BDC7F7 /* View */ = { 49 | isa = PBXGroup; 50 | children = ( 51 | ); 52 | path = View; 53 | sourceTree = ""; 54 | }; 55 | 7417B55C1E7597B400BDC7F7 /* Model */ = { 56 | isa = PBXGroup; 57 | children = ( 58 | ); 59 | path = Model; 60 | sourceTree = ""; 61 | }; 62 | 7417B55D1E7597B400BDC7F7 /* Layouts */ = { 63 | isa = PBXGroup; 64 | children = ( 65 | 743C4F7F1E67CF1F000A7E8F /* CardLayout.swift */, 66 | ); 67 | path = Layouts; 68 | sourceTree = ""; 69 | }; 70 | 7417B55E1E75980E00BDC7F7 /* Support */ = { 71 | isa = PBXGroup; 72 | children = ( 73 | 743C4F711E67CEF3000A7E8F /* Main.storyboard */, 74 | 743C4F741E67CEF3000A7E8F /* Assets.xcassets */, 75 | 743C4F761E67CEF3000A7E8F /* LaunchScreen.storyboard */, 76 | 743C4F791E67CEF3000A7E8F /* Info.plist */, 77 | ); 78 | name = Support; 79 | sourceTree = ""; 80 | }; 81 | 7417B55F1E75983C00BDC7F7 /* Demo */ = { 82 | isa = PBXGroup; 83 | children = ( 84 | 743C4F6D1E67CEF3000A7E8F /* AppDelegate.swift */, 85 | 7417B55A1E7597B400BDC7F7 /* Controller */, 86 | 7417B55B1E7597B400BDC7F7 /* View */, 87 | 7417B55C1E7597B400BDC7F7 /* Model */, 88 | ); 89 | name = Demo; 90 | sourceTree = ""; 91 | }; 92 | 743C4F611E67CEF3000A7E8F = { 93 | isa = PBXGroup; 94 | children = ( 95 | 743C4F6C1E67CEF3000A7E8F /* AwsomeLayout */, 96 | 743C4F6B1E67CEF3000A7E8F /* Products */, 97 | ); 98 | sourceTree = ""; 99 | }; 100 | 743C4F6B1E67CEF3000A7E8F /* Products */ = { 101 | isa = PBXGroup; 102 | children = ( 103 | 743C4F6A1E67CEF3000A7E8F /* AwsomeLayout.app */, 104 | ); 105 | name = Products; 106 | sourceTree = ""; 107 | }; 108 | 743C4F6C1E67CEF3000A7E8F /* AwsomeLayout */ = { 109 | isa = PBXGroup; 110 | children = ( 111 | 7417B55F1E75983C00BDC7F7 /* Demo */, 112 | 7417B55D1E7597B400BDC7F7 /* Layouts */, 113 | 7417B55E1E75980E00BDC7F7 /* Support */, 114 | ); 115 | path = AwsomeLayout; 116 | sourceTree = ""; 117 | }; 118 | /* End PBXGroup section */ 119 | 120 | /* Begin PBXNativeTarget section */ 121 | 743C4F691E67CEF3000A7E8F /* AwsomeLayout */ = { 122 | isa = PBXNativeTarget; 123 | buildConfigurationList = 743C4F7C1E67CEF3000A7E8F /* Build configuration list for PBXNativeTarget "AwsomeLayout" */; 124 | buildPhases = ( 125 | 743C4F661E67CEF3000A7E8F /* Sources */, 126 | 743C4F671E67CEF3000A7E8F /* Frameworks */, 127 | 743C4F681E67CEF3000A7E8F /* Resources */, 128 | ); 129 | buildRules = ( 130 | ); 131 | dependencies = ( 132 | ); 133 | name = AwsomeLayout; 134 | productName = CardLayout; 135 | productReference = 743C4F6A1E67CEF3000A7E8F /* AwsomeLayout.app */; 136 | productType = "com.apple.product-type.application"; 137 | }; 138 | /* End PBXNativeTarget section */ 139 | 140 | /* Begin PBXProject section */ 141 | 743C4F621E67CEF3000A7E8F /* Project object */ = { 142 | isa = PBXProject; 143 | attributes = { 144 | LastSwiftUpdateCheck = 0810; 145 | LastUpgradeCheck = 0820; 146 | ORGANIZATIONNAME = "陈凯"; 147 | TargetAttributes = { 148 | 743C4F691E67CEF3000A7E8F = { 149 | CreatedOnToolsVersion = 8.1; 150 | DevelopmentTeam = 6QEB559EPD; 151 | ProvisioningStyle = Automatic; 152 | }; 153 | }; 154 | }; 155 | buildConfigurationList = 743C4F651E67CEF3000A7E8F /* Build configuration list for PBXProject "AwsomeLayout" */; 156 | compatibilityVersion = "Xcode 3.2"; 157 | developmentRegion = English; 158 | hasScannedForEncodings = 0; 159 | knownRegions = ( 160 | en, 161 | Base, 162 | ); 163 | mainGroup = 743C4F611E67CEF3000A7E8F; 164 | productRefGroup = 743C4F6B1E67CEF3000A7E8F /* Products */; 165 | projectDirPath = ""; 166 | projectRoot = ""; 167 | targets = ( 168 | 743C4F691E67CEF3000A7E8F /* AwsomeLayout */, 169 | ); 170 | }; 171 | /* End PBXProject section */ 172 | 173 | /* Begin PBXResourcesBuildPhase section */ 174 | 743C4F681E67CEF3000A7E8F /* Resources */ = { 175 | isa = PBXResourcesBuildPhase; 176 | buildActionMask = 2147483647; 177 | files = ( 178 | 743C4F781E67CEF3000A7E8F /* LaunchScreen.storyboard in Resources */, 179 | 743C4F751E67CEF3000A7E8F /* Assets.xcassets in Resources */, 180 | 743C4F731E67CEF3000A7E8F /* Main.storyboard in Resources */, 181 | ); 182 | runOnlyForDeploymentPostprocessing = 0; 183 | }; 184 | /* End PBXResourcesBuildPhase section */ 185 | 186 | /* Begin PBXSourcesBuildPhase section */ 187 | 743C4F661E67CEF3000A7E8F /* Sources */ = { 188 | isa = PBXSourcesBuildPhase; 189 | buildActionMask = 2147483647; 190 | files = ( 191 | 743C4F701E67CEF3000A7E8F /* ViewController.swift in Sources */, 192 | 743C4F801E67CF1F000A7E8F /* CardLayout.swift in Sources */, 193 | 743C4F6E1E67CEF3000A7E8F /* AppDelegate.swift in Sources */, 194 | ); 195 | runOnlyForDeploymentPostprocessing = 0; 196 | }; 197 | /* End PBXSourcesBuildPhase section */ 198 | 199 | /* Begin PBXVariantGroup section */ 200 | 743C4F711E67CEF3000A7E8F /* Main.storyboard */ = { 201 | isa = PBXVariantGroup; 202 | children = ( 203 | 743C4F721E67CEF3000A7E8F /* Base */, 204 | ); 205 | name = Main.storyboard; 206 | sourceTree = ""; 207 | }; 208 | 743C4F761E67CEF3000A7E8F /* LaunchScreen.storyboard */ = { 209 | isa = PBXVariantGroup; 210 | children = ( 211 | 743C4F771E67CEF3000A7E8F /* Base */, 212 | ); 213 | name = LaunchScreen.storyboard; 214 | sourceTree = ""; 215 | }; 216 | /* End PBXVariantGroup section */ 217 | 218 | /* Begin XCBuildConfiguration section */ 219 | 743C4F7A1E67CEF3000A7E8F /* Debug */ = { 220 | isa = XCBuildConfiguration; 221 | buildSettings = { 222 | ALWAYS_SEARCH_USER_PATHS = NO; 223 | CLANG_ANALYZER_NONNULL = YES; 224 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 225 | CLANG_CXX_LIBRARY = "libc++"; 226 | CLANG_ENABLE_MODULES = YES; 227 | CLANG_ENABLE_OBJC_ARC = YES; 228 | CLANG_WARN_BOOL_CONVERSION = YES; 229 | CLANG_WARN_CONSTANT_CONVERSION = YES; 230 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 231 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 232 | CLANG_WARN_EMPTY_BODY = YES; 233 | CLANG_WARN_ENUM_CONVERSION = YES; 234 | CLANG_WARN_INFINITE_RECURSION = YES; 235 | CLANG_WARN_INT_CONVERSION = YES; 236 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 237 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 238 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 239 | CLANG_WARN_UNREACHABLE_CODE = YES; 240 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 241 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 242 | COPY_PHASE_STRIP = NO; 243 | DEBUG_INFORMATION_FORMAT = dwarf; 244 | ENABLE_STRICT_OBJC_MSGSEND = YES; 245 | ENABLE_TESTABILITY = YES; 246 | GCC_C_LANGUAGE_STANDARD = gnu99; 247 | GCC_DYNAMIC_NO_PIC = NO; 248 | GCC_NO_COMMON_BLOCKS = YES; 249 | GCC_OPTIMIZATION_LEVEL = 0; 250 | GCC_PREPROCESSOR_DEFINITIONS = ( 251 | "DEBUG=1", 252 | "$(inherited)", 253 | ); 254 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 255 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 256 | GCC_WARN_UNDECLARED_SELECTOR = YES; 257 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 258 | GCC_WARN_UNUSED_FUNCTION = YES; 259 | GCC_WARN_UNUSED_VARIABLE = YES; 260 | IPHONEOS_DEPLOYMENT_TARGET = 10.1; 261 | MTL_ENABLE_DEBUG_INFO = YES; 262 | ONLY_ACTIVE_ARCH = YES; 263 | SDKROOT = iphoneos; 264 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 265 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 266 | TARGETED_DEVICE_FAMILY = "1,2"; 267 | }; 268 | name = Debug; 269 | }; 270 | 743C4F7B1E67CEF3000A7E8F /* Release */ = { 271 | isa = XCBuildConfiguration; 272 | buildSettings = { 273 | ALWAYS_SEARCH_USER_PATHS = NO; 274 | CLANG_ANALYZER_NONNULL = YES; 275 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 276 | CLANG_CXX_LIBRARY = "libc++"; 277 | CLANG_ENABLE_MODULES = YES; 278 | CLANG_ENABLE_OBJC_ARC = YES; 279 | CLANG_WARN_BOOL_CONVERSION = YES; 280 | CLANG_WARN_CONSTANT_CONVERSION = YES; 281 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 282 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 283 | CLANG_WARN_EMPTY_BODY = YES; 284 | CLANG_WARN_ENUM_CONVERSION = YES; 285 | CLANG_WARN_INFINITE_RECURSION = YES; 286 | CLANG_WARN_INT_CONVERSION = YES; 287 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 288 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 289 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 290 | CLANG_WARN_UNREACHABLE_CODE = YES; 291 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 292 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 293 | COPY_PHASE_STRIP = NO; 294 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 295 | ENABLE_NS_ASSERTIONS = NO; 296 | ENABLE_STRICT_OBJC_MSGSEND = YES; 297 | GCC_C_LANGUAGE_STANDARD = gnu99; 298 | GCC_NO_COMMON_BLOCKS = YES; 299 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 300 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 301 | GCC_WARN_UNDECLARED_SELECTOR = YES; 302 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 303 | GCC_WARN_UNUSED_FUNCTION = YES; 304 | GCC_WARN_UNUSED_VARIABLE = YES; 305 | IPHONEOS_DEPLOYMENT_TARGET = 10.1; 306 | MTL_ENABLE_DEBUG_INFO = NO; 307 | SDKROOT = iphoneos; 308 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 309 | TARGETED_DEVICE_FAMILY = "1,2"; 310 | VALIDATE_PRODUCT = YES; 311 | }; 312 | name = Release; 313 | }; 314 | 743C4F7D1E67CEF3000A7E8F /* Debug */ = { 315 | isa = XCBuildConfiguration; 316 | buildSettings = { 317 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 318 | DEVELOPMENT_TEAM = 6QEB559EPD; 319 | INFOPLIST_FILE = AwsomeLayout/Info.plist; 320 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 321 | PRODUCT_BUNDLE_IDENTIFIER = com.MrChen.CardLayout; 322 | PRODUCT_NAME = "$(TARGET_NAME)"; 323 | SWIFT_VERSION = 3.0; 324 | }; 325 | name = Debug; 326 | }; 327 | 743C4F7E1E67CEF3000A7E8F /* Release */ = { 328 | isa = XCBuildConfiguration; 329 | buildSettings = { 330 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 331 | DEVELOPMENT_TEAM = 6QEB559EPD; 332 | INFOPLIST_FILE = AwsomeLayout/Info.plist; 333 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 334 | PRODUCT_BUNDLE_IDENTIFIER = com.MrChen.CardLayout; 335 | PRODUCT_NAME = "$(TARGET_NAME)"; 336 | SWIFT_VERSION = 3.0; 337 | }; 338 | name = Release; 339 | }; 340 | /* End XCBuildConfiguration section */ 341 | 342 | /* Begin XCConfigurationList section */ 343 | 743C4F651E67CEF3000A7E8F /* Build configuration list for PBXProject "AwsomeLayout" */ = { 344 | isa = XCConfigurationList; 345 | buildConfigurations = ( 346 | 743C4F7A1E67CEF3000A7E8F /* Debug */, 347 | 743C4F7B1E67CEF3000A7E8F /* Release */, 348 | ); 349 | defaultConfigurationIsVisible = 0; 350 | defaultConfigurationName = Release; 351 | }; 352 | 743C4F7C1E67CEF3000A7E8F /* Build configuration list for PBXNativeTarget "AwsomeLayout" */ = { 353 | isa = XCConfigurationList; 354 | buildConfigurations = ( 355 | 743C4F7D1E67CEF3000A7E8F /* Debug */, 356 | 743C4F7E1E67CEF3000A7E8F /* Release */, 357 | ); 358 | defaultConfigurationIsVisible = 0; 359 | defaultConfigurationName = Release; 360 | }; 361 | /* End XCConfigurationList section */ 362 | }; 363 | rootObject = 743C4F621E67CEF3000A7E8F /* Project object */; 364 | } 365 | -------------------------------------------------------------------------------- /AwsomeLayout.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /AwsomeLayout/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // AwsomeLayout 4 | // 5 | // Created by 陈凯 on 2017/3/2. 6 | // Copyright © 2017年 陈凯. 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 invalidate graphics rendering callbacks. 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 active 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 | -------------------------------------------------------------------------------- /AwsomeLayout/Assets.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 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /AwsomeLayout/Base.lproj/LaunchScreen.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 | -------------------------------------------------------------------------------- /AwsomeLayout/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 | -------------------------------------------------------------------------------- /AwsomeLayout/Controller/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // AwsomeLayout 4 | // 5 | // Created by 陈凯 on 2017/3/2. 6 | // Copyright © 2017年 陈凯. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | var collectionView: UICollectionView! 14 | 15 | override func viewDidLoad() { 16 | super.viewDidLoad() 17 | 18 | let layout = CardLayout() 19 | layout.scale = 1.1 20 | layout.itemSize = CGSize(width: 200, height: 300) 21 | 22 | collectionView = UICollectionView(frame: view.bounds, collectionViewLayout: layout) 23 | collectionView.backgroundColor = .white 24 | collectionView.dataSource = self 25 | collectionView.showsVerticalScrollIndicator = false 26 | collectionView.showsHorizontalScrollIndicator = false 27 | collectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "CellID") 28 | view.addSubview(collectionView) 29 | } 30 | 31 | override func viewDidLayoutSubviews() { 32 | super.viewDidLayoutSubviews() 33 | 34 | collectionView.frame = view.bounds 35 | } 36 | 37 | override var prefersStatusBarHidden: Bool { 38 | return true 39 | } 40 | } 41 | 42 | extension ViewController: UICollectionViewDataSource { 43 | 44 | func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 45 | return 10 46 | } 47 | 48 | func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 49 | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CellID", for: indexPath) 50 | cell.layer.cornerRadius = 5 51 | cell.backgroundColor = UIColor(white: 0.8, alpha: 1)//indexPath.item%2==0 ? UIColor(white: 0.8, alpha: 1) : UIColor(white: 0.6, alpha: 1) 52 | return cell 53 | } 54 | 55 | } 56 | 57 | -------------------------------------------------------------------------------- /AwsomeLayout/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 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /AwsomeLayout/Layouts/CardLayout.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CardLayout.swift 3 | // AwsomeLayout 4 | // 5 | // Created by 陈凯 on 2017/3/2. 6 | // Copyright © 2017年 陈凯. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class CardLayout: UICollectionViewLayout { 12 | 13 | var itemSize: CGSize = CGSize(width: 280, height: 400) { 14 | 15 | didSet { 16 | if itemSize != oldValue { 17 | invalidateLayout() 18 | } 19 | } 20 | } 21 | 22 | var spacing: CGFloat = 20.0 { 23 | didSet { 24 | if spacing != oldValue { 25 | invalidateLayout() 26 | } 27 | } 28 | } 29 | 30 | var scale: CGFloat = 1.0 { 31 | didSet { 32 | if scale != oldValue { 33 | invalidateLayout() 34 | } 35 | } 36 | } 37 | 38 | var edgeInset: UIEdgeInsets = UIEdgeInsetsMake(20, 20, 20, 20) { 39 | didSet { 40 | if edgeInset != oldValue { 41 | invalidateLayout() 42 | } 43 | } 44 | } 45 | 46 | var scrollDirection: UICollectionViewScrollDirection = .horizontal { 47 | didSet { 48 | if scrollDirection != oldValue { 49 | invalidateLayout() 50 | } 51 | } 52 | } 53 | 54 | private var rectAttributes:[UICollectionViewLayoutAttributes] = []; 55 | 56 | override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool { 57 | return true 58 | } 59 | 60 | override var collectionViewContentSize: CGSize { 61 | 62 | guard let collectionView = collectionView else { 63 | return .zero 64 | } 65 | let count = collectionView.numberOfItems(inSection: 0) 66 | 67 | var width, height: CGFloat 68 | switch scrollDirection { 69 | case .horizontal: 70 | width = CGFloat(count)*(itemSize.width+spacing)-spacing+edgeInset.left+edgeInset.right 71 | height = collectionView.bounds.height 72 | 73 | case .vertical: 74 | width = collectionView.bounds.width 75 | height = CGFloat(count)*(itemSize.height+spacing)-spacing+edgeInset.top+edgeInset.bottom 76 | } 77 | return CGSize(width: width, height: height) 78 | } 79 | 80 | override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? { 81 | 82 | guard let collectionView = collectionView else { 83 | return nil 84 | } 85 | 86 | let attribute = UICollectionViewLayoutAttributes(forCellWith: indexPath) 87 | attribute.size = itemSize 88 | 89 | var x, y:CGFloat 90 | switch scrollDirection { 91 | case .horizontal: 92 | x = edgeInset.left + CGFloat(indexPath.item)*(itemSize.width+spacing) 93 | y = 0.5*(collectionView.bounds.height - itemSize.height) 94 | 95 | case .vertical: 96 | x = 0.5*(collectionView.bounds.width - itemSize.width) 97 | y = edgeInset.top + CGFloat(indexPath.item)*(itemSize.height+spacing) 98 | } 99 | attribute.frame = CGRect(origin: CGPoint(x:x, y:y), size: itemSize) 100 | return attribute 101 | } 102 | 103 | override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { 104 | 105 | guard let collectionView = collectionView else { 106 | return nil 107 | } 108 | 109 | let attributes = self.attributes(in: rect) 110 | 111 | var scale, offset, deno: CGFloat 112 | switch scrollDirection { 113 | case .horizontal: 114 | let centerX = collectionView.contentOffset.x+0.5*collectionView.bounds.width 115 | for attribute in attributes { 116 | offset = abs(attribute.center.x - centerX) 117 | deno = itemSize.width+spacing 118 | if offset CGPoint { 141 | 142 | guard let collectionView = collectionView else { 143 | return proposedContentOffset 144 | } 145 | 146 | let rect = CGRect(x: proposedContentOffset.x, y: proposedContentOffset.y, width: collectionView.bounds.width, height: collectionView.bounds.height) 147 | guard let attributes = layoutAttributesForElements(in: rect) else { 148 | return proposedContentOffset 149 | } 150 | 151 | switch scrollDirection { 152 | case .horizontal: 153 | let centerX = proposedContentOffset.x+0.5*collectionView.bounds.width 154 | var minOffsetX = CGFloat(Int.max) 155 | for attribute in attributes { 156 | let offsetX = attribute.center.x-centerX 157 | if abs(offsetX) [UICollectionViewLayoutAttributes] { 177 | 178 | guard let collectionView = collectionView else { 179 | return [] 180 | } 181 | 182 | let itemCount = collectionView.numberOfItems(inSection: 0) 183 | var preIndex, latIndex: Int; 184 | switch scrollDirection { 185 | case .horizontal: 186 | preIndex = Int((rect.origin.x-edgeInset.left)/(itemSize.width+spacing)) 187 | latIndex = Int((rect.maxX-edgeInset.left)/(itemSize.width+spacing)) 188 | 189 | case .vertical: 190 | preIndex = Int((rect.origin.y-edgeInset.top)/(itemSize.height+spacing)) 191 | latIndex = Int((rect.maxY-edgeInset.top)/(itemSize.height+spacing)) 192 | } 193 | preIndex = preIndex<0 ? 0 : preIndex 194 | preIndex = preIndex>=itemCount ? itemCount-1 : preIndex 195 | latIndex = latIndex>=itemCount ? itemCount-1 : latIndex 196 | 197 | rectAttributes.removeAll() 198 | for i in preIndex...latIndex { 199 | let indexPath = IndexPath(item: i, section: 0) 200 | let attribute = layoutAttributesForItem(at: indexPath) 201 | if rect.intersects(attribute!.frame) { 202 | rectAttributes.append(attribute!) 203 | } 204 | } 205 | 206 | return rectAttributes; 207 | } 208 | 209 | } 210 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## 卡片布局,支持水平、垂直滚动。OC版本请[点击这里](https://github.com/Pr-Chen/CardLayout-OC) 2 | ![](https://ww3.sinaimg.cn/large/006tNbRwly1fd8xu377fng305k09vdo5.gif) 3 | ![](https://ww2.sinaimg.cn/large/006tNbRwly1fd8xu51jf4g305k09vq9x.gif) 4 | ![](https://ww4.sinaimg.cn/large/006tNbRwly1fd8xug0iejg305k09vdu7.gif) 5 | ![](https://ww4.sinaimg.cn/large/006tNbRwly1fd8xuimwh4g305k09vn64.gif) 6 | 7 | ## 用法简单 8 | ```swift 9 | let layout = CardLayout() 10 | let collectionView = UICollectionView(frame: view.bounds, collectionViewLayout: layout) 11 | ``` 12 | 13 | ## 可以设置的属性 14 | ```swift 15 | //cell的尺寸 16 | var itemSize: CGSize 17 | 18 | //cell间距 19 | var spacing: CGFloat 20 | 21 | //缩放率 22 | var scale: CGFloat 23 | 24 | //边距 25 | var edgeInset: UIEdgeInsets 26 | 27 | //滚动方向 28 | var scrollDirection: UICollectionViewScrollDirection 29 | 30 | ``` 31 | --------------------------------------------------------------------------------