├── .gitignore ├── 1.gif ├── Card ├── Card.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── Card │ ├── Assets.xcassets │ ├── AccentColor.colorset │ │ └── Contents.json │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json │ ├── Card.entitlements │ ├── CardApp.swift │ ├── CardView.swift │ ├── ContentView.swift │ ├── Info.plist │ ├── Preview Content │ └── Preview Assets.xcassets │ │ └── Contents.json │ └── SwipeCardView.swift ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## User settings 6 | xcuserdata/ 7 | 8 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) 9 | *.xcscmblueprint 10 | *.xccheckout 11 | 12 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) 13 | build/ 14 | DerivedData/ 15 | *.moved-aside 16 | *.pbxuser 17 | !default.pbxuser 18 | *.mode1v3 19 | !default.mode1v3 20 | *.mode2v3 21 | !default.mode2v3 22 | *.perspectivev3 23 | !default.perspectivev3 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | 28 | ## App packaging 29 | *.ipa 30 | *.dSYM.zip 31 | *.dSYM 32 | 33 | ## Playgrounds 34 | timeline.xctimeline 35 | playground.xcworkspace 36 | 37 | # Swift Package Manager 38 | # 39 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 40 | # Packages/ 41 | # Package.pins 42 | # Package.resolved 43 | # *.xcodeproj 44 | # 45 | # Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata 46 | # hence it is not needed unless you have added a package configuration file to your project 47 | # .swiftpm 48 | 49 | .build/ 50 | 51 | # CocoaPods 52 | # 53 | # We recommend against adding the Pods directory to your .gitignore. However 54 | # you should judge for yourself, the pros and cons are mentioned at: 55 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 56 | # 57 | # Pods/ 58 | # 59 | # Add this line if you want to avoid checking in source code from the Xcode workspace 60 | # *.xcworkspace 61 | 62 | # Carthage 63 | # 64 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 65 | # Carthage/Checkouts 66 | 67 | Carthage/Build/ 68 | 69 | # Accio dependency management 70 | Dependencies/ 71 | .accio/ 72 | 73 | # fastlane 74 | # 75 | # It is recommended to not store the screenshots in the git repo. 76 | # Instead, use fastlane to re-generate the screenshots whenever they are needed. 77 | # For more information about the recommended setup visit: 78 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 79 | 80 | fastlane/report.xml 81 | fastlane/Preview.html 82 | fastlane/screenshots/**/*.png 83 | fastlane/test_output 84 | 85 | # Code Injection 86 | # 87 | # After new code Injection tools there's a generated folder /iOSInjectionProject 88 | # https://github.com/johnno1962/injectionforxcode 89 | 90 | iOSInjectionProject/ 91 | -------------------------------------------------------------------------------- /1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zjinhu/CardStack-SwiftUI/4f2fdae6bb34591cb468c8c1ed94ff1af79c7aa5/1.gif -------------------------------------------------------------------------------- /Card/Card.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 812463BC25BFB7AF00138267 /* CardApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 812463BB25BFB7AF00138267 /* CardApp.swift */; }; 11 | 812463BE25BFB7AF00138267 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 812463BD25BFB7AF00138267 /* ContentView.swift */; }; 12 | 812463C025BFB7B000138267 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 812463BF25BFB7B000138267 /* Assets.xcassets */; }; 13 | 812463C325BFB7B000138267 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 812463C225BFB7B000138267 /* Preview Assets.xcassets */; }; 14 | 812463D425BFEA8700138267 /* CardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 812463D325BFEA8700138267 /* CardView.swift */; }; 15 | /* End PBXBuildFile section */ 16 | 17 | /* Begin PBXFileReference section */ 18 | 812463B825BFB7AF00138267 /* Card.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Card.app; sourceTree = BUILT_PRODUCTS_DIR; }; 19 | 812463BB25BFB7AF00138267 /* CardApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardApp.swift; sourceTree = ""; }; 20 | 812463BD25BFB7AF00138267 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 21 | 812463BF25BFB7B000138267 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 22 | 812463C225BFB7B000138267 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 23 | 812463C425BFB7B000138267 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 24 | 812463D325BFEA8700138267 /* CardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardView.swift; sourceTree = ""; }; 25 | 812463D725C001E400138267 /* Card.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Card.entitlements; sourceTree = ""; }; 26 | /* End PBXFileReference section */ 27 | 28 | /* Begin PBXFrameworksBuildPhase section */ 29 | 812463B525BFB7AF00138267 /* Frameworks */ = { 30 | isa = PBXFrameworksBuildPhase; 31 | buildActionMask = 2147483647; 32 | files = ( 33 | ); 34 | runOnlyForDeploymentPostprocessing = 0; 35 | }; 36 | /* End PBXFrameworksBuildPhase section */ 37 | 38 | /* Begin PBXGroup section */ 39 | 812463AF25BFB7AF00138267 = { 40 | isa = PBXGroup; 41 | children = ( 42 | 812463BA25BFB7AF00138267 /* Card */, 43 | 812463B925BFB7AF00138267 /* Products */, 44 | ); 45 | sourceTree = ""; 46 | }; 47 | 812463B925BFB7AF00138267 /* Products */ = { 48 | isa = PBXGroup; 49 | children = ( 50 | 812463B825BFB7AF00138267 /* Card.app */, 51 | ); 52 | name = Products; 53 | sourceTree = ""; 54 | }; 55 | 812463BA25BFB7AF00138267 /* Card */ = { 56 | isa = PBXGroup; 57 | children = ( 58 | 812463D725C001E400138267 /* Card.entitlements */, 59 | 812463BB25BFB7AF00138267 /* CardApp.swift */, 60 | 812463BD25BFB7AF00138267 /* ContentView.swift */, 61 | 812463D325BFEA8700138267 /* CardView.swift */, 62 | 812463BF25BFB7B000138267 /* Assets.xcassets */, 63 | 812463C425BFB7B000138267 /* Info.plist */, 64 | 812463C125BFB7B000138267 /* Preview Content */, 65 | ); 66 | path = Card; 67 | sourceTree = ""; 68 | }; 69 | 812463C125BFB7B000138267 /* Preview Content */ = { 70 | isa = PBXGroup; 71 | children = ( 72 | 812463C225BFB7B000138267 /* Preview Assets.xcassets */, 73 | ); 74 | path = "Preview Content"; 75 | sourceTree = ""; 76 | }; 77 | /* End PBXGroup section */ 78 | 79 | /* Begin PBXNativeTarget section */ 80 | 812463B725BFB7AF00138267 /* Card */ = { 81 | isa = PBXNativeTarget; 82 | buildConfigurationList = 812463C725BFB7B000138267 /* Build configuration list for PBXNativeTarget "Card" */; 83 | buildPhases = ( 84 | 812463B425BFB7AF00138267 /* Sources */, 85 | 812463B525BFB7AF00138267 /* Frameworks */, 86 | 812463B625BFB7AF00138267 /* Resources */, 87 | ); 88 | buildRules = ( 89 | ); 90 | dependencies = ( 91 | ); 92 | name = Card; 93 | productName = Card; 94 | productReference = 812463B825BFB7AF00138267 /* Card.app */; 95 | productType = "com.apple.product-type.application"; 96 | }; 97 | /* End PBXNativeTarget section */ 98 | 99 | /* Begin PBXProject section */ 100 | 812463B025BFB7AF00138267 /* Project object */ = { 101 | isa = PBXProject; 102 | attributes = { 103 | LastSwiftUpdateCheck = 1230; 104 | LastUpgradeCheck = 1230; 105 | TargetAttributes = { 106 | 812463B725BFB7AF00138267 = { 107 | CreatedOnToolsVersion = 12.3; 108 | }; 109 | }; 110 | }; 111 | buildConfigurationList = 812463B325BFB7AF00138267 /* Build configuration list for PBXProject "Card" */; 112 | compatibilityVersion = "Xcode 9.3"; 113 | developmentRegion = en; 114 | hasScannedForEncodings = 0; 115 | knownRegions = ( 116 | en, 117 | Base, 118 | ); 119 | mainGroup = 812463AF25BFB7AF00138267; 120 | productRefGroup = 812463B925BFB7AF00138267 /* Products */; 121 | projectDirPath = ""; 122 | projectRoot = ""; 123 | targets = ( 124 | 812463B725BFB7AF00138267 /* Card */, 125 | ); 126 | }; 127 | /* End PBXProject section */ 128 | 129 | /* Begin PBXResourcesBuildPhase section */ 130 | 812463B625BFB7AF00138267 /* Resources */ = { 131 | isa = PBXResourcesBuildPhase; 132 | buildActionMask = 2147483647; 133 | files = ( 134 | 812463C325BFB7B000138267 /* Preview Assets.xcassets in Resources */, 135 | 812463C025BFB7B000138267 /* Assets.xcassets in Resources */, 136 | ); 137 | runOnlyForDeploymentPostprocessing = 0; 138 | }; 139 | /* End PBXResourcesBuildPhase section */ 140 | 141 | /* Begin PBXSourcesBuildPhase section */ 142 | 812463B425BFB7AF00138267 /* Sources */ = { 143 | isa = PBXSourcesBuildPhase; 144 | buildActionMask = 2147483647; 145 | files = ( 146 | 812463BE25BFB7AF00138267 /* ContentView.swift in Sources */, 147 | 812463BC25BFB7AF00138267 /* CardApp.swift in Sources */, 148 | 812463D425BFEA8700138267 /* CardView.swift in Sources */, 149 | ); 150 | runOnlyForDeploymentPostprocessing = 0; 151 | }; 152 | /* End PBXSourcesBuildPhase section */ 153 | 154 | /* Begin XCBuildConfiguration section */ 155 | 812463C525BFB7B000138267 /* Debug */ = { 156 | isa = XCBuildConfiguration; 157 | buildSettings = { 158 | ALWAYS_SEARCH_USER_PATHS = NO; 159 | CLANG_ANALYZER_NONNULL = YES; 160 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 161 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 162 | CLANG_CXX_LIBRARY = "libc++"; 163 | CLANG_ENABLE_MODULES = YES; 164 | CLANG_ENABLE_OBJC_ARC = YES; 165 | CLANG_ENABLE_OBJC_WEAK = YES; 166 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 167 | CLANG_WARN_BOOL_CONVERSION = YES; 168 | CLANG_WARN_COMMA = YES; 169 | CLANG_WARN_CONSTANT_CONVERSION = YES; 170 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 171 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 172 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 173 | CLANG_WARN_EMPTY_BODY = YES; 174 | CLANG_WARN_ENUM_CONVERSION = YES; 175 | CLANG_WARN_INFINITE_RECURSION = YES; 176 | CLANG_WARN_INT_CONVERSION = YES; 177 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 178 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 179 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 180 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 181 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 182 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 183 | CLANG_WARN_STRICT_PROTOTYPES = YES; 184 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 185 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 186 | CLANG_WARN_UNREACHABLE_CODE = YES; 187 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 188 | COPY_PHASE_STRIP = NO; 189 | DEBUG_INFORMATION_FORMAT = dwarf; 190 | ENABLE_STRICT_OBJC_MSGSEND = YES; 191 | ENABLE_TESTABILITY = YES; 192 | GCC_C_LANGUAGE_STANDARD = gnu11; 193 | GCC_DYNAMIC_NO_PIC = NO; 194 | GCC_NO_COMMON_BLOCKS = YES; 195 | GCC_OPTIMIZATION_LEVEL = 0; 196 | GCC_PREPROCESSOR_DEFINITIONS = ( 197 | "DEBUG=1", 198 | "$(inherited)", 199 | ); 200 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 201 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 202 | GCC_WARN_UNDECLARED_SELECTOR = YES; 203 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 204 | GCC_WARN_UNUSED_FUNCTION = YES; 205 | GCC_WARN_UNUSED_VARIABLE = YES; 206 | IPHONEOS_DEPLOYMENT_TARGET = 14.3; 207 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 208 | MTL_FAST_MATH = YES; 209 | ONLY_ACTIVE_ARCH = YES; 210 | SDKROOT = iphoneos; 211 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 212 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 213 | }; 214 | name = Debug; 215 | }; 216 | 812463C625BFB7B000138267 /* Release */ = { 217 | isa = XCBuildConfiguration; 218 | buildSettings = { 219 | ALWAYS_SEARCH_USER_PATHS = NO; 220 | CLANG_ANALYZER_NONNULL = YES; 221 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 222 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 223 | CLANG_CXX_LIBRARY = "libc++"; 224 | CLANG_ENABLE_MODULES = YES; 225 | CLANG_ENABLE_OBJC_ARC = YES; 226 | CLANG_ENABLE_OBJC_WEAK = YES; 227 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 228 | CLANG_WARN_BOOL_CONVERSION = YES; 229 | CLANG_WARN_COMMA = YES; 230 | CLANG_WARN_CONSTANT_CONVERSION = YES; 231 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 232 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 233 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 234 | CLANG_WARN_EMPTY_BODY = YES; 235 | CLANG_WARN_ENUM_CONVERSION = YES; 236 | CLANG_WARN_INFINITE_RECURSION = YES; 237 | CLANG_WARN_INT_CONVERSION = YES; 238 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 239 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 240 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 241 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 242 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 243 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 244 | CLANG_WARN_STRICT_PROTOTYPES = YES; 245 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 246 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 247 | CLANG_WARN_UNREACHABLE_CODE = YES; 248 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 249 | COPY_PHASE_STRIP = NO; 250 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 251 | ENABLE_NS_ASSERTIONS = NO; 252 | ENABLE_STRICT_OBJC_MSGSEND = YES; 253 | GCC_C_LANGUAGE_STANDARD = gnu11; 254 | GCC_NO_COMMON_BLOCKS = YES; 255 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 256 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 257 | GCC_WARN_UNDECLARED_SELECTOR = YES; 258 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 259 | GCC_WARN_UNUSED_FUNCTION = YES; 260 | GCC_WARN_UNUSED_VARIABLE = YES; 261 | IPHONEOS_DEPLOYMENT_TARGET = 14.3; 262 | MTL_ENABLE_DEBUG_INFO = NO; 263 | MTL_FAST_MATH = YES; 264 | SDKROOT = iphoneos; 265 | SWIFT_COMPILATION_MODE = wholemodule; 266 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 267 | VALIDATE_PRODUCT = YES; 268 | }; 269 | name = Release; 270 | }; 271 | 812463C825BFB7B000138267 /* Debug */ = { 272 | isa = XCBuildConfiguration; 273 | buildSettings = { 274 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 275 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 276 | CODE_SIGN_ENTITLEMENTS = Card/Card.entitlements; 277 | CODE_SIGN_STYLE = Automatic; 278 | DEVELOPMENT_ASSET_PATHS = "\"Card/Preview Content\""; 279 | DEVELOPMENT_TEAM = 69LR4SZVY2; 280 | ENABLE_PREVIEWS = YES; 281 | INFOPLIST_FILE = Card/Info.plist; 282 | IPHONEOS_DEPLOYMENT_TARGET = 14.0; 283 | LD_RUNPATH_SEARCH_PATHS = ( 284 | "$(inherited)", 285 | "@executable_path/Frameworks", 286 | ); 287 | PRODUCT_BUNDLE_IDENTIFIER = hu.Card; 288 | PRODUCT_NAME = "$(TARGET_NAME)"; 289 | SUPPORTS_MACCATALYST = YES; 290 | SWIFT_VERSION = 5.0; 291 | TARGETED_DEVICE_FAMILY = "1,2"; 292 | }; 293 | name = Debug; 294 | }; 295 | 812463C925BFB7B000138267 /* Release */ = { 296 | isa = XCBuildConfiguration; 297 | buildSettings = { 298 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 299 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 300 | CODE_SIGN_ENTITLEMENTS = Card/Card.entitlements; 301 | CODE_SIGN_STYLE = Automatic; 302 | DEVELOPMENT_ASSET_PATHS = "\"Card/Preview Content\""; 303 | DEVELOPMENT_TEAM = 69LR4SZVY2; 304 | ENABLE_PREVIEWS = YES; 305 | INFOPLIST_FILE = Card/Info.plist; 306 | IPHONEOS_DEPLOYMENT_TARGET = 14.0; 307 | LD_RUNPATH_SEARCH_PATHS = ( 308 | "$(inherited)", 309 | "@executable_path/Frameworks", 310 | ); 311 | PRODUCT_BUNDLE_IDENTIFIER = hu.Card; 312 | PRODUCT_NAME = "$(TARGET_NAME)"; 313 | SUPPORTS_MACCATALYST = YES; 314 | SWIFT_VERSION = 5.0; 315 | TARGETED_DEVICE_FAMILY = "1,2"; 316 | }; 317 | name = Release; 318 | }; 319 | /* End XCBuildConfiguration section */ 320 | 321 | /* Begin XCConfigurationList section */ 322 | 812463B325BFB7AF00138267 /* Build configuration list for PBXProject "Card" */ = { 323 | isa = XCConfigurationList; 324 | buildConfigurations = ( 325 | 812463C525BFB7B000138267 /* Debug */, 326 | 812463C625BFB7B000138267 /* Release */, 327 | ); 328 | defaultConfigurationIsVisible = 0; 329 | defaultConfigurationName = Release; 330 | }; 331 | 812463C725BFB7B000138267 /* Build configuration list for PBXNativeTarget "Card" */ = { 332 | isa = XCConfigurationList; 333 | buildConfigurations = ( 334 | 812463C825BFB7B000138267 /* Debug */, 335 | 812463C925BFB7B000138267 /* Release */, 336 | ); 337 | defaultConfigurationIsVisible = 0; 338 | defaultConfigurationName = Release; 339 | }; 340 | /* End XCConfigurationList section */ 341 | }; 342 | rootObject = 812463B025BFB7AF00138267 /* Project object */; 343 | } 344 | -------------------------------------------------------------------------------- /Card/Card.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Card/Card.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Card/Card/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Card/Card/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "scale" : "1x", 46 | "size" : "20x20" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "scale" : "2x", 51 | "size" : "20x20" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "scale" : "1x", 56 | "size" : "29x29" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "scale" : "2x", 61 | "size" : "29x29" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "scale" : "1x", 66 | "size" : "40x40" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "scale" : "2x", 71 | "size" : "40x40" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "scale" : "1x", 76 | "size" : "76x76" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "scale" : "2x", 81 | "size" : "76x76" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "scale" : "2x", 86 | "size" : "83.5x83.5" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "scale" : "1x", 91 | "size" : "1024x1024" 92 | } 93 | ], 94 | "info" : { 95 | "author" : "xcode", 96 | "version" : 1 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /Card/Card/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Card/Card/Card.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | com.apple.security.network.client 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Card/Card/CardApp.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CardApp.swift 3 | // Card 4 | // 5 | // Created by iOS on 2021/1/26. 6 | // 7 | 8 | import SwiftUI 9 | 10 | @main 11 | struct CardApp: App { 12 | var body: some Scene { 13 | WindowGroup { 14 | ContentView() 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Card/Card/CardView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CardView.swift 3 | // Card 4 | // 5 | // Created by iOS on 2021/1/26. 6 | // 7 | 8 | import SwiftUI 9 | 10 | public let CardNotification = "CardNotification" 11 | 12 | public struct CardStack: View where Data.Index: Hashable { 13 | 14 | @State var index: Data.Index 15 | 16 | private let data: Data 17 | private let id: KeyPath 18 | private let content: (Data.Element) -> Content 19 | 20 | public init(index: Int, 21 | data: Data, 22 | id: KeyPath, 23 | @ViewBuilder content: @escaping (Data.Element) -> Content) { 24 | 25 | self.data = data 26 | self.id = id 27 | self.content = content 28 | self._index = State(initialValue: index as! Data.Index) 29 | } 30 | 31 | public var body: some View { 32 | ZStack { 33 | ForEach(data.indices.reversed(), id: \.self) { index -> AnyView in 34 | let relativeIndex = self.data.distance(from: self.index, to: index) 35 | if relativeIndex >= 0 && relativeIndex < 5 { 36 | return AnyView(self.card(index: index, relativeIndex: relativeIndex)) 37 | } else { 38 | return AnyView(EmptyView()) 39 | } 40 | } 41 | } 42 | .onReceive(NotificationCenter.default.publisher(for: Notification.Name.init(CardNotification)), perform: { noti in 43 | if let num : Int = noti.object as? Int { 44 | index = num as! Data.Index 45 | } 46 | }) 47 | } 48 | 49 | private func card(index: Data.Index, relativeIndex: Int) -> some View { 50 | CardView(onSwipe: { 51 | self.index = self.data.index(after: index) 52 | }, content: { 53 | self.content(self.data[index]) 54 | .offset(x: 0,y: CGFloat(relativeIndex) * 10) 55 | .scaleEffect(1 - 0.1 * CGFloat(relativeIndex),anchor: .bottom) 56 | }) 57 | } 58 | } 59 | 60 | extension CardStack where Data.Element: Identifiable, ID == Data.Element.ID { 61 | 62 | public init(index: Int, 63 | data: Data, 64 | @ViewBuilder content: @escaping (Data.Element) -> Content ) { 65 | self.init(index: index, data: data, id: \Data.Element.id, content: content) 66 | } 67 | 68 | } 69 | 70 | extension CardStack where Data.Element: Hashable, ID == Data.Element { 71 | 72 | public init(index: Int, 73 | data: Data, 74 | @ViewBuilder content: @escaping (Data.Element) -> Content ) { 75 | self.init(index: index, data: data, id: \Data.Element.self, content: content) 76 | } 77 | 78 | } 79 | 80 | 81 | struct CardView: View { 82 | 83 | @State private var offset: CGSize = .zero 84 | private var contentView: () -> Content 85 | private let swipe: () -> Void 86 | 87 | init(onSwipe: @escaping () -> Void, 88 | @ViewBuilder content: @escaping () -> Content) { 89 | contentView = content 90 | swipe = onSwipe 91 | } 92 | 93 | var body: some View { 94 | GeometryReader{ geo in 95 | contentView() 96 | .offset(offset) 97 | .rotationEffect(.degrees(Double(offset.width/geo.size.width))) 98 | .gesture(dragGesture(geo)) 99 | } 100 | .animation(.spring()) 101 | } 102 | 103 | private func dragGesture(_ geometry: GeometryProxy) -> some Gesture { 104 | DragGesture() 105 | .onChanged { value in 106 | offset = value.translation 107 | } 108 | .onEnded { value in 109 | offset = value.translation 110 | 111 | let threshold = min(geometry.size.width, geometry.size.height) / 2 112 | let distance = hypot(offset.width, offset.height) 113 | 114 | if distance > threshold { 115 | withAnimation { swipe()} 116 | } else { 117 | withAnimation { offset = .zero} 118 | } 119 | } 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /Card/Card/ContentView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContentView.swift 3 | // Card 4 | // 5 | // Created by iOS on 2021/1/26. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct Card : Hashable{ 11 | let number: String 12 | } 13 | 14 | struct ContentView: View { 15 | 16 | @State private var cards = [Card]() 17 | 18 | var body: some View { 19 | 20 | VStack{ 21 | CardStack(index: 1, data: cards) { date in 22 | 23 | GeometryReader { geo in 24 | ZStack{ 25 | RoundedRectangle(cornerRadius: 25, style: .continuous) 26 | .foregroundColor(/*@START_MENU_TOKEN@*/.white/*@END_MENU_TOKEN@*/) 27 | 28 | Text("\(date.number)") 29 | } 30 | 31 | } 32 | .shadow(radius: 4) 33 | .padding(.all, 10.0) 34 | 35 | 36 | }.onAppear(perform: loadData) 37 | 38 | Button(action: { 39 | NotificationCenter.default.post(name: NSNotification.Name.init(CardNotification), object: 5) 40 | }, label: { 41 | Text("Button5") 42 | }) 43 | 44 | Button(action: { 45 | NotificationCenter.default.post(name: NSNotification.Name.init(CardNotification), object: 2) 46 | }, label: { 47 | Text("Button2") 48 | }) 49 | } 50 | } 51 | 52 | 53 | func loadData() { 54 | 55 | cards = [Card(number: "1"), 56 | Card(number: "2"), 57 | Card(number: "3"), 58 | Card(number: "4"), 59 | Card(number: "5"), 60 | Card(number: "6"), 61 | Card(number: "7"), 62 | Card(number: "8"), 63 | Card(number: "9"), 64 | Card(number: "10"), 65 | Card(number: "11"), 66 | Card(number: "12"), 67 | Card(number: "13"), 68 | Card(number: "14"), 69 | Card(number: "15"), 70 | Card(number: "16"), 71 | Card(number: "17"), 72 | Card(number: "18"), 73 | Card(number: "19"), 74 | Card(number: "20") 75 | ] 76 | } 77 | } 78 | 79 | struct ContentView_Previews: PreviewProvider { 80 | static var previews: some View { 81 | ContentView() 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Card/Card/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 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UIApplicationSceneManifest 24 | 25 | UIApplicationSupportsMultipleScenes 26 | 27 | 28 | UIApplicationSupportsIndirectInputEvents 29 | 30 | UILaunchScreen 31 | 32 | UIRequiredDeviceCapabilities 33 | 34 | armv7 35 | 36 | UISupportedInterfaceOrientations 37 | 38 | UIInterfaceOrientationPortrait 39 | UIInterfaceOrientationLandscapeLeft 40 | UIInterfaceOrientationLandscapeRight 41 | 42 | UISupportedInterfaceOrientations~ipad 43 | 44 | UIInterfaceOrientationPortrait 45 | UIInterfaceOrientationPortraitUpsideDown 46 | UIInterfaceOrientationLandscapeLeft 47 | UIInterfaceOrientationLandscapeRight 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /Card/Card/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Card/Card/SwipeCardView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SwipeCardView.swift 3 | // Card 4 | // 5 | // Created by iOS on 2021/1/26. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct SwipeCardView: View { 11 | @State var offset = CGSize.zero 12 | let card: Card 13 | var removal: (() -> Void)? = nil 14 | 15 | var body: some View { 16 | ZStack{ 17 | RoundedRectangle(cornerRadius: 25, style: .continuous) 18 | .background(Color.red) 19 | } 20 | .frame(width: 250, height: 450) 21 | .rotationEffect(.degrees(Double(offset.width/250))) 22 | .offset(offset) 23 | .gesture( 24 | DragGesture() 25 | .onChanged { gesture in 26 | self.offset = gesture.translation 27 | } 28 | 29 | .onEnded { _ in 30 | if abs(self.offset.width) > 100 { 31 | // 移除卡片 32 | self.removal?() 33 | } else { 34 | self.offset = .zero 35 | } 36 | 37 | 38 | } 39 | 40 | ) 41 | .animation(.spring()) 42 | } 43 | } 44 | 45 | struct SwipeCardView_Previews: PreviewProvider { 46 | static var previews: some View { 47 | SwipeCardView(card: Card(prompt: "", answer: "")) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 jinhu 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CardStack-SwiftUI 2 | SwiftUI实现的堆叠卡片,可以拖动切换下一张卡片 3 | 4 | ![](1.gif) --------------------------------------------------------------------------------