├── .gitignore ├── CardView ├── CardView.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata └── CardView │ ├── AppDelegate.swift │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ ├── design │ │ ├── Contents.json │ │ ├── img_00.imageset │ │ │ ├── Contents.json │ │ │ └── img_00.png │ │ ├── img_01.imageset │ │ │ ├── Contents.json │ │ │ └── img_01.png │ │ ├── img_02.imageset │ │ │ ├── Contents.json │ │ │ └── img_02.png │ │ ├── img_03.imageset │ │ │ ├── Contents.json │ │ │ └── img_03.png │ │ ├── img_04.imageset │ │ │ ├── Contents.json │ │ │ └── img_04.png │ │ └── img_05.imageset │ │ │ ├── Contents.json │ │ │ └── img_05.png │ ├── me.imageset │ │ ├── Contents.json │ │ └── me-1.png │ └── start_button.imageset │ │ ├── Contents.json │ │ ├── start_button@2x.png │ │ └── start_button@3x.png │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── CardView │ ├── CardItem.swift │ ├── CardView.swift │ └── ImageCardItem.swift │ ├── Info.plist │ └── ViewController.swift ├── LICENSE ├── README.md └── cardView.gif /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xccheckout 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | ## Playgrounds 32 | timeline.xctimeline 33 | playground.xcworkspace 34 | 35 | # Swift Package Manager 36 | # 37 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 38 | # Packages/ 39 | # Package.pins 40 | .build/ 41 | 42 | # CocoaPods 43 | # 44 | # We recommend against adding the Pods directory to your .gitignore. However 45 | # you should judge for yourself, the pros and cons are mentioned at: 46 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 47 | # 48 | # Pods/ 49 | 50 | # Carthage 51 | # 52 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 53 | # Carthage/Checkouts 54 | 55 | Carthage/Build 56 | 57 | # fastlane 58 | # 59 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 60 | # screenshots whenever they are needed. 61 | # For more information about the recommended setup visit: 62 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 63 | 64 | fastlane/report.xml 65 | fastlane/Preview.html 66 | fastlane/screenshots 67 | fastlane/test_output 68 | -------------------------------------------------------------------------------- /CardView/CardView.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 48; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 142AF0BF201E127C0084D736 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 142AF0BE201E127C0084D736 /* Assets.xcassets */; }; 11 | 5FA0E5C1201C477D0057C84E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FA0E5C0201C477D0057C84E /* AppDelegate.swift */; }; 12 | 5FA0E5C3201C477D0057C84E /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FA0E5C2201C477D0057C84E /* ViewController.swift */; }; 13 | 5FA0E5C6201C477D0057C84E /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5FA0E5C4201C477D0057C84E /* Main.storyboard */; }; 14 | 5FA0E5CB201C477D0057C84E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5FA0E5C9201C477D0057C84E /* LaunchScreen.storyboard */; }; 15 | 5FA0E5D4201C47B50057C84E /* CardItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FA0E5D3201C47B50057C84E /* CardItem.swift */; }; 16 | 5FA0E5D6201C4FD60057C84E /* CardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FA0E5D5201C4FD60057C84E /* CardView.swift */; }; 17 | 5FA0E5D8201C64760057C84E /* ImageCardItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FA0E5D7201C64760057C84E /* ImageCardItem.swift */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXFileReference section */ 21 | 142AF0BE201E127C0084D736 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 22 | 5FA0E5BD201C477D0057C84E /* CardView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CardView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 23 | 5FA0E5C0201C477D0057C84E /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 24 | 5FA0E5C2201C477D0057C84E /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 25 | 5FA0E5C5201C477D0057C84E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 26 | 5FA0E5CA201C477D0057C84E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 27 | 5FA0E5CC201C477D0057C84E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 28 | 5FA0E5D3201C47B50057C84E /* CardItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardItem.swift; sourceTree = ""; }; 29 | 5FA0E5D5201C4FD60057C84E /* CardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardView.swift; sourceTree = ""; }; 30 | 5FA0E5D7201C64760057C84E /* ImageCardItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageCardItem.swift; sourceTree = ""; }; 31 | /* End PBXFileReference section */ 32 | 33 | /* Begin PBXFrameworksBuildPhase section */ 34 | 5FA0E5BA201C477D0057C84E /* Frameworks */ = { 35 | isa = PBXFrameworksBuildPhase; 36 | buildActionMask = 2147483647; 37 | files = ( 38 | ); 39 | runOnlyForDeploymentPostprocessing = 0; 40 | }; 41 | /* End PBXFrameworksBuildPhase section */ 42 | 43 | /* Begin PBXGroup section */ 44 | 5FA0E5B4201C477D0057C84E = { 45 | isa = PBXGroup; 46 | children = ( 47 | 5FA0E5BF201C477D0057C84E /* CardView */, 48 | 5FA0E5BE201C477D0057C84E /* Products */, 49 | ); 50 | sourceTree = ""; 51 | }; 52 | 5FA0E5BE201C477D0057C84E /* Products */ = { 53 | isa = PBXGroup; 54 | children = ( 55 | 5FA0E5BD201C477D0057C84E /* CardView.app */, 56 | ); 57 | name = Products; 58 | sourceTree = ""; 59 | }; 60 | 5FA0E5BF201C477D0057C84E /* CardView */ = { 61 | isa = PBXGroup; 62 | children = ( 63 | 5FA0E5D2201C478D0057C84E /* CardView */, 64 | 5FA0E5C0201C477D0057C84E /* AppDelegate.swift */, 65 | 5FA0E5C2201C477D0057C84E /* ViewController.swift */, 66 | 142AF0BE201E127C0084D736 /* Assets.xcassets */, 67 | 5FA0E5C4201C477D0057C84E /* Main.storyboard */, 68 | 5FA0E5C9201C477D0057C84E /* LaunchScreen.storyboard */, 69 | 5FA0E5CC201C477D0057C84E /* Info.plist */, 70 | ); 71 | path = CardView; 72 | sourceTree = ""; 73 | }; 74 | 5FA0E5D2201C478D0057C84E /* CardView */ = { 75 | isa = PBXGroup; 76 | children = ( 77 | 5FA0E5D3201C47B50057C84E /* CardItem.swift */, 78 | 5FA0E5D7201C64760057C84E /* ImageCardItem.swift */, 79 | 5FA0E5D5201C4FD60057C84E /* CardView.swift */, 80 | ); 81 | path = CardView; 82 | sourceTree = ""; 83 | }; 84 | /* End PBXGroup section */ 85 | 86 | /* Begin PBXNativeTarget section */ 87 | 5FA0E5BC201C477D0057C84E /* CardView */ = { 88 | isa = PBXNativeTarget; 89 | buildConfigurationList = 5FA0E5CF201C477D0057C84E /* Build configuration list for PBXNativeTarget "CardView" */; 90 | buildPhases = ( 91 | 5FA0E5B9201C477D0057C84E /* Sources */, 92 | 5FA0E5BA201C477D0057C84E /* Frameworks */, 93 | 5FA0E5BB201C477D0057C84E /* Resources */, 94 | ); 95 | buildRules = ( 96 | ); 97 | dependencies = ( 98 | ); 99 | name = CardView; 100 | productName = CardView; 101 | productReference = 5FA0E5BD201C477D0057C84E /* CardView.app */; 102 | productType = "com.apple.product-type.application"; 103 | }; 104 | /* End PBXNativeTarget section */ 105 | 106 | /* Begin PBXProject section */ 107 | 5FA0E5B5201C477D0057C84E /* Project object */ = { 108 | isa = PBXProject; 109 | attributes = { 110 | LastSwiftUpdateCheck = 0920; 111 | LastUpgradeCheck = 1010; 112 | ORGANIZATIONNAME = com.dxchq; 113 | TargetAttributes = { 114 | 5FA0E5BC201C477D0057C84E = { 115 | CreatedOnToolsVersion = 9.2; 116 | LastSwiftMigration = 1010; 117 | ProvisioningStyle = Automatic; 118 | }; 119 | }; 120 | }; 121 | buildConfigurationList = 5FA0E5B8201C477D0057C84E /* Build configuration list for PBXProject "CardView" */; 122 | compatibilityVersion = "Xcode 8.0"; 123 | developmentRegion = en; 124 | hasScannedForEncodings = 0; 125 | knownRegions = ( 126 | en, 127 | Base, 128 | ); 129 | mainGroup = 5FA0E5B4201C477D0057C84E; 130 | productRefGroup = 5FA0E5BE201C477D0057C84E /* Products */; 131 | projectDirPath = ""; 132 | projectRoot = ""; 133 | targets = ( 134 | 5FA0E5BC201C477D0057C84E /* CardView */, 135 | ); 136 | }; 137 | /* End PBXProject section */ 138 | 139 | /* Begin PBXResourcesBuildPhase section */ 140 | 5FA0E5BB201C477D0057C84E /* Resources */ = { 141 | isa = PBXResourcesBuildPhase; 142 | buildActionMask = 2147483647; 143 | files = ( 144 | 5FA0E5CB201C477D0057C84E /* LaunchScreen.storyboard in Resources */, 145 | 142AF0BF201E127C0084D736 /* Assets.xcassets in Resources */, 146 | 5FA0E5C6201C477D0057C84E /* Main.storyboard in Resources */, 147 | ); 148 | runOnlyForDeploymentPostprocessing = 0; 149 | }; 150 | /* End PBXResourcesBuildPhase section */ 151 | 152 | /* Begin PBXSourcesBuildPhase section */ 153 | 5FA0E5B9201C477D0057C84E /* Sources */ = { 154 | isa = PBXSourcesBuildPhase; 155 | buildActionMask = 2147483647; 156 | files = ( 157 | 5FA0E5C3201C477D0057C84E /* ViewController.swift in Sources */, 158 | 5FA0E5C1201C477D0057C84E /* AppDelegate.swift in Sources */, 159 | 5FA0E5D8201C64760057C84E /* ImageCardItem.swift in Sources */, 160 | 5FA0E5D6201C4FD60057C84E /* CardView.swift in Sources */, 161 | 5FA0E5D4201C47B50057C84E /* CardItem.swift in Sources */, 162 | ); 163 | runOnlyForDeploymentPostprocessing = 0; 164 | }; 165 | /* End PBXSourcesBuildPhase section */ 166 | 167 | /* Begin PBXVariantGroup section */ 168 | 5FA0E5C4201C477D0057C84E /* Main.storyboard */ = { 169 | isa = PBXVariantGroup; 170 | children = ( 171 | 5FA0E5C5201C477D0057C84E /* Base */, 172 | ); 173 | name = Main.storyboard; 174 | sourceTree = ""; 175 | }; 176 | 5FA0E5C9201C477D0057C84E /* LaunchScreen.storyboard */ = { 177 | isa = PBXVariantGroup; 178 | children = ( 179 | 5FA0E5CA201C477D0057C84E /* Base */, 180 | ); 181 | name = LaunchScreen.storyboard; 182 | sourceTree = ""; 183 | }; 184 | /* End PBXVariantGroup section */ 185 | 186 | /* Begin XCBuildConfiguration section */ 187 | 5FA0E5CD201C477D0057C84E /* Debug */ = { 188 | isa = XCBuildConfiguration; 189 | buildSettings = { 190 | ALWAYS_SEARCH_USER_PATHS = NO; 191 | CLANG_ANALYZER_NONNULL = YES; 192 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 193 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 194 | CLANG_CXX_LIBRARY = "libc++"; 195 | CLANG_ENABLE_MODULES = YES; 196 | CLANG_ENABLE_OBJC_ARC = YES; 197 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 198 | CLANG_WARN_BOOL_CONVERSION = YES; 199 | CLANG_WARN_COMMA = YES; 200 | CLANG_WARN_CONSTANT_CONVERSION = YES; 201 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 202 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 203 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 204 | CLANG_WARN_EMPTY_BODY = YES; 205 | CLANG_WARN_ENUM_CONVERSION = YES; 206 | CLANG_WARN_INFINITE_RECURSION = YES; 207 | CLANG_WARN_INT_CONVERSION = YES; 208 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 209 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 210 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 211 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 212 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 213 | CLANG_WARN_STRICT_PROTOTYPES = YES; 214 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 215 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 216 | CLANG_WARN_UNREACHABLE_CODE = YES; 217 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 218 | CODE_SIGN_IDENTITY = "iPhone Developer"; 219 | COPY_PHASE_STRIP = NO; 220 | DEBUG_INFORMATION_FORMAT = dwarf; 221 | ENABLE_STRICT_OBJC_MSGSEND = YES; 222 | ENABLE_TESTABILITY = YES; 223 | GCC_C_LANGUAGE_STANDARD = gnu11; 224 | GCC_DYNAMIC_NO_PIC = NO; 225 | GCC_NO_COMMON_BLOCKS = YES; 226 | GCC_OPTIMIZATION_LEVEL = 0; 227 | GCC_PREPROCESSOR_DEFINITIONS = ( 228 | "DEBUG=1", 229 | "$(inherited)", 230 | ); 231 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 232 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 233 | GCC_WARN_UNDECLARED_SELECTOR = YES; 234 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 235 | GCC_WARN_UNUSED_FUNCTION = YES; 236 | GCC_WARN_UNUSED_VARIABLE = YES; 237 | IPHONEOS_DEPLOYMENT_TARGET = 11.2; 238 | MTL_ENABLE_DEBUG_INFO = YES; 239 | ONLY_ACTIVE_ARCH = YES; 240 | SDKROOT = iphoneos; 241 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 242 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 243 | }; 244 | name = Debug; 245 | }; 246 | 5FA0E5CE201C477D0057C84E /* Release */ = { 247 | isa = XCBuildConfiguration; 248 | buildSettings = { 249 | ALWAYS_SEARCH_USER_PATHS = NO; 250 | CLANG_ANALYZER_NONNULL = YES; 251 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 252 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 253 | CLANG_CXX_LIBRARY = "libc++"; 254 | CLANG_ENABLE_MODULES = YES; 255 | CLANG_ENABLE_OBJC_ARC = YES; 256 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 257 | CLANG_WARN_BOOL_CONVERSION = YES; 258 | CLANG_WARN_COMMA = YES; 259 | CLANG_WARN_CONSTANT_CONVERSION = YES; 260 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 261 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 262 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 263 | CLANG_WARN_EMPTY_BODY = YES; 264 | CLANG_WARN_ENUM_CONVERSION = YES; 265 | CLANG_WARN_INFINITE_RECURSION = YES; 266 | CLANG_WARN_INT_CONVERSION = YES; 267 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 268 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 269 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 270 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 271 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 272 | CLANG_WARN_STRICT_PROTOTYPES = YES; 273 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 274 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 275 | CLANG_WARN_UNREACHABLE_CODE = YES; 276 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 277 | CODE_SIGN_IDENTITY = "iPhone Developer"; 278 | COPY_PHASE_STRIP = NO; 279 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 280 | ENABLE_NS_ASSERTIONS = NO; 281 | ENABLE_STRICT_OBJC_MSGSEND = YES; 282 | GCC_C_LANGUAGE_STANDARD = gnu11; 283 | GCC_NO_COMMON_BLOCKS = YES; 284 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 285 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 286 | GCC_WARN_UNDECLARED_SELECTOR = YES; 287 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 288 | GCC_WARN_UNUSED_FUNCTION = YES; 289 | GCC_WARN_UNUSED_VARIABLE = YES; 290 | IPHONEOS_DEPLOYMENT_TARGET = 11.2; 291 | MTL_ENABLE_DEBUG_INFO = NO; 292 | SDKROOT = iphoneos; 293 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 294 | VALIDATE_PRODUCT = YES; 295 | }; 296 | name = Release; 297 | }; 298 | 5FA0E5D0201C477D0057C84E /* Debug */ = { 299 | isa = XCBuildConfiguration; 300 | buildSettings = { 301 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 302 | CODE_SIGN_STYLE = Automatic; 303 | DEVELOPMENT_TEAM = G9M2LEZ945; 304 | INFOPLIST_FILE = CardView/Info.plist; 305 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 306 | PRODUCT_BUNDLE_IDENTIFIER = com.chq.CardView; 307 | PRODUCT_NAME = "$(TARGET_NAME)"; 308 | SWIFT_VERSION = 4.2; 309 | TARGETED_DEVICE_FAMILY = "1,2"; 310 | }; 311 | name = Debug; 312 | }; 313 | 5FA0E5D1201C477D0057C84E /* Release */ = { 314 | isa = XCBuildConfiguration; 315 | buildSettings = { 316 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 317 | CODE_SIGN_STYLE = Automatic; 318 | DEVELOPMENT_TEAM = G9M2LEZ945; 319 | INFOPLIST_FILE = CardView/Info.plist; 320 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 321 | PRODUCT_BUNDLE_IDENTIFIER = com.chq.CardView; 322 | PRODUCT_NAME = "$(TARGET_NAME)"; 323 | SWIFT_VERSION = 4.2; 324 | TARGETED_DEVICE_FAMILY = "1,2"; 325 | }; 326 | name = Release; 327 | }; 328 | /* End XCBuildConfiguration section */ 329 | 330 | /* Begin XCConfigurationList section */ 331 | 5FA0E5B8201C477D0057C84E /* Build configuration list for PBXProject "CardView" */ = { 332 | isa = XCConfigurationList; 333 | buildConfigurations = ( 334 | 5FA0E5CD201C477D0057C84E /* Debug */, 335 | 5FA0E5CE201C477D0057C84E /* Release */, 336 | ); 337 | defaultConfigurationIsVisible = 0; 338 | defaultConfigurationName = Release; 339 | }; 340 | 5FA0E5CF201C477D0057C84E /* Build configuration list for PBXNativeTarget "CardView" */ = { 341 | isa = XCConfigurationList; 342 | buildConfigurations = ( 343 | 5FA0E5D0201C477D0057C84E /* Debug */, 344 | 5FA0E5D1201C477D0057C84E /* Release */, 345 | ); 346 | defaultConfigurationIsVisible = 0; 347 | defaultConfigurationName = Release; 348 | }; 349 | /* End XCConfigurationList section */ 350 | }; 351 | rootObject = 5FA0E5B5201C477D0057C84E /* Project object */; 352 | } 353 | -------------------------------------------------------------------------------- /CardView/CardView.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CardView/CardView/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // CardView 4 | // 5 | // Created by chq on 2018/1/27. 6 | // Copyright © 2018年 chq. 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: [UIApplication.LaunchOptionsKey: 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 | -------------------------------------------------------------------------------- /CardView/CardView/Assets.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" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /CardView/CardView/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /CardView/CardView/Assets.xcassets/design/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /CardView/CardView/Assets.xcassets/design/img_00.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "img_00.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 | } -------------------------------------------------------------------------------- /CardView/CardView/Assets.xcassets/design/img_00.imageset/img_00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chquanquan/CardView/371e8459b7caa2bb404a6dbb0068a1e48edecb30/CardView/CardView/Assets.xcassets/design/img_00.imageset/img_00.png -------------------------------------------------------------------------------- /CardView/CardView/Assets.xcassets/design/img_01.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "img_01.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 | } -------------------------------------------------------------------------------- /CardView/CardView/Assets.xcassets/design/img_01.imageset/img_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chquanquan/CardView/371e8459b7caa2bb404a6dbb0068a1e48edecb30/CardView/CardView/Assets.xcassets/design/img_01.imageset/img_01.png -------------------------------------------------------------------------------- /CardView/CardView/Assets.xcassets/design/img_02.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "img_02.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 | } -------------------------------------------------------------------------------- /CardView/CardView/Assets.xcassets/design/img_02.imageset/img_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chquanquan/CardView/371e8459b7caa2bb404a6dbb0068a1e48edecb30/CardView/CardView/Assets.xcassets/design/img_02.imageset/img_02.png -------------------------------------------------------------------------------- /CardView/CardView/Assets.xcassets/design/img_03.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "img_03.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 | } -------------------------------------------------------------------------------- /CardView/CardView/Assets.xcassets/design/img_03.imageset/img_03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chquanquan/CardView/371e8459b7caa2bb404a6dbb0068a1e48edecb30/CardView/CardView/Assets.xcassets/design/img_03.imageset/img_03.png -------------------------------------------------------------------------------- /CardView/CardView/Assets.xcassets/design/img_04.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "img_04.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 | } -------------------------------------------------------------------------------- /CardView/CardView/Assets.xcassets/design/img_04.imageset/img_04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chquanquan/CardView/371e8459b7caa2bb404a6dbb0068a1e48edecb30/CardView/CardView/Assets.xcassets/design/img_04.imageset/img_04.png -------------------------------------------------------------------------------- /CardView/CardView/Assets.xcassets/design/img_05.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "img_05.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 | } -------------------------------------------------------------------------------- /CardView/CardView/Assets.xcassets/design/img_05.imageset/img_05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chquanquan/CardView/371e8459b7caa2bb404a6dbb0068a1e48edecb30/CardView/CardView/Assets.xcassets/design/img_05.imageset/img_05.png -------------------------------------------------------------------------------- /CardView/CardView/Assets.xcassets/me.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "me-1.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /CardView/CardView/Assets.xcassets/me.imageset/me-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chquanquan/CardView/371e8459b7caa2bb404a6dbb0068a1e48edecb30/CardView/CardView/Assets.xcassets/me.imageset/me-1.png -------------------------------------------------------------------------------- /CardView/CardView/Assets.xcassets/start_button.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "start_button@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "filename" : "start_button@3x.png", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /CardView/CardView/Assets.xcassets/start_button.imageset/start_button@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chquanquan/CardView/371e8459b7caa2bb404a6dbb0068a1e48edecb30/CardView/CardView/Assets.xcassets/start_button.imageset/start_button@2x.png -------------------------------------------------------------------------------- /CardView/CardView/Assets.xcassets/start_button.imageset/start_button@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chquanquan/CardView/371e8459b7caa2bb404a6dbb0068a1e48edecb30/CardView/CardView/Assets.xcassets/start_button.imageset/start_button@3x.png -------------------------------------------------------------------------------- /CardView/CardView/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 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /CardView/CardView/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 | 34 | 47 | 48 | 49 | 50 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 68 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /CardView/CardView/CardView/CardItem.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CardItem.swift 3 | // CardItem 4 | // 5 | // Created by chq on 2018/1/27. 6 | // Copyright © 2018年 chq. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | protocol CardItemDelegate: AnyObject { 12 | func removeFromSuperView(item: CardItem) 13 | } 14 | 15 | class CardItem: UIView { 16 | 17 | override var frame: CGRect { 18 | didSet { 19 | originalCenter = CGPoint(x: frame.size.width * 0.5, y: frame.size.height * 0.5) 20 | } 21 | } 22 | 23 | weak var delegate: CardItemDelegate? 24 | 25 | /// 子视图最好加在contentView上 26 | var contentView: UIView 27 | var cornerRadius: CGFloat = 5 28 | var originalCenter: CGPoint 29 | var currentAngle: CGFloat = 0 30 | var isRight = false 31 | var isDown = false 32 | /// 如果不想让item可以拖动可以设置为false, 默认是true 33 | var isPan = true 34 | 35 | override init(frame: CGRect) { 36 | originalCenter = CGPoint(x: frame.width * 0.5, y: frame.height * 0.5) 37 | contentView = UIView() 38 | super.init(frame: frame) 39 | addSubview(contentView) 40 | addPanGesture() 41 | layout() 42 | isUserInteractionEnabled = false 43 | } 44 | 45 | required init?(coder aDecoder: NSCoder) { 46 | fatalError("init(coder:) has not been implemented") 47 | } 48 | 49 | override func layoutSubviews() { 50 | super.layoutSubviews() 51 | contentView.frame = bounds 52 | } 53 | 54 | func addPanGesture() { 55 | let panGesture = UIPanGestureRecognizer.init(target: self, action: #selector(panGesture(_:))) 56 | addGestureRecognizer(panGesture) 57 | } 58 | 59 | func layout() { 60 | contentView.layer.cornerRadius = cornerRadius 61 | contentView.layer.masksToBounds = true 62 | contentView.layer.shouldRasterize = true 63 | 64 | layer.shadowColor = UIColor.black.cgColor 65 | layer.shadowOffset = CGSize(width: 5, height: 5) 66 | layer.shadowRadius = 5 67 | layer.shadowOpacity = 0.5 68 | } 69 | 70 | @objc func panGesture(_ pan: UIPanGestureRecognizer) { 71 | guard isPan else { return } 72 | if pan.state == .changed { 73 | let movePoint = pan.translation(in: self) 74 | isRight = movePoint.x > 0 75 | isDown = movePoint.y > 0 76 | center = CGPoint(x: center.x + movePoint.x, y: center.y + movePoint.y) 77 | currentAngle = (center.x - frame.width * 0.5) / frame.width / 4.0 78 | transform = CGAffineTransform(rotationAngle: currentAngle) 79 | pan.setTranslation(CGPoint.zero, in: self) 80 | } else if pan.state == .ended { 81 | let vel = pan.velocity(in: self) 82 | if vel.x > 800 { 83 | remove(with: .right, angle: currentAngle) 84 | return 85 | } else if vel.x < -800 { 86 | remove(with: .left, angle: currentAngle) 87 | return 88 | } else if vel.y > 800 { 89 | remove(with: .down, angle: currentAngle) 90 | return 91 | } else if vel.y < -800 { 92 | remove(with: .up, angle: currentAngle) 93 | return 94 | } 95 | 96 | if (frame.origin.x + frame.width > 150 && frame.origin.x < frame.width - 150) && 97 | (frame.origin.y + frame.height > 150 && frame.origin.y < frame.height - 150) { 98 | UIView.animate(withDuration: 0.5, animations: { 99 | [weak self] in guard let `self` = self else { return } 100 | self.center = self.originalCenter 101 | self.transform = CGAffineTransform.identity 102 | }) 103 | } else { 104 | let distanceX = center.x - originalCenter.x 105 | let distanceY = center.y - originalCenter.y 106 | if abs(distanceX) > abs(distanceY) { 107 | remove(with: distanceX > 0 ? .right : .left, angle: currentAngle) 108 | } else { 109 | remove(with: distanceY > 0 ? .down : .up, angle: currentAngle) 110 | } 111 | } 112 | } 113 | } 114 | 115 | /// 移除item 116 | /// 117 | /// - Parameters: 118 | /// - direction: 移除方向 119 | /// - angle: 移除时候的角度,默认0 120 | func remove(with direction: CardDirection = .right, angle: CGFloat = 0, animated: Bool = true) { 121 | if animated { 122 | UIView.animate(withDuration: 0.3, animations: { 123 | [weak self] in guard let self = self else { return } 124 | switch direction { 125 | case .up: 126 | self.center = CGPoint(x: self.center.x + self.currentAngle * self.frame.width + angle, y: self.frame.height - 1000) 127 | case .left: 128 | self.center = CGPoint(x: -1000, y: self.center.y + self.currentAngle * self.frame.height + angle) 129 | case .down: 130 | self.center = CGPoint(x: self.center.x + self.currentAngle * self.frame.width + angle, y: 1000) 131 | case .right: 132 | self.center = CGPoint(x: self.frame.width + 1000, y: self.center.y - self.currentAngle * self.frame.height + angle) 133 | } 134 | }) { [weak self] (_) in 135 | guard let `self` = self else { return } 136 | self.removeFromSuperview() 137 | self.delegate?.removeFromSuperView(item: self) 138 | } 139 | } else { 140 | removeFromSuperview() 141 | delegate?.removeFromSuperView(item: self) 142 | } 143 | 144 | } 145 | 146 | } 147 | -------------------------------------------------------------------------------- /CardView/CardView/CardView/CardView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CardView.swift 3 | // CardView 4 | // 5 | // Created by chq on 2018/1/27. 6 | // Copyright © 2018年 chq. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | 12 | /************** 最上面那张的序号是 0 *****************/ 13 | 14 | enum CardDirection { 15 | case up, left, down, right 16 | } 17 | 18 | protocol CardViewDelegate: AnyObject { 19 | func didClick(cardView: CardView, with index: Int) 20 | func remove(cardView: CardView, item: CardItem, with index: Int) 21 | func revoke(cardView: CardView, item: CardItem, with index: Int) 22 | } 23 | 24 | protocol CardViewDataSource: AnyObject { 25 | func numberOfItems(`in` cardView: CardView) -> Int 26 | func cardView(_ cardView: CardView, cellForItemAt Index: Int) -> CardItem 27 | func cardView(_ cardView: CardView, sizeForItemAt index: Int) -> CGSize 28 | } 29 | 30 | 31 | extension CardViewDataSource { 32 | func cardView(_ cardView: CardView, sizeForItemAt index: Int) -> CGSize { 33 | return cardView.frame.size 34 | } 35 | } 36 | 37 | private let tagMark = 100 38 | 39 | class CardView: UIView { 40 | 41 | weak var delegate: CardViewDelegate? 42 | weak var dataSource: CardViewDataSource? 43 | 44 | ///是否完全重叠,默认否 45 | var isOverlap = false 46 | var isEmpty: Bool { 47 | return count == 0 48 | } 49 | 50 | private var count: Int = 0 51 | private var lastFrames = [Int: CGRect]() 52 | 53 | override init(frame: CGRect) { 54 | super.init(frame: frame) 55 | } 56 | 57 | required init?(coder aDecoder: NSCoder) { 58 | fatalError("init(coder:) has not been implemented") 59 | } 60 | 61 | func reloadData() { 62 | guard let dataSource = dataSource else { return } 63 | count = dataSource.numberOfItems(in: self) 64 | for index in 0.. CardItem { 88 | let size = itemSize(at: index) 89 | let item = itemView(at: index) 90 | item.delegate = self 91 | item.tag = index + tagMark 92 | item.frame = CGRect(x: frame.width * 0.5 - size.width * 0.5, y: frame.height * 0.5 - size.height * 0.5, width: size.width, height: size.height) 93 | return item 94 | } 95 | 96 | @objc private func handleTapGesture(_ tap: UITapGestureRecognizer) { 97 | guard let tapView = tap.view else { return } 98 | self.delegate?.didClick(cardView: self, with: tapView.tag - tagMark) 99 | } 100 | 101 | private func itemSize(at index: Int) -> CGSize { 102 | guard let dataSource = dataSource, index < count else { 103 | return frame.size 104 | } 105 | 106 | var size = dataSource.cardView(self, sizeForItemAt: index) 107 | if size.width > frame.width || size.width == 0 { 108 | print("wraning: item.width == 0") 109 | size.width = frame.width 110 | } 111 | if size.height > frame.height || size.height == 0 { 112 | print("wraning: item.height == 0") 113 | size.height = frame.height 114 | } 115 | return size 116 | } 117 | 118 | private func itemView(at index: Int) -> CardItem { 119 | guard let dataSource = dataSource else { 120 | return CardItem() 121 | } 122 | return dataSource.cardView(self, cellForItemAt: index) 123 | } 124 | 125 | func removeAll(animated: Bool = true) { 126 | for (index, item) in subviews.reversed().enumerated() { 127 | if let item = item as? CardItem { 128 | if animated { 129 | DispatchQueue.main.asyncAfter(deadline: .now() + (0.1 * Double(index)), execute: { 130 | item.remove(animated: true) 131 | }) 132 | } else { 133 | item.remove(animated: false) 134 | } 135 | 136 | } 137 | } 138 | } 139 | 140 | func removeTopItem(with direction: CardDirection = .right, angle: CGFloat = 0) { 141 | if let item = subviews.last as? CardItem { 142 | item.remove(with: direction, angle: angle) 143 | } 144 | } 145 | 146 | /// 返回上一张卡片. 147 | func revokeCard() { 148 | if let topItem = subviews.last as? CardItem { 149 | let index = topItem.tag - tagMark - 1 150 | guard index >= 0, let lastFrame = self.lastFrames[index] else { 151 | print("no item to revoke") 152 | return 153 | } 154 | let item = createItem(with: index) 155 | addSubview(item) 156 | item.isHidden = true 157 | UIView.animate(withDuration: 0.01, animations: { 158 | item.transform = CGAffineTransform(translationX: lastFrame.origin.x, y: lastFrame.origin.y) 159 | }, completion: { (_) in 160 | item.isHidden = false 161 | UIView.animate(withDuration: 0.25, animations: { [weak self] in 162 | item.transform = CGAffineTransform.identity 163 | self?.relayoutItem(isRevoke: true) 164 | }, completion: { [weak self] (_) in 165 | if self != nil { 166 | self?.delegate?.revoke(cardView: self!, item: item, with: index) 167 | } 168 | }) 169 | }) 170 | 171 | 172 | } 173 | } 174 | 175 | private func relayoutItem(isRevoke: Bool = false) { 176 | for (index, item) in subviews.reversed().enumerated() { 177 | if index == 0 { 178 | item.isUserInteractionEnabled = true 179 | if isRevoke { continue } 180 | } 181 | if !isOverlap { 182 | UIView.animate(withDuration: 0.1, animations: { 183 | let scale = 1 - 0.05 * CGFloat(index) 184 | UIView.animate(withDuration: 0.1, animations: { 185 | let transform = CGAffineTransform(scaleX: scale, y: scale).translatedBy(x: 0, y: 25 * CGFloat(index)) 186 | item.transform = transform 187 | }) 188 | }) 189 | } 190 | } 191 | } 192 | 193 | } 194 | 195 | 196 | extension CardView: CardItemDelegate { 197 | func removeFromSuperView(item: CardItem) { 198 | let index = item.tag - tagMark 199 | lastFrames[index] = item.frame 200 | if count > 0 { 201 | count -= 1 202 | } 203 | relayoutItem() 204 | delegate?.remove(cardView: self, item: item, with: index) 205 | } 206 | } 207 | -------------------------------------------------------------------------------- /CardView/CardView/CardView/ImageCardItem.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ImageCardItem.swift 3 | // ImageCardItem 4 | // 5 | // Created by chq on 2018/1/27. 6 | // Copyright © 2018年 chq. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ImageCardItem: CardItem { 12 | 13 | var image: UIImage 14 | var imageView: UIImageView! 15 | init(image: UIImage) { 16 | self.image = image 17 | super.init(frame: CGRect.zero) 18 | initView() 19 | } 20 | 21 | required init?(coder aDecoder: NSCoder) { 22 | fatalError("init(coder:) has not been implemented") 23 | } 24 | 25 | func initView() { 26 | imageView = UIImageView() 27 | imageView.image = image 28 | contentView.addSubview(imageView) 29 | } 30 | 31 | override func layoutSubviews() { 32 | super.layoutSubviews() 33 | imageView.frame = bounds 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /CardView/CardView/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 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 | -------------------------------------------------------------------------------- /CardView/CardView/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // CardView 4 | // 5 | // Created by chq on 2018/1/27. 6 | // Copyright © 2018年 chq. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | let count = 6 13 | var cardView: CardView! 14 | var startButton: UIButton? 15 | @IBOutlet weak var autoReloadSwitch: UISwitch! 16 | @IBOutlet weak var skipAnimateSwitch: UISwitch! 17 | @IBOutlet weak var reloadButton: UIButton! 18 | 19 | override func viewDidLoad() { 20 | super.viewDidLoad() 21 | view.backgroundColor = UIColor.white 22 | addCardView() 23 | view.bringSubviewToFront(reloadButton) 24 | } 25 | 26 | func addCardView() { 27 | 28 | cardView = CardView(frame: CGRect(x: 0, y: 0, width: 300, height: 500)) 29 | cardView.center = view.center 30 | // cardView.isOverlap = false 31 | view.addSubview(cardView) 32 | cardView?.delegate = self 33 | cardView?.dataSource = self 34 | cardView?.reloadData() 35 | 36 | } 37 | 38 | @IBAction func skipAction(_ sender: UIButton) { 39 | // cardView.removeTopItem() 40 | cardView.removeAll(animated: skipAnimateSwitch.isOn) 41 | } 42 | 43 | @IBAction func revokeAction(_ sender: UIButton) { 44 | cardView.revokeCard() 45 | } 46 | 47 | @IBAction func overlapValueChanged(_ sender: UISwitch) { 48 | cardView.isOverlap = sender.isOn 49 | cardView.removeAll(animated: false) 50 | reloadButton.isHidden = true 51 | cardView.reloadData() 52 | 53 | } 54 | 55 | 56 | @IBAction func autoReloadValueChanged(_ sender: UISwitch) { 57 | if cardView.isEmpty { 58 | reloadButton.isHidden = true 59 | cardView.reloadData() 60 | } 61 | } 62 | 63 | @IBAction func reload(_ sender: UIButton) { 64 | sender.isHidden = true 65 | cardView.reloadData() 66 | } 67 | 68 | 69 | override func didReceiveMemoryWarning() { 70 | super.didReceiveMemoryWarning() 71 | // Dispose of any resources that can be recreated. 72 | } 73 | 74 | 75 | } 76 | 77 | extension ViewController: CardViewDelegate { 78 | func revoke(cardView: CardView, item: CardItem, with index: Int) { 79 | print("revoke index: \(index)") 80 | } 81 | 82 | 83 | func didClick(cardView: CardView, with index: Int) { 84 | print("click index: \(index)") 85 | } 86 | 87 | func remove(cardView: CardView, item: CardItem, with index: Int) { 88 | print("remove: \(index)") 89 | if index == count - 1 { 90 | if autoReloadSwitch.isOn { 91 | cardView.reloadData() 92 | } else { 93 | reloadButton.isHidden = false 94 | } 95 | } 96 | } 97 | 98 | 99 | } 100 | 101 | extension ViewController: CardViewDataSource { 102 | 103 | func numberOfItems(in cardView: CardView) -> Int { 104 | return count 105 | } 106 | 107 | func cardView(_ cardView: CardView, cellForItemAt Index: Int) -> CardItem { 108 | 109 | //序号越靠前,越在前面..0最上面. 110 | var item: ImageCardItem! 111 | if let image = UIImage(named: "img_0" + "\(Index)") { 112 | item = ImageCardItem(image: image) 113 | } else { 114 | item = ImageCardItem(image: UIImage.getImageWithColor(color: UIColor.randomColor)) 115 | } 116 | 117 | if Index == count - 1 { 118 | addStartButton(item: item) 119 | item.isPan = false //此属性可以让cardItem不能拖动. 120 | } 121 | return item 122 | } 123 | 124 | func addStartButton(item: CardItem) { 125 | let button = UIButton(type: .custom) 126 | button.frame = CGRect(x: 0, y: 0, width: 70, height: 70) 127 | button.setBackgroundImage(#imageLiteral(resourceName: "start_button"), for: .normal) 128 | button.addTarget(self, action: #selector(startAction(_:)), for: .touchUpInside) 129 | item.contentView.addSubview(button) 130 | 131 | button.translatesAutoresizingMaskIntoConstraints = false 132 | item.addConstraint(NSLayoutConstraint(item: button, attribute: .centerX, relatedBy: .equal, toItem: item, attribute: .centerX, multiplier: 1, constant: 0)) 133 | item.addConstraint(NSLayoutConstraint(item: button, attribute: .bottom, relatedBy: .equal, toItem: item, attribute: .bottom, multiplier: 1, constant: -30)) 134 | 135 | startButton = button 136 | } 137 | 138 | @objc func startAction(_ button: UIButton) { 139 | print("start button clicked") 140 | cardView.removeTopItem(with: .up) 141 | } 142 | 143 | } 144 | 145 | 146 | 147 | 148 | extension UIImage { 149 | /// 将颜色转换为图片 150 | static func getImageWithColor(color:UIColor)->UIImage{ 151 | let rect = CGRect(x: 0, y: 0, width: 1, height: 1) 152 | UIGraphicsBeginImageContext(rect.size) 153 | let context = UIGraphicsGetCurrentContext() 154 | context!.setFillColor(color.cgColor) 155 | context!.fill(rect) 156 | let image = UIGraphicsGetImageFromCurrentImageContext() 157 | UIGraphicsEndImageContext() 158 | return image! 159 | } 160 | } 161 | 162 | extension UIColor { 163 | //返回随机颜色 164 | class var randomColor: UIColor { 165 | get { 166 | let red = CGFloat(arc4random()%256)/255.0 167 | let green = CGFloat(arc4random()%256)/255.0 168 | let blue = CGFloat(arc4random()%256)/255.0 169 | return UIColor(red: red, green: green, blue: blue, alpha: 1.0) 170 | } 171 | } 172 | } 173 | 174 | 175 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CardView 2 | a beautiful cardView and easy to use. 3 | 4 | It can be dragged to remove, so you can use it to delete pics or show app's new features. 5 | 6 | [中文说明](http://blog.csdn.net/ch_quan/article/details/79200800) 7 | 8 | You can use it just like use a TableView, apply to CardViewDelegate and CardViewDataSource. 9 | 10 | You can use delegate to listen to Click and Remove event. 11 | 12 | use dataSorce to return number and cardItem. 13 | 14 | 15 | ![CardView](https://github.com/chquanquan/CardView/blob/master/cardView.gif?raw=true) 16 | 17 | 18 | eg: 19 | 20 | ``` 21 | extension ViewController:CardViewDelegate { 22 | 23 | func didClick(cardView: CardView, with index: Int) { 24 | print("click index:\(index)") 25 | } 26 | 27 | func remove(cardView: CardView, item: CardItem, with index: Int) { 28 | print("remove:\(index)") 29 | if index == count - 1 { 30 | cardView.reloadData() 31 | } 32 | } 33 | 34 | } 35 | ``` 36 | 37 | ``` 38 | extension ViewController:CardViewDataSource { 39 | 40 | func numberOfItems(in cardView: CardView) -> Int { 41 | return count 42 | } 43 | 44 | func cardView(_ cardView:CardView, cellForItemAt Index:Int) ->CardItem { 45 | 46 | // first item at top. 47 | var item: ImageCardItem! 48 | if let image =UIImage(named:"img_0" +"\(Index)") { 49 | item = ImageCardItem(image: image) 50 | } 51 | 52 | if Index == count - 1 { 53 | addStartButton(item: item) 54 | // decide to pan 55 | item.isPan = false. 56 | } 57 | return item 58 | } 59 | } 60 | ``` 61 | 62 | 63 | By the way, if you want to load local images, use ImageCardItem,if you want to load network Images, just implement your LoadImage func in imageView. 64 | If you want to a custom cardItem, please add your subviews to cardItem's contentView. or inherit cardItem 65 | 66 | This CardView also can be removed cardItem by code for four direction. 67 | 68 | This demo clearly shows about how to use a CardView......^_^ 69 | 70 | 71 | -------------------------------------------------------------------------------- /cardView.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chquanquan/CardView/371e8459b7caa2bb404a6dbb0068a1e48edecb30/cardView.gif --------------------------------------------------------------------------------