├── .gitignore ├── .swift-version ├── Example ├── Example.xcodeproj │ ├── project.pbxproj │ └── xcuserdata │ │ └── joejoe.xcuserdatad │ │ └── xcschemes │ │ ├── Example.xcscheme │ │ └── xcschememanagement.plist ├── Example │ ├── AppDelegate.swift │ ├── Assets.xcassets │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ └── Contents.json │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── Info.plist │ ├── ViewController.swift │ ├── image.jpg │ └── mask.png └── ExampleTests │ ├── ExampleTests.swift │ └── Info.plist ├── LICENSE ├── README.md ├── ScratchCard.podspec ├── ScratchCard.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── joejoe.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── joejoe.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── ScratchCard.xcscheme │ └── xcschememanagement.plist └── ScratchCard ├── Info.plist ├── ScratchCard.h ├── ScratchUIView.swift ├── ScratchView.swift ├── result.gif └── result.jpg /.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 | *.xcuserstate 23 | 24 | ## Obj-C/Swift specific 25 | *.hmap 26 | *.ipa 27 | *.dSYM.zip 28 | *.dSYM 29 | 30 | ## Playgrounds 31 | timeline.xctimeline 32 | playground.xcworkspace 33 | 34 | # Swift Package Manager 35 | # 36 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 37 | # Packages/ 38 | .build/ 39 | 40 | # CocoaPods 41 | # 42 | # We recommend against adding the Pods directory to your .gitignore. However 43 | # you should judge for yourself, the pros and cons are mentioned at: 44 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 45 | # 46 | # Pods/ 47 | 48 | # Carthage 49 | # 50 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 51 | # Carthage/Checkouts 52 | 53 | Carthage/Build 54 | 55 | # fastlane 56 | # 57 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 58 | # screenshots whenever they are needed. 59 | # For more information about the recommended setup visit: 60 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 61 | 62 | fastlane/report.xml 63 | fastlane/Preview.html 64 | fastlane/screenshots 65 | fastlane/test_output -------------------------------------------------------------------------------- /.swift-version: -------------------------------------------------------------------------------- 1 | 3.0 2 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | B4285D6A1E77D4830008466D /* ScratchCard.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B4285D691E77D4830008466D /* ScratchCard.framework */; }; 11 | B4285D6B1E77D4830008466D /* ScratchCard.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = B4285D691E77D4830008466D /* ScratchCard.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 12 | B4389DAD1DFFF7B100B3DDE4 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4389DAC1DFFF7B100B3DDE4 /* AppDelegate.swift */; }; 13 | B4389DAF1DFFF7B100B3DDE4 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4389DAE1DFFF7B100B3DDE4 /* ViewController.swift */; }; 14 | B4389DB21DFFF7B100B3DDE4 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B4389DB01DFFF7B100B3DDE4 /* Main.storyboard */; }; 15 | B4389DB41DFFF7B100B3DDE4 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B4389DB31DFFF7B100B3DDE4 /* Assets.xcassets */; }; 16 | B4389DB71DFFF7B100B3DDE4 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B4389DB51DFFF7B100B3DDE4 /* LaunchScreen.storyboard */; }; 17 | B4389DC21DFFF7B100B3DDE4 /* ExampleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4389DC11DFFF7B100B3DDE4 /* ExampleTests.swift */; }; 18 | B4389DDB1DFFFC4C00B3DDE4 /* image.jpg in Resources */ = {isa = PBXBuildFile; fileRef = B4389DD91DFFFC4C00B3DDE4 /* image.jpg */; }; 19 | B4389DDC1DFFFC4C00B3DDE4 /* mask.png in Resources */ = {isa = PBXBuildFile; fileRef = B4389DDA1DFFFC4C00B3DDE4 /* mask.png */; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXContainerItemProxy section */ 23 | B4389DBE1DFFF7B100B3DDE4 /* PBXContainerItemProxy */ = { 24 | isa = PBXContainerItemProxy; 25 | containerPortal = B4389DA11DFFF7B100B3DDE4 /* Project object */; 26 | proxyType = 1; 27 | remoteGlobalIDString = B4389DA81DFFF7B100B3DDE4; 28 | remoteInfo = Example; 29 | }; 30 | /* End PBXContainerItemProxy section */ 31 | 32 | /* Begin PBXCopyFilesBuildPhase section */ 33 | B45007D01E07EFB000AB92E2 /* Embed Frameworks */ = { 34 | isa = PBXCopyFilesBuildPhase; 35 | buildActionMask = 2147483647; 36 | dstPath = ""; 37 | dstSubfolderSpec = 10; 38 | files = ( 39 | B4285D6B1E77D4830008466D /* ScratchCard.framework in Embed Frameworks */, 40 | ); 41 | name = "Embed Frameworks"; 42 | runOnlyForDeploymentPostprocessing = 0; 43 | }; 44 | /* End PBXCopyFilesBuildPhase section */ 45 | 46 | /* Begin PBXFileReference section */ 47 | B4285D691E77D4830008466D /* ScratchCard.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = ScratchCard.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 48 | B4389DA91DFFF7B100B3DDE4 /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; 49 | B4389DAC1DFFF7B100B3DDE4 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 50 | B4389DAE1DFFF7B100B3DDE4 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 51 | B4389DB11DFFF7B100B3DDE4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 52 | B4389DB31DFFF7B100B3DDE4 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 53 | B4389DB61DFFF7B100B3DDE4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 54 | B4389DB81DFFF7B100B3DDE4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 55 | B4389DBD1DFFF7B100B3DDE4 /* ExampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ExampleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 56 | B4389DC11DFFF7B100B3DDE4 /* ExampleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExampleTests.swift; sourceTree = ""; }; 57 | B4389DC31DFFF7B100B3DDE4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 58 | B4389DD91DFFFC4C00B3DDE4 /* image.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = image.jpg; sourceTree = ""; }; 59 | B4389DDA1DFFFC4C00B3DDE4 /* mask.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = mask.png; sourceTree = ""; }; 60 | /* End PBXFileReference section */ 61 | 62 | /* Begin PBXFrameworksBuildPhase section */ 63 | B4389DA61DFFF7B100B3DDE4 /* Frameworks */ = { 64 | isa = PBXFrameworksBuildPhase; 65 | buildActionMask = 2147483647; 66 | files = ( 67 | B4285D6A1E77D4830008466D /* ScratchCard.framework in Frameworks */, 68 | ); 69 | runOnlyForDeploymentPostprocessing = 0; 70 | }; 71 | B4389DBA1DFFF7B100B3DDE4 /* Frameworks */ = { 72 | isa = PBXFrameworksBuildPhase; 73 | buildActionMask = 2147483647; 74 | files = ( 75 | ); 76 | runOnlyForDeploymentPostprocessing = 0; 77 | }; 78 | /* End PBXFrameworksBuildPhase section */ 79 | 80 | /* Begin PBXGroup section */ 81 | B4389DA01DFFF7B100B3DDE4 = { 82 | isa = PBXGroup; 83 | children = ( 84 | B4285D691E77D4830008466D /* ScratchCard.framework */, 85 | B4389DAB1DFFF7B100B3DDE4 /* Example */, 86 | B4389DC01DFFF7B100B3DDE4 /* ExampleTests */, 87 | B4389DAA1DFFF7B100B3DDE4 /* Products */, 88 | ); 89 | sourceTree = ""; 90 | }; 91 | B4389DAA1DFFF7B100B3DDE4 /* Products */ = { 92 | isa = PBXGroup; 93 | children = ( 94 | B4389DA91DFFF7B100B3DDE4 /* Example.app */, 95 | B4389DBD1DFFF7B100B3DDE4 /* ExampleTests.xctest */, 96 | ); 97 | name = Products; 98 | sourceTree = ""; 99 | }; 100 | B4389DAB1DFFF7B100B3DDE4 /* Example */ = { 101 | isa = PBXGroup; 102 | children = ( 103 | B4389DD91DFFFC4C00B3DDE4 /* image.jpg */, 104 | B4389DDA1DFFFC4C00B3DDE4 /* mask.png */, 105 | B4389DAC1DFFF7B100B3DDE4 /* AppDelegate.swift */, 106 | B4389DAE1DFFF7B100B3DDE4 /* ViewController.swift */, 107 | B4389DB01DFFF7B100B3DDE4 /* Main.storyboard */, 108 | B4389DB31DFFF7B100B3DDE4 /* Assets.xcassets */, 109 | B4389DB51DFFF7B100B3DDE4 /* LaunchScreen.storyboard */, 110 | B4389DB81DFFF7B100B3DDE4 /* Info.plist */, 111 | ); 112 | path = Example; 113 | sourceTree = ""; 114 | }; 115 | B4389DC01DFFF7B100B3DDE4 /* ExampleTests */ = { 116 | isa = PBXGroup; 117 | children = ( 118 | B4389DC11DFFF7B100B3DDE4 /* ExampleTests.swift */, 119 | B4389DC31DFFF7B100B3DDE4 /* Info.plist */, 120 | ); 121 | path = ExampleTests; 122 | sourceTree = ""; 123 | }; 124 | /* End PBXGroup section */ 125 | 126 | /* Begin PBXNativeTarget section */ 127 | B4389DA81DFFF7B100B3DDE4 /* Example */ = { 128 | isa = PBXNativeTarget; 129 | buildConfigurationList = B4389DC61DFFF7B100B3DDE4 /* Build configuration list for PBXNativeTarget "Example" */; 130 | buildPhases = ( 131 | B4389DA51DFFF7B100B3DDE4 /* Sources */, 132 | B4389DA61DFFF7B100B3DDE4 /* Frameworks */, 133 | B4389DA71DFFF7B100B3DDE4 /* Resources */, 134 | B45007D01E07EFB000AB92E2 /* Embed Frameworks */, 135 | ); 136 | buildRules = ( 137 | ); 138 | dependencies = ( 139 | ); 140 | name = Example; 141 | productName = Example; 142 | productReference = B4389DA91DFFF7B100B3DDE4 /* Example.app */; 143 | productType = "com.apple.product-type.application"; 144 | }; 145 | B4389DBC1DFFF7B100B3DDE4 /* ExampleTests */ = { 146 | isa = PBXNativeTarget; 147 | buildConfigurationList = B4389DC91DFFF7B100B3DDE4 /* Build configuration list for PBXNativeTarget "ExampleTests" */; 148 | buildPhases = ( 149 | B4389DB91DFFF7B100B3DDE4 /* Sources */, 150 | B4389DBA1DFFF7B100B3DDE4 /* Frameworks */, 151 | B4389DBB1DFFF7B100B3DDE4 /* Resources */, 152 | ); 153 | buildRules = ( 154 | ); 155 | dependencies = ( 156 | B4389DBF1DFFF7B100B3DDE4 /* PBXTargetDependency */, 157 | ); 158 | name = ExampleTests; 159 | productName = ExampleTests; 160 | productReference = B4389DBD1DFFF7B100B3DDE4 /* ExampleTests.xctest */; 161 | productType = "com.apple.product-type.bundle.unit-test"; 162 | }; 163 | /* End PBXNativeTarget section */ 164 | 165 | /* Begin PBXProject section */ 166 | B4389DA11DFFF7B100B3DDE4 /* Project object */ = { 167 | isa = PBXProject; 168 | attributes = { 169 | LastSwiftUpdateCheck = 0810; 170 | LastUpgradeCheck = 0810; 171 | ORGANIZATIONNAME = Joe; 172 | TargetAttributes = { 173 | B4389DA81DFFF7B100B3DDE4 = { 174 | CreatedOnToolsVersion = 8.1; 175 | DevelopmentTeam = 79FT757QWM; 176 | LastSwiftMigration = 0820; 177 | ProvisioningStyle = Automatic; 178 | }; 179 | B4389DBC1DFFF7B100B3DDE4 = { 180 | CreatedOnToolsVersion = 8.1; 181 | DevelopmentTeam = Y3YDLKH37F; 182 | LastSwiftMigration = 0820; 183 | ProvisioningStyle = Automatic; 184 | TestTargetID = B4389DA81DFFF7B100B3DDE4; 185 | }; 186 | }; 187 | }; 188 | buildConfigurationList = B4389DA41DFFF7B100B3DDE4 /* Build configuration list for PBXProject "Example" */; 189 | compatibilityVersion = "Xcode 3.2"; 190 | developmentRegion = English; 191 | hasScannedForEncodings = 0; 192 | knownRegions = ( 193 | en, 194 | Base, 195 | ); 196 | mainGroup = B4389DA01DFFF7B100B3DDE4; 197 | productRefGroup = B4389DAA1DFFF7B100B3DDE4 /* Products */; 198 | projectDirPath = ""; 199 | projectRoot = ""; 200 | targets = ( 201 | B4389DA81DFFF7B100B3DDE4 /* Example */, 202 | B4389DBC1DFFF7B100B3DDE4 /* ExampleTests */, 203 | ); 204 | }; 205 | /* End PBXProject section */ 206 | 207 | /* Begin PBXResourcesBuildPhase section */ 208 | B4389DA71DFFF7B100B3DDE4 /* Resources */ = { 209 | isa = PBXResourcesBuildPhase; 210 | buildActionMask = 2147483647; 211 | files = ( 212 | B4389DB71DFFF7B100B3DDE4 /* LaunchScreen.storyboard in Resources */, 213 | B4389DDC1DFFFC4C00B3DDE4 /* mask.png in Resources */, 214 | B4389DB41DFFF7B100B3DDE4 /* Assets.xcassets in Resources */, 215 | B4389DB21DFFF7B100B3DDE4 /* Main.storyboard in Resources */, 216 | B4389DDB1DFFFC4C00B3DDE4 /* image.jpg in Resources */, 217 | ); 218 | runOnlyForDeploymentPostprocessing = 0; 219 | }; 220 | B4389DBB1DFFF7B100B3DDE4 /* Resources */ = { 221 | isa = PBXResourcesBuildPhase; 222 | buildActionMask = 2147483647; 223 | files = ( 224 | ); 225 | runOnlyForDeploymentPostprocessing = 0; 226 | }; 227 | /* End PBXResourcesBuildPhase section */ 228 | 229 | /* Begin PBXSourcesBuildPhase section */ 230 | B4389DA51DFFF7B100B3DDE4 /* Sources */ = { 231 | isa = PBXSourcesBuildPhase; 232 | buildActionMask = 2147483647; 233 | files = ( 234 | B4389DAF1DFFF7B100B3DDE4 /* ViewController.swift in Sources */, 235 | B4389DAD1DFFF7B100B3DDE4 /* AppDelegate.swift in Sources */, 236 | ); 237 | runOnlyForDeploymentPostprocessing = 0; 238 | }; 239 | B4389DB91DFFF7B100B3DDE4 /* Sources */ = { 240 | isa = PBXSourcesBuildPhase; 241 | buildActionMask = 2147483647; 242 | files = ( 243 | B4389DC21DFFF7B100B3DDE4 /* ExampleTests.swift in Sources */, 244 | ); 245 | runOnlyForDeploymentPostprocessing = 0; 246 | }; 247 | /* End PBXSourcesBuildPhase section */ 248 | 249 | /* Begin PBXTargetDependency section */ 250 | B4389DBF1DFFF7B100B3DDE4 /* PBXTargetDependency */ = { 251 | isa = PBXTargetDependency; 252 | target = B4389DA81DFFF7B100B3DDE4 /* Example */; 253 | targetProxy = B4389DBE1DFFF7B100B3DDE4 /* PBXContainerItemProxy */; 254 | }; 255 | /* End PBXTargetDependency section */ 256 | 257 | /* Begin PBXVariantGroup section */ 258 | B4389DB01DFFF7B100B3DDE4 /* Main.storyboard */ = { 259 | isa = PBXVariantGroup; 260 | children = ( 261 | B4389DB11DFFF7B100B3DDE4 /* Base */, 262 | ); 263 | name = Main.storyboard; 264 | sourceTree = ""; 265 | }; 266 | B4389DB51DFFF7B100B3DDE4 /* LaunchScreen.storyboard */ = { 267 | isa = PBXVariantGroup; 268 | children = ( 269 | B4389DB61DFFF7B100B3DDE4 /* Base */, 270 | ); 271 | name = LaunchScreen.storyboard; 272 | sourceTree = ""; 273 | }; 274 | /* End PBXVariantGroup section */ 275 | 276 | /* Begin XCBuildConfiguration section */ 277 | B4389DC41DFFF7B100B3DDE4 /* Debug */ = { 278 | isa = XCBuildConfiguration; 279 | buildSettings = { 280 | ALWAYS_SEARCH_USER_PATHS = NO; 281 | CLANG_ANALYZER_NONNULL = YES; 282 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 283 | CLANG_CXX_LIBRARY = "libc++"; 284 | CLANG_ENABLE_MODULES = YES; 285 | CLANG_ENABLE_OBJC_ARC = YES; 286 | CLANG_WARN_BOOL_CONVERSION = YES; 287 | CLANG_WARN_CONSTANT_CONVERSION = YES; 288 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 289 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 290 | CLANG_WARN_EMPTY_BODY = YES; 291 | CLANG_WARN_ENUM_CONVERSION = YES; 292 | CLANG_WARN_INFINITE_RECURSION = YES; 293 | CLANG_WARN_INT_CONVERSION = YES; 294 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 295 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 296 | CLANG_WARN_UNREACHABLE_CODE = YES; 297 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 298 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 299 | COPY_PHASE_STRIP = NO; 300 | DEBUG_INFORMATION_FORMAT = dwarf; 301 | ENABLE_STRICT_OBJC_MSGSEND = YES; 302 | ENABLE_TESTABILITY = YES; 303 | GCC_C_LANGUAGE_STANDARD = gnu99; 304 | GCC_DYNAMIC_NO_PIC = NO; 305 | GCC_NO_COMMON_BLOCKS = YES; 306 | GCC_OPTIMIZATION_LEVEL = 0; 307 | GCC_PREPROCESSOR_DEFINITIONS = ( 308 | "DEBUG=1", 309 | "$(inherited)", 310 | ); 311 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 312 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 313 | GCC_WARN_UNDECLARED_SELECTOR = YES; 314 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 315 | GCC_WARN_UNUSED_FUNCTION = YES; 316 | GCC_WARN_UNUSED_VARIABLE = YES; 317 | IPHONEOS_DEPLOYMENT_TARGET = 10.1; 318 | MTL_ENABLE_DEBUG_INFO = YES; 319 | ONLY_ACTIVE_ARCH = YES; 320 | SDKROOT = iphoneos; 321 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 322 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 323 | }; 324 | name = Debug; 325 | }; 326 | B4389DC51DFFF7B100B3DDE4 /* Release */ = { 327 | isa = XCBuildConfiguration; 328 | buildSettings = { 329 | ALWAYS_SEARCH_USER_PATHS = NO; 330 | CLANG_ANALYZER_NONNULL = YES; 331 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 332 | CLANG_CXX_LIBRARY = "libc++"; 333 | CLANG_ENABLE_MODULES = YES; 334 | CLANG_ENABLE_OBJC_ARC = YES; 335 | CLANG_WARN_BOOL_CONVERSION = YES; 336 | CLANG_WARN_CONSTANT_CONVERSION = YES; 337 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 338 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 339 | CLANG_WARN_EMPTY_BODY = YES; 340 | CLANG_WARN_ENUM_CONVERSION = YES; 341 | CLANG_WARN_INFINITE_RECURSION = YES; 342 | CLANG_WARN_INT_CONVERSION = YES; 343 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 344 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 345 | CLANG_WARN_UNREACHABLE_CODE = YES; 346 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 347 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 348 | COPY_PHASE_STRIP = NO; 349 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 350 | ENABLE_NS_ASSERTIONS = NO; 351 | ENABLE_STRICT_OBJC_MSGSEND = YES; 352 | GCC_C_LANGUAGE_STANDARD = gnu99; 353 | GCC_NO_COMMON_BLOCKS = YES; 354 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 355 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 356 | GCC_WARN_UNDECLARED_SELECTOR = YES; 357 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 358 | GCC_WARN_UNUSED_FUNCTION = YES; 359 | GCC_WARN_UNUSED_VARIABLE = YES; 360 | IPHONEOS_DEPLOYMENT_TARGET = 10.1; 361 | MTL_ENABLE_DEBUG_INFO = NO; 362 | SDKROOT = iphoneos; 363 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 364 | VALIDATE_PRODUCT = YES; 365 | }; 366 | name = Release; 367 | }; 368 | B4389DC71DFFF7B100B3DDE4 /* Debug */ = { 369 | isa = XCBuildConfiguration; 370 | buildSettings = { 371 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 372 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 373 | DEVELOPMENT_TEAM = 79FT757QWM; 374 | FRAMEWORK_SEARCH_PATHS = ( 375 | "$(inherited)", 376 | "$(PROJECT_DIR)", 377 | ); 378 | INFOPLIST_FILE = Example/Info.plist; 379 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 380 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 381 | PRODUCT_BUNDLE_IDENTIFIER = Scratch.Example; 382 | PRODUCT_NAME = "$(TARGET_NAME)"; 383 | SWIFT_VERSION = 3.0; 384 | }; 385 | name = Debug; 386 | }; 387 | B4389DC81DFFF7B100B3DDE4 /* Release */ = { 388 | isa = XCBuildConfiguration; 389 | buildSettings = { 390 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 391 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 392 | DEVELOPMENT_TEAM = 79FT757QWM; 393 | FRAMEWORK_SEARCH_PATHS = ( 394 | "$(inherited)", 395 | "$(PROJECT_DIR)", 396 | ); 397 | INFOPLIST_FILE = Example/Info.plist; 398 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 399 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 400 | PRODUCT_BUNDLE_IDENTIFIER = Scratch.Example; 401 | PRODUCT_NAME = "$(TARGET_NAME)"; 402 | SWIFT_VERSION = 3.0; 403 | }; 404 | name = Release; 405 | }; 406 | B4389DCA1DFFF7B100B3DDE4 /* Debug */ = { 407 | isa = XCBuildConfiguration; 408 | buildSettings = { 409 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 410 | BUNDLE_LOADER = "$(TEST_HOST)"; 411 | DEVELOPMENT_TEAM = Y3YDLKH37F; 412 | INFOPLIST_FILE = ExampleTests/Info.plist; 413 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 414 | PRODUCT_BUNDLE_IDENTIFIER = joe.ExampleTests; 415 | PRODUCT_NAME = "$(TARGET_NAME)"; 416 | SWIFT_VERSION = 3.0; 417 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Example.app/Example"; 418 | }; 419 | name = Debug; 420 | }; 421 | B4389DCB1DFFF7B100B3DDE4 /* Release */ = { 422 | isa = XCBuildConfiguration; 423 | buildSettings = { 424 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 425 | BUNDLE_LOADER = "$(TEST_HOST)"; 426 | DEVELOPMENT_TEAM = Y3YDLKH37F; 427 | INFOPLIST_FILE = ExampleTests/Info.plist; 428 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 429 | PRODUCT_BUNDLE_IDENTIFIER = joe.ExampleTests; 430 | PRODUCT_NAME = "$(TARGET_NAME)"; 431 | SWIFT_VERSION = 3.0; 432 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Example.app/Example"; 433 | }; 434 | name = Release; 435 | }; 436 | /* End XCBuildConfiguration section */ 437 | 438 | /* Begin XCConfigurationList section */ 439 | B4389DA41DFFF7B100B3DDE4 /* Build configuration list for PBXProject "Example" */ = { 440 | isa = XCConfigurationList; 441 | buildConfigurations = ( 442 | B4389DC41DFFF7B100B3DDE4 /* Debug */, 443 | B4389DC51DFFF7B100B3DDE4 /* Release */, 444 | ); 445 | defaultConfigurationIsVisible = 0; 446 | defaultConfigurationName = Release; 447 | }; 448 | B4389DC61DFFF7B100B3DDE4 /* Build configuration list for PBXNativeTarget "Example" */ = { 449 | isa = XCConfigurationList; 450 | buildConfigurations = ( 451 | B4389DC71DFFF7B100B3DDE4 /* Debug */, 452 | B4389DC81DFFF7B100B3DDE4 /* Release */, 453 | ); 454 | defaultConfigurationIsVisible = 0; 455 | defaultConfigurationName = Release; 456 | }; 457 | B4389DC91DFFF7B100B3DDE4 /* Build configuration list for PBXNativeTarget "ExampleTests" */ = { 458 | isa = XCConfigurationList; 459 | buildConfigurations = ( 460 | B4389DCA1DFFF7B100B3DDE4 /* Debug */, 461 | B4389DCB1DFFF7B100B3DDE4 /* Release */, 462 | ); 463 | defaultConfigurationIsVisible = 0; 464 | defaultConfigurationName = Release; 465 | }; 466 | /* End XCConfigurationList section */ 467 | }; 468 | rootObject = B4389DA11DFFF7B100B3DDE4 /* Project object */; 469 | } 470 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/xcuserdata/joejoe.xcuserdatad/xcschemes/Example.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 49 | 50 | 51 | 52 | 53 | 54 | 64 | 66 | 72 | 73 | 74 | 75 | 76 | 77 | 83 | 85 | 91 | 92 | 93 | 94 | 96 | 97 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/xcuserdata/joejoe.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | Example.xcscheme 8 | 9 | orderHint 10 | 1 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | B4389DA81DFFF7B100B3DDE4 16 | 17 | primary 18 | 19 | 20 | B4389DBC1DFFF7B100B3DDE4 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Example/Example/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Example 4 | // 5 | // Created by JoeJoe on 2016/12/13. 6 | // Copyright © 2016年 Joe. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Example/Example/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 | "info" : { 45 | "version" : 1, 46 | "author" : "xcode" 47 | } 48 | } -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Example/Example/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 | -------------------------------------------------------------------------------- /Example/Example/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /Example/Example/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /Example/Example/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // Example 4 | // 5 | // Created by JoeJoe on 2016/12/13. 6 | // Copyright © 2016年 Joe. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import ScratchCard 11 | 12 | class ViewController: UIViewController, ScratchUIViewDelegate { 13 | 14 | var scratchCard: ScratchUIView! 15 | @IBOutlet weak var textField: UITextField! 16 | override func viewDidLoad() { 17 | super.viewDidLoad() 18 | // Do any additional setup after loading the view, typically from a nib. 19 | 20 | scratchCard = ScratchUIView(frame: CGRect(x:50, y:80, width:320, height:480), Coupon: "image.jpg", MaskImage: "mask.png", ScratchWidth: CGFloat(40)) 21 | 22 | scratchCard.delegate = self 23 | 24 | self.view.addSubview(scratchCard) 25 | } 26 | 27 | override func didReceiveMemoryWarning() { 28 | super.didReceiveMemoryWarning() 29 | // Dispose of any resources that can be recreated. 30 | } 31 | 32 | @IBAction func getScratchPercent(_ sender: Any) { 33 | let scratchPercent: Double = scratchCard.getScratchPercent() 34 | textField.text = String(format: "%.2f", scratchPercent * 100) + "%" 35 | } 36 | 37 | //Scratch Began Event(optional) 38 | func scratchBegan(_ view: ScratchUIView) { 39 | print("scratchBegan") 40 | 41 | ////Get the Scratch Position in ScratchCard(coordinate origin is at the lower left corner) 42 | let position = Int(view.scratchPosition.x).description + "," + Int(view.scratchPosition.y).description 43 | print(position) 44 | 45 | } 46 | 47 | //Scratch Moved Event(optional) 48 | func scratchMoved(_ view: ScratchUIView) { 49 | let scratchPercent: Double = self.scratchCard.getScratchPercent() 50 | self.textField.text = String(format: "%.2f", scratchPercent * 100) + "%" 51 | print("scratchMoved") 52 | ////Get the Scratch Position in ScratchCard(coordinate origin is at the lower left corner) 53 | let position = Int(view.scratchPosition.x).description + "," + Int(view.scratchPosition.y).description 54 | print(position) 55 | } 56 | 57 | //Scratch Ended Event(optional) 58 | func scratchEnded(_ view: ScratchUIView) { 59 | print("scratchEnded") 60 | 61 | ////Get the Scratch Position in ScratchCard(coordinate origin is at the lower left corner) 62 | let position = Int(view.scratchPosition.x).description + "," + Int(view.scratchPosition.y).description 63 | print(position) 64 | 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Example/Example/image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joehour/ScratchCard/dd5c34c8ee3214e7d1cfaae146d12ced602932a3/Example/Example/image.jpg -------------------------------------------------------------------------------- /Example/Example/mask.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joehour/ScratchCard/dd5c34c8ee3214e7d1cfaae146d12ced602932a3/Example/Example/mask.png -------------------------------------------------------------------------------- /Example/ExampleTests/ExampleTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ExampleTests.swift 3 | // ExampleTests 4 | // 5 | // Created by JoeJoe on 2016/12/13. 6 | // Copyright © 2016年 Joe. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | //@testable import Example 11 | 12 | class ExampleTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testExample() { 25 | // This is an example of a functional test case. 26 | // Use XCTAssert and related functions to verify your tests produce the correct results. 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measure { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /Example/ExampleTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 joehour 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 | # ScratchCard 2 | 3 | 4 | Requirements 5 | ---------- 6 | 7 | - iOS 8.0+ 8 | - Xcode 8.0+ Swift 3 9 | 10 | 11 | ## Installation 12 | 13 | #### CocoaPods 14 | 15 | Check out [Get Started](https://guides.cocoapods.org/using/getting-started.html) tab on [cocoapods.org](http://cocoapods.org/). 16 | 17 | To use ScratchCard in your project add the following 'Podfile' to your project 18 | 19 | pod 'ScratchCard', '~> 1.1.3' 20 | 21 | Then run: 22 | 23 | pod install 24 | 25 | #### Source Code 26 | 27 | Copy the ScratchView.swift and ScratchUIView.swift to your project. 28 | 29 | Go ahead and import ScratchCard to your file. 30 | 31 | 32 | Example 33 | ---------- 34 | 35 | #### Please check out the Example project included. 36 | 37 | 38 | Usage 39 | ---------- 40 | 41 | * Sample: 42 | ```swift 43 | import ScratchCard 44 | 45 | class ViewController: UIViewController { 46 | 47 | var scratchCard: ScratchUIView! 48 | override func viewDidLoad() { 49 | super.viewDidLoad() 50 | 51 | scratchCard = ScratchUIView(frame: CGRect(x:50, y:80, width:320, height:480),Coupon: "image.jpg", MaskImage: "mask.png", ScratchWidth: CGFloat(40)) 52 | 53 | self.view.addSubview(scratchCard) 54 | } 55 | } 56 | ``` 57 | 58 | Scratched Percent 59 | ---------- 60 | 61 | It is easy to get the scratched percent. 62 | 63 | * Sample: 64 | ```swift 65 | let scratchPercent: Double = scratchCard.getScratchPercent() 66 | ``` 67 | 68 | Handle Scratch Event 69 | ---------- 70 | 71 | It is easy to handle the scratch event(ScratchBegan, ScratchMoved, and ScratchEnded). 72 | 73 | You can get the Scratch Position in the ScratchCard. 74 | 75 | Please set the ScratchUIViewDelegate in your code. 76 | 77 | * Sample: 78 | ```swift 79 | class ViewController: UIViewController, ScratchUIViewDelegate { 80 | 81 | var scratchCard: ScratchUIView! 82 | override func viewDidLoad() { 83 | super.viewDidLoad() 84 | 85 | scratchCard = ScratchUIView(frame: CGRect(x:50, y:80, width:320, height:480), Coupon: "image", MaskImage: "mask", ScratchWidth: CGFloat(40)) 86 | scratchCard.delegate = self 87 | 88 | self.view.addSubview(scratchCard) 89 | } 90 | 91 | //Scratch Began Event(optional) 92 | func scratchBegan(_ view: ScratchUIView) { 93 | print("scratchBegan") 94 | 95 | ////Get the Scratch Position in ScratchCard(coordinate origin is at the lower left corner) 96 | let position = Int(view.scratchPosition.x).description + "," + Int(view.scratchPosition.y).description 97 | print(position) 98 | 99 | } 100 | 101 | //Scratch Moved Event(optional) 102 | func scratchMoved(_ view: ScratchUIView) { 103 | let scratchPercent: Double = scratchCard.getScratchPercent() 104 | textField.text = String(format: "%.2f", scratchPercent * 100) + "%" 105 | print("scratchMoved") 106 | 107 | ////Get the Scratch Position in ScratchCard(coordinate origin is at the lower left corner) 108 | let position = Int(view.scratchPosition.x).description + "," + Int(view.scratchPosition.y).description 109 | print(position) 110 | } 111 | 112 | //Scratch Ended Event(optional) 113 | func scratchEnded(_ view: ScratchUIView) { 114 | print("scratchEnded") 115 | 116 | ////Get the Scratch Position in ScratchCard(coordinate origin is at the lower left corner) 117 | let position = Int(view.scratchPosition.x).description + "," + Int(view.scratchPosition.y).description 118 | print(position) 119 | 120 | } 121 | } 122 | ``` 123 | 124 | ## License 125 | ScratchCard is available under the MIT License. 126 | 127 | Copyright © 2016 Joe. 128 | -------------------------------------------------------------------------------- /ScratchCard.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "ScratchCard" 3 | s.version = "1.1.3" 4 | s.license = "MIT" 5 | s.summary = "A ScratchCard view on iOS(swift)." 6 | s.homepage = "https://github.com/joehour/ScratchCard" 7 | s.authors = { "joe" => "joemail168@gmail.com" } 8 | s.source = { :git => "https://github.com/joehour/ScratchCard.git", :tag => s.version.to_s } 9 | s.requires_arc = true 10 | s.ios.deployment_target = "8.0" 11 | s.source_files = "ScratchCard/*.{swift}" 12 | end 13 | -------------------------------------------------------------------------------- /ScratchCard.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | B4FDC4BF1CC0C1FB00D6B52C /* ScratchCard.h in Headers */ = {isa = PBXBuildFile; fileRef = B4FDC4BE1CC0C1FB00D6B52C /* ScratchCard.h */; settings = {ATTRIBUTES = (Public, ); }; }; 11 | B4FDC4C71CC0C28700D6B52C /* ScratchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4FDC4C61CC0C28700D6B52C /* ScratchView.swift */; }; 12 | B4FDC4C91CC0C2EE00D6B52C /* ScratchUIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4FDC4C81CC0C2EE00D6B52C /* ScratchUIView.swift */; }; 13 | /* End PBXBuildFile section */ 14 | 15 | /* Begin PBXContainerItemProxy section */ 16 | B4389DD11DFFF7B200B3DDE4 /* PBXContainerItemProxy */ = { 17 | isa = PBXContainerItemProxy; 18 | containerPortal = B4389DCC1DFFF7B100B3DDE4 /* Example.xcodeproj */; 19 | proxyType = 2; 20 | remoteGlobalIDString = B4389DA91DFFF7B100B3DDE4; 21 | remoteInfo = Example; 22 | }; 23 | B4389DD31DFFF7B200B3DDE4 /* PBXContainerItemProxy */ = { 24 | isa = PBXContainerItemProxy; 25 | containerPortal = B4389DCC1DFFF7B100B3DDE4 /* Example.xcodeproj */; 26 | proxyType = 2; 27 | remoteGlobalIDString = B4389DBD1DFFF7B100B3DDE4; 28 | remoteInfo = ExampleTests; 29 | }; 30 | /* End PBXContainerItemProxy section */ 31 | 32 | /* Begin PBXFileReference section */ 33 | B4389DCC1DFFF7B100B3DDE4 /* Example.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Example.xcodeproj; path = Example/Example.xcodeproj; sourceTree = ""; }; 34 | B4FDC4BB1CC0C1FB00D6B52C /* ScratchCard.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ScratchCard.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 35 | B4FDC4BE1CC0C1FB00D6B52C /* ScratchCard.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ScratchCard.h; sourceTree = ""; }; 36 | B4FDC4C01CC0C1FB00D6B52C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 37 | B4FDC4C61CC0C28700D6B52C /* ScratchView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScratchView.swift; sourceTree = ""; }; 38 | B4FDC4C81CC0C2EE00D6B52C /* ScratchUIView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScratchUIView.swift; sourceTree = ""; }; 39 | /* End PBXFileReference section */ 40 | 41 | /* Begin PBXFrameworksBuildPhase section */ 42 | B4FDC4B71CC0C1FB00D6B52C /* Frameworks */ = { 43 | isa = PBXFrameworksBuildPhase; 44 | buildActionMask = 2147483647; 45 | files = ( 46 | ); 47 | runOnlyForDeploymentPostprocessing = 0; 48 | }; 49 | /* End PBXFrameworksBuildPhase section */ 50 | 51 | /* Begin PBXGroup section */ 52 | B4389DCD1DFFF7B100B3DDE4 /* Products */ = { 53 | isa = PBXGroup; 54 | children = ( 55 | B4389DD21DFFF7B200B3DDE4 /* Example.app */, 56 | B4389DD41DFFF7B200B3DDE4 /* ExampleTests.xctest */, 57 | ); 58 | name = Products; 59 | sourceTree = ""; 60 | }; 61 | B4FDC4B11CC0C1FB00D6B52C = { 62 | isa = PBXGroup; 63 | children = ( 64 | B4389DCC1DFFF7B100B3DDE4 /* Example.xcodeproj */, 65 | B4FDC4BD1CC0C1FB00D6B52C /* ScratchCard */, 66 | B4FDC4BC1CC0C1FB00D6B52C /* Products */, 67 | ); 68 | sourceTree = ""; 69 | }; 70 | B4FDC4BC1CC0C1FB00D6B52C /* Products */ = { 71 | isa = PBXGroup; 72 | children = ( 73 | B4FDC4BB1CC0C1FB00D6B52C /* ScratchCard.framework */, 74 | ); 75 | name = Products; 76 | sourceTree = ""; 77 | }; 78 | B4FDC4BD1CC0C1FB00D6B52C /* ScratchCard */ = { 79 | isa = PBXGroup; 80 | children = ( 81 | B4FDC4BE1CC0C1FB00D6B52C /* ScratchCard.h */, 82 | B4FDC4C01CC0C1FB00D6B52C /* Info.plist */, 83 | B4FDC4C61CC0C28700D6B52C /* ScratchView.swift */, 84 | B4FDC4C81CC0C2EE00D6B52C /* ScratchUIView.swift */, 85 | ); 86 | path = ScratchCard; 87 | sourceTree = ""; 88 | }; 89 | /* End PBXGroup section */ 90 | 91 | /* Begin PBXHeadersBuildPhase section */ 92 | B4FDC4B81CC0C1FB00D6B52C /* Headers */ = { 93 | isa = PBXHeadersBuildPhase; 94 | buildActionMask = 2147483647; 95 | files = ( 96 | B4FDC4BF1CC0C1FB00D6B52C /* ScratchCard.h in Headers */, 97 | ); 98 | runOnlyForDeploymentPostprocessing = 0; 99 | }; 100 | /* End PBXHeadersBuildPhase section */ 101 | 102 | /* Begin PBXNativeTarget section */ 103 | B4FDC4BA1CC0C1FB00D6B52C /* ScratchCard */ = { 104 | isa = PBXNativeTarget; 105 | buildConfigurationList = B4FDC4C31CC0C1FB00D6B52C /* Build configuration list for PBXNativeTarget "ScratchCard" */; 106 | buildPhases = ( 107 | B4FDC4B61CC0C1FB00D6B52C /* Sources */, 108 | B4FDC4B71CC0C1FB00D6B52C /* Frameworks */, 109 | B4FDC4B81CC0C1FB00D6B52C /* Headers */, 110 | B4FDC4B91CC0C1FB00D6B52C /* Resources */, 111 | ); 112 | buildRules = ( 113 | ); 114 | dependencies = ( 115 | ); 116 | name = ScratchCard; 117 | productName = ScratchCard; 118 | productReference = B4FDC4BB1CC0C1FB00D6B52C /* ScratchCard.framework */; 119 | productType = "com.apple.product-type.framework"; 120 | }; 121 | /* End PBXNativeTarget section */ 122 | 123 | /* Begin PBXProject section */ 124 | B4FDC4B21CC0C1FB00D6B52C /* Project object */ = { 125 | isa = PBXProject; 126 | attributes = { 127 | LastUpgradeCheck = 0810; 128 | ORGANIZATIONNAME = JoeJoe; 129 | TargetAttributes = { 130 | B4FDC4BA1CC0C1FB00D6B52C = { 131 | CreatedOnToolsVersion = 7.2; 132 | DevelopmentTeam = 79FT757QWM; 133 | LastSwiftMigration = 0810; 134 | ProvisioningStyle = Automatic; 135 | }; 136 | }; 137 | }; 138 | buildConfigurationList = B4FDC4B51CC0C1FB00D6B52C /* Build configuration list for PBXProject "ScratchCard" */; 139 | compatibilityVersion = "Xcode 3.2"; 140 | developmentRegion = English; 141 | hasScannedForEncodings = 0; 142 | knownRegions = ( 143 | en, 144 | ); 145 | mainGroup = B4FDC4B11CC0C1FB00D6B52C; 146 | productRefGroup = B4FDC4BC1CC0C1FB00D6B52C /* Products */; 147 | projectDirPath = ""; 148 | projectReferences = ( 149 | { 150 | ProductGroup = B4389DCD1DFFF7B100B3DDE4 /* Products */; 151 | ProjectRef = B4389DCC1DFFF7B100B3DDE4 /* Example.xcodeproj */; 152 | }, 153 | ); 154 | projectRoot = ""; 155 | targets = ( 156 | B4FDC4BA1CC0C1FB00D6B52C /* ScratchCard */, 157 | ); 158 | }; 159 | /* End PBXProject section */ 160 | 161 | /* Begin PBXReferenceProxy section */ 162 | B4389DD21DFFF7B200B3DDE4 /* Example.app */ = { 163 | isa = PBXReferenceProxy; 164 | fileType = wrapper.application; 165 | path = Example.app; 166 | remoteRef = B4389DD11DFFF7B200B3DDE4 /* PBXContainerItemProxy */; 167 | sourceTree = BUILT_PRODUCTS_DIR; 168 | }; 169 | B4389DD41DFFF7B200B3DDE4 /* ExampleTests.xctest */ = { 170 | isa = PBXReferenceProxy; 171 | fileType = wrapper.cfbundle; 172 | path = ExampleTests.xctest; 173 | remoteRef = B4389DD31DFFF7B200B3DDE4 /* PBXContainerItemProxy */; 174 | sourceTree = BUILT_PRODUCTS_DIR; 175 | }; 176 | /* End PBXReferenceProxy section */ 177 | 178 | /* Begin PBXResourcesBuildPhase section */ 179 | B4FDC4B91CC0C1FB00D6B52C /* Resources */ = { 180 | isa = PBXResourcesBuildPhase; 181 | buildActionMask = 2147483647; 182 | files = ( 183 | ); 184 | runOnlyForDeploymentPostprocessing = 0; 185 | }; 186 | /* End PBXResourcesBuildPhase section */ 187 | 188 | /* Begin PBXSourcesBuildPhase section */ 189 | B4FDC4B61CC0C1FB00D6B52C /* Sources */ = { 190 | isa = PBXSourcesBuildPhase; 191 | buildActionMask = 2147483647; 192 | files = ( 193 | B4FDC4C71CC0C28700D6B52C /* ScratchView.swift in Sources */, 194 | B4FDC4C91CC0C2EE00D6B52C /* ScratchUIView.swift in Sources */, 195 | ); 196 | runOnlyForDeploymentPostprocessing = 0; 197 | }; 198 | /* End PBXSourcesBuildPhase section */ 199 | 200 | /* Begin XCBuildConfiguration section */ 201 | B4FDC4C11CC0C1FB00D6B52C /* Debug */ = { 202 | isa = XCBuildConfiguration; 203 | buildSettings = { 204 | ALWAYS_SEARCH_USER_PATHS = NO; 205 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 206 | CLANG_CXX_LIBRARY = "libc++"; 207 | CLANG_ENABLE_MODULES = YES; 208 | CLANG_ENABLE_OBJC_ARC = YES; 209 | CLANG_WARN_BOOL_CONVERSION = YES; 210 | CLANG_WARN_CONSTANT_CONVERSION = YES; 211 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 212 | CLANG_WARN_EMPTY_BODY = YES; 213 | CLANG_WARN_ENUM_CONVERSION = YES; 214 | CLANG_WARN_INFINITE_RECURSION = YES; 215 | CLANG_WARN_INT_CONVERSION = YES; 216 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 217 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 218 | CLANG_WARN_UNREACHABLE_CODE = YES; 219 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 220 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 221 | COPY_PHASE_STRIP = NO; 222 | CURRENT_PROJECT_VERSION = 1; 223 | DEBUG_INFORMATION_FORMAT = dwarf; 224 | ENABLE_STRICT_OBJC_MSGSEND = YES; 225 | ENABLE_TESTABILITY = YES; 226 | GCC_C_LANGUAGE_STANDARD = gnu99; 227 | GCC_DYNAMIC_NO_PIC = NO; 228 | GCC_NO_COMMON_BLOCKS = YES; 229 | GCC_OPTIMIZATION_LEVEL = 0; 230 | GCC_PREPROCESSOR_DEFINITIONS = ( 231 | "DEBUG=1", 232 | "$(inherited)", 233 | ); 234 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 235 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 236 | GCC_WARN_UNDECLARED_SELECTOR = YES; 237 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 238 | GCC_WARN_UNUSED_FUNCTION = YES; 239 | GCC_WARN_UNUSED_VARIABLE = YES; 240 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 241 | MTL_ENABLE_DEBUG_INFO = YES; 242 | ONLY_ACTIVE_ARCH = YES; 243 | SDKROOT = iphoneos; 244 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 245 | SWIFT_VERSION = ""; 246 | TARGETED_DEVICE_FAMILY = "1,2"; 247 | VERSIONING_SYSTEM = "apple-generic"; 248 | VERSION_INFO_PREFIX = ""; 249 | }; 250 | name = Debug; 251 | }; 252 | B4FDC4C21CC0C1FB00D6B52C /* Release */ = { 253 | isa = XCBuildConfiguration; 254 | buildSettings = { 255 | ALWAYS_SEARCH_USER_PATHS = NO; 256 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 257 | CLANG_CXX_LIBRARY = "libc++"; 258 | CLANG_ENABLE_MODULES = YES; 259 | CLANG_ENABLE_OBJC_ARC = YES; 260 | CLANG_WARN_BOOL_CONVERSION = YES; 261 | CLANG_WARN_CONSTANT_CONVERSION = YES; 262 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 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_OBJC_ROOT_CLASS = YES_ERROR; 268 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 269 | CLANG_WARN_UNREACHABLE_CODE = YES; 270 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 271 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 272 | COPY_PHASE_STRIP = NO; 273 | CURRENT_PROJECT_VERSION = 1; 274 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 275 | ENABLE_NS_ASSERTIONS = NO; 276 | ENABLE_STRICT_OBJC_MSGSEND = YES; 277 | GCC_C_LANGUAGE_STANDARD = gnu99; 278 | GCC_NO_COMMON_BLOCKS = YES; 279 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 280 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 281 | GCC_WARN_UNDECLARED_SELECTOR = YES; 282 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 283 | GCC_WARN_UNUSED_FUNCTION = YES; 284 | GCC_WARN_UNUSED_VARIABLE = YES; 285 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 286 | MTL_ENABLE_DEBUG_INFO = NO; 287 | SDKROOT = iphoneos; 288 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 289 | SWIFT_VERSION = ""; 290 | TARGETED_DEVICE_FAMILY = "1,2"; 291 | VALIDATE_PRODUCT = YES; 292 | VERSIONING_SYSTEM = "apple-generic"; 293 | VERSION_INFO_PREFIX = ""; 294 | }; 295 | name = Release; 296 | }; 297 | B4FDC4C41CC0C1FB00D6B52C /* Debug */ = { 298 | isa = XCBuildConfiguration; 299 | buildSettings = { 300 | CLANG_ENABLE_MODULES = YES; 301 | CODE_SIGN_IDENTITY = "iPhone Developer"; 302 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 303 | DEFINES_MODULE = YES; 304 | DEVELOPMENT_TEAM = 79FT757QWM; 305 | DYLIB_COMPATIBILITY_VERSION = 1; 306 | DYLIB_CURRENT_VERSION = 1; 307 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 308 | INFOPLIST_FILE = ScratchCard/Info.plist; 309 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 310 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 311 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 312 | PRODUCT_BUNDLE_IDENTIFIER = joe.ScratchCard; 313 | PRODUCT_NAME = "$(TARGET_NAME)"; 314 | PROVISIONING_PROFILE_SPECIFIER = ""; 315 | SKIP_INSTALL = YES; 316 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 317 | SWIFT_VERSION = 3.0; 318 | }; 319 | name = Debug; 320 | }; 321 | B4FDC4C51CC0C1FB00D6B52C /* Release */ = { 322 | isa = XCBuildConfiguration; 323 | buildSettings = { 324 | CLANG_ENABLE_MODULES = YES; 325 | CODE_SIGN_IDENTITY = "iPhone Developer"; 326 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 327 | DEFINES_MODULE = YES; 328 | DEVELOPMENT_TEAM = 79FT757QWM; 329 | DYLIB_COMPATIBILITY_VERSION = 1; 330 | DYLIB_CURRENT_VERSION = 1; 331 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 332 | INFOPLIST_FILE = ScratchCard/Info.plist; 333 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 334 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 335 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 336 | PRODUCT_BUNDLE_IDENTIFIER = joe.ScratchCard; 337 | PRODUCT_NAME = "$(TARGET_NAME)"; 338 | PROVISIONING_PROFILE_SPECIFIER = ""; 339 | SKIP_INSTALL = YES; 340 | SWIFT_VERSION = 3.0; 341 | }; 342 | name = Release; 343 | }; 344 | /* End XCBuildConfiguration section */ 345 | 346 | /* Begin XCConfigurationList section */ 347 | B4FDC4B51CC0C1FB00D6B52C /* Build configuration list for PBXProject "ScratchCard" */ = { 348 | isa = XCConfigurationList; 349 | buildConfigurations = ( 350 | B4FDC4C11CC0C1FB00D6B52C /* Debug */, 351 | B4FDC4C21CC0C1FB00D6B52C /* Release */, 352 | ); 353 | defaultConfigurationIsVisible = 0; 354 | defaultConfigurationName = Release; 355 | }; 356 | B4FDC4C31CC0C1FB00D6B52C /* Build configuration list for PBXNativeTarget "ScratchCard" */ = { 357 | isa = XCConfigurationList; 358 | buildConfigurations = ( 359 | B4FDC4C41CC0C1FB00D6B52C /* Debug */, 360 | B4FDC4C51CC0C1FB00D6B52C /* Release */, 361 | ); 362 | defaultConfigurationIsVisible = 0; 363 | defaultConfigurationName = Release; 364 | }; 365 | /* End XCConfigurationList section */ 366 | }; 367 | rootObject = B4FDC4B21CC0C1FB00D6B52C /* Project object */; 368 | } 369 | -------------------------------------------------------------------------------- /ScratchCard.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ScratchCard.xcodeproj/project.xcworkspace/xcuserdata/joejoe.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joehour/ScratchCard/dd5c34c8ee3214e7d1cfaae146d12ced602932a3/ScratchCard.xcodeproj/project.xcworkspace/xcuserdata/joejoe.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /ScratchCard.xcodeproj/xcuserdata/joejoe.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 20 | 21 | 22 | 24 | 36 | 37 | 38 | 40 | 52 | 53 | 54 | 56 | 68 | 69 | 70 | 72 | 84 | 85 | 86 | 88 | 100 | 101 | 102 | 104 | 116 | 117 | 118 | 120 | 132 | 133 | 134 | 136 | 148 | 149 | 150 | 152 | 164 | 165 | 166 | 168 | 180 | 181 | 182 | 184 | 196 | 197 | 198 | 200 | 212 | 213 | 214 | 216 | 228 | 229 | 230 | 232 | 244 | 245 | 246 | 248 | 260 | 261 | 262 | 264 | 276 | 277 | 278 | 280 | 292 | 293 | 294 | 296 | 308 | 309 | 310 | 312 | 322 | 323 | 324 | 326 | 338 | 339 | 340 | 342 | 352 | 353 | 354 | 356 | 366 | 367 | 368 | 370 | 382 | 383 | 384 | 386 | 396 | 397 | 398 | 400 | 410 | 411 | 412 | 414 | 426 | 427 | 428 | 430 | 442 | 443 | 444 | 446 | 458 | 459 | 460 | 462 | 474 | 475 | 476 | 478 | 490 | 491 | 492 | 494 | 506 | 507 | 508 | 510 | 522 | 523 | 524 | 526 | 538 | 539 | 540 | 542 | 554 | 555 | 556 | 558 | 570 | 571 | 572 | 574 | 586 | 587 | 588 | 590 | 602 | 603 | 604 | 606 | 618 | 619 | 620 | 622 | 634 | 635 | 636 | 638 | 650 | 651 | 652 | 654 | 666 | 667 | 668 | 670 | 682 | 683 | 684 | 685 | 686 | -------------------------------------------------------------------------------- /ScratchCard.xcodeproj/xcuserdata/joejoe.xcuserdatad/xcschemes/ScratchCard.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /ScratchCard.xcodeproj/xcuserdata/joejoe.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | ScratchCard.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | B4FDC4BA1CC0C1FB00D6B52C 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /ScratchCard/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0.10 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /ScratchCard/ScratchCard.h: -------------------------------------------------------------------------------- 1 | // 2 | // ScratchCard.h 3 | // ScratchCard 4 | // 5 | // Created by JoeJoe on 2016/4/15. 6 | // Copyright © 2016年 JoeJoe. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for ScratchCard. 12 | FOUNDATION_EXPORT double ScratchCardVersionNumber; 13 | 14 | //! Project version string for ScratchCard. 15 | FOUNDATION_EXPORT const unsigned char ScratchCardVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /ScratchCard/ScratchUIView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ScratchUIView.swift 3 | // ScratchCard 4 | // 5 | // Created by JoeJoe on 2016/4/15. 6 | // Copyright © 2016年 JoeJoe. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | 12 | 13 | var uiScratchWidth: CGFloat! 14 | 15 | @objc public protocol ScratchUIViewDelegate: class { 16 | @objc optional func scratchBegan(_ view: ScratchUIView) 17 | @objc optional func scratchMoved(_ view: ScratchUIView) 18 | @objc optional func scratchEnded(_ view: ScratchUIView) 19 | } 20 | 21 | open class ScratchUIView: UIView, ScratchViewDelegate { 22 | 23 | open weak var delegate: ScratchUIViewDelegate! 24 | public var scratchView: ScratchView! 25 | var maskImage: UIImageView! 26 | var maskPath: String! 27 | var coupponPath: String! 28 | open var scratchPosition: CGPoint! 29 | override init(frame: CGRect) { 30 | super.init(frame: frame) 31 | self.Init() 32 | } 33 | 34 | open func getScratchPercent() -> Double { 35 | return scratchView.getAlphaPixelPercent() 36 | } 37 | 38 | public init(frame: CGRect, Coupon: String, MaskImage: String, ScratchWidth: CGFloat) { 39 | super.init(frame: frame) 40 | coupponPath = Coupon 41 | maskPath = MaskImage 42 | uiScratchWidth = ScratchWidth 43 | self.Init() 44 | } 45 | 46 | required public init?(coder aDecoder: NSCoder) { 47 | super.init(coder: aDecoder) 48 | self.InitXib() 49 | } 50 | 51 | fileprivate func Init() { 52 | maskImage = UIImageView(image: UIImage(named: maskPath))//UIImageView(image: processPixels(in: UIImage(named: maskPath)!)) 53 | scratchView = ScratchView(frame: self.frame, CouponImage: coupponPath, ScratchWidth: uiScratchWidth) 54 | 55 | maskImage.frame = CGRect(x: 0, y: 0, width: self.frame.width, height: self.frame.height) 56 | scratchView.frame = CGRect(x: 0, y: 0, width: self.frame.width, height: self.frame.height) 57 | scratchView.delegate = self 58 | self.addSubview(maskImage) 59 | self.addSubview(scratchView) 60 | self.bringSubview(toFront: scratchView) 61 | 62 | } 63 | 64 | internal func began(_ view: ScratchView) { 65 | if self.delegate != nil { 66 | guard self.delegate.scratchBegan != nil else { 67 | return 68 | } 69 | if view.position.x >= 0 && view.position.x <= view.frame.width && view.position.y >= 0 && view.position.y <= view.frame.height { 70 | scratchPosition = view.position 71 | } 72 | self.delegate.scratchBegan!(self) 73 | } 74 | } 75 | 76 | internal func moved(_ view: ScratchView) { 77 | if self.delegate != nil { 78 | guard self.delegate.scratchMoved != nil else { 79 | return 80 | } 81 | if view.position.x >= 0 && view.position.x <= view.frame.width && view.position.y >= 0 && view.position.y <= view.frame.height { 82 | scratchPosition = view.position 83 | } 84 | self.delegate.scratchMoved!(self) 85 | } 86 | } 87 | 88 | internal func ended(_ view: ScratchView) { 89 | if self.delegate != nil { 90 | guard self.delegate.scratchEnded != nil else { 91 | return 92 | } 93 | if view.position.x >= 0 && view.position.x <= view.frame.width && view.position.y >= 0 && view.position.y <= view.frame.height { 94 | scratchPosition = view.position 95 | } 96 | self.delegate.scratchEnded!(self) 97 | } 98 | } 99 | 100 | fileprivate func InitXib() { 101 | 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /ScratchCard/ScratchView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ScratchView.swift 3 | // ScratchCard 4 | // 5 | // Created by JoeJoe on 2016/4/15. 6 | // Copyright © 2016年 JoeJoe. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | 12 | var width: Int! 13 | var height: Int! 14 | var location: CGPoint! 15 | var previousLocation: CGPoint! 16 | var firstTouch: Bool! 17 | //var scratchable: CGImage! 18 | var scratched: CGImage! 19 | var alphaPixels: CGContext! 20 | var provider: CGDataProvider! 21 | var pixelBuffer: UnsafeMutablePointer! 22 | var couponImage: String! 23 | var scratchWidth: CGFloat! 24 | var contentLayer: CALayer! 25 | var maskLayer: CAShapeLayer! 26 | 27 | internal protocol ScratchViewDelegate: class { 28 | func began(_ view: ScratchView) 29 | func moved(_ view: ScratchView) 30 | func ended(_ view: ScratchView) 31 | } 32 | 33 | open class ScratchView: UIView { 34 | 35 | internal weak var delegate: ScratchViewDelegate! 36 | internal var position: CGPoint! 37 | override init(frame: CGRect) { 38 | super.init(frame: frame) 39 | self.Init() 40 | } 41 | 42 | init(frame: CGRect, CouponImage: String, ScratchWidth: CGFloat) { 43 | super.init(frame: frame) 44 | couponImage = CouponImage 45 | scratchWidth = ScratchWidth 46 | self.Init() 47 | } 48 | 49 | required public init?(coder aDecoder: NSCoder) { 50 | super.init(coder: aDecoder) 51 | 52 | self.InitXib() 53 | } 54 | 55 | fileprivate func Init() { 56 | let image = processPixels(image: UIImage(named: couponImage)!) 57 | if image != nil { 58 | scratched = image?.cgImage 59 | } else { 60 | scratched = UIImage(named: couponImage)?.cgImage 61 | } 62 | width = (Int)(self.frame.width) 63 | height = (Int)(self.frame.height) 64 | 65 | self.isOpaque = false 66 | 67 | let colorspace: CGColorSpace = CGColorSpaceCreateDeviceGray() 68 | 69 | let pixels: CFMutableData = CFDataCreateMutable(nil, width * height) 70 | 71 | alphaPixels = CGContext( data: CFDataGetMutableBytePtr(pixels), width: width, height: height, bitsPerComponent: 8, bytesPerRow: width, space: colorspace, bitmapInfo: CGImageAlphaInfo.none.rawValue) 72 | 73 | alphaPixels.setFillColor(UIColor.black.cgColor) 74 | alphaPixels.setStrokeColor(UIColor.white.cgColor) 75 | alphaPixels.setLineWidth(scratchWidth) 76 | alphaPixels.setLineCap(CGLineCap.round) 77 | 78 | //fix mask initialization error on simulator device(issue9) 79 | pixelBuffer = alphaPixels.data?.bindMemory(to: UInt8.self, capacity: width * height) 80 | var byteIndex: Int = 0 81 | for _ in 0...width * height { 82 | if pixelBuffer?[byteIndex] != 0 { 83 | pixelBuffer?[byteIndex] = 0 84 | } 85 | byteIndex += 1 86 | } 87 | provider = CGDataProvider(data: pixels) 88 | 89 | maskLayer = CAShapeLayer() 90 | maskLayer.frame = CGRect(x:0, y:0, width:width, height:height) 91 | maskLayer.backgroundColor = UIColor.clear.cgColor 92 | 93 | contentLayer = CALayer() 94 | contentLayer.frame = CGRect(x:0, y:0, width:width, height:height) 95 | contentLayer.contents = scratched 96 | contentLayer.mask = maskLayer 97 | self.layer.addSublayer(contentLayer) 98 | } 99 | 100 | fileprivate func InitXib() { 101 | 102 | } 103 | 104 | override open func touchesBegan(_ touches: Set, 105 | with event: UIEvent?) { 106 | if let touch = touches.first { 107 | firstTouch = true 108 | location = CGPoint(x: touch.location(in: self).x, y: touch.location(in: self).y) 109 | 110 | position = location 111 | 112 | if self.delegate != nil { 113 | self.delegate.began(self) 114 | } 115 | } 116 | } 117 | 118 | override open func touchesMoved(_ touches: Set, 119 | with event: UIEvent?) { 120 | if let touch = touches.first { 121 | if firstTouch! { 122 | firstTouch = false 123 | previousLocation = CGPoint(x: touch.previousLocation(in: self).x, y: touch.previousLocation(in: self).y) 124 | } else { 125 | 126 | location = CGPoint(x: touch.location(in: self).x, y: touch.location(in: self).y) 127 | previousLocation = CGPoint(x: touch.previousLocation(in: self).x, y: touch.previousLocation(in: self).y) 128 | } 129 | 130 | position = previousLocation 131 | 132 | renderLineFromPoint(previousLocation, end: location) 133 | 134 | if self.delegate != nil { 135 | self.delegate.moved(self) 136 | } 137 | } 138 | } 139 | 140 | override open func touchesEnded(_ touches: Set, 141 | with event: UIEvent?) { 142 | if let touch = touches.first { 143 | if firstTouch! { 144 | firstTouch = false 145 | previousLocation = CGPoint(x: touch.previousLocation(in: self).x, y: touch.previousLocation(in: self).y) 146 | 147 | position = previousLocation 148 | 149 | renderLineFromPoint(previousLocation, end: location) 150 | 151 | if self.delegate != nil { 152 | self.delegate.ended(self) 153 | } 154 | } 155 | } 156 | } 157 | 158 | // override open func draw(_ rect: CGRect) { 159 | // UIGraphicsGetCurrentContext()?.saveGState() 160 | // contentLayer.render(in: UIGraphicsGetCurrentContext()!) 161 | // UIGraphicsGetCurrentContext()?.restoreGState() 162 | // 163 | // } 164 | 165 | func renderLineFromPoint(_ start: CGPoint, end: CGPoint) { 166 | alphaPixels.move(to: CGPoint(x: start.x, y: start.y)) 167 | alphaPixels.addLine(to: CGPoint(x: end.x, y: end.y)) 168 | alphaPixels.strokePath() 169 | drawLine(onLayer: maskLayer, fromPoint: start, toPoint: end) 170 | } 171 | 172 | func drawLine(onLayer layer: CALayer, fromPoint start: CGPoint, toPoint end: CGPoint) { 173 | let line = CAShapeLayer() 174 | let linePath = UIBezierPath() 175 | linePath.move(to: start) 176 | linePath.addLine(to: end) 177 | linePath.lineCapStyle = .round 178 | line.lineWidth = scratchWidth 179 | line.path = linePath.cgPath 180 | line.opacity = 1 181 | line.strokeColor = UIColor.white.cgColor 182 | line.lineCap = "round" 183 | layer.addSublayer(line) 184 | } 185 | 186 | internal func getAlphaPixelPercent() -> Double { 187 | var byteIndex: Int = 0 188 | var count: Double = 0 189 | let data = UnsafePointer(pixelBuffer) 190 | for _ in 0...width * height { 191 | if data![byteIndex] != 0 { 192 | count += 1 193 | } 194 | byteIndex += 1 195 | } 196 | return count / Double(width * height) 197 | } 198 | 199 | // iOS 11.2 error 200 | // internal func getAlphaPixelPercent() -> Double { 201 | // let pixelData = provider.data 202 | // let data: UnsafePointer = CFDataGetBytePtr(pixelData) 203 | // let imageWidth: size_t = alphaPixels.makeImage()!.width 204 | // let imageHeight: size_t = alphaPixels.makeImage()!.height 205 | // 206 | // var byteIndex: Int = 0 207 | // var count: Double = 0 208 | // 209 | // for _ in 0...imageWidth * imageHeight { 210 | // if data[byteIndex] != 0 { 211 | // count += 1 212 | // } 213 | // byteIndex += 1 214 | // } 215 | // 216 | // return count / Double(imageWidth * imageHeight) 217 | // } 218 | 219 | func processPixels(image: UIImage) -> UIImage? { 220 | guard let inputCGImage = image.cgImage else { 221 | print("unable to get cgImage") 222 | return nil 223 | } 224 | let colorSpace = CGColorSpaceCreateDeviceRGB() 225 | let width = inputCGImage.width 226 | let height = inputCGImage.height 227 | let bytesPerPixel = 4 228 | let bitsPerComponent = 8 229 | let bytesPerRow = bytesPerPixel * width 230 | let bitmapInfo = CGImageAlphaInfo.premultipliedLast.rawValue | CGBitmapInfo.byteOrder32Little.rawValue 231 | 232 | guard let context = CGContext(data: nil, width: width, height: height, bitsPerComponent: bitsPerComponent, bytesPerRow: bytesPerRow, space: colorSpace, bitmapInfo: bitmapInfo) else { 233 | return nil 234 | } 235 | context.draw(inputCGImage, in: CGRect(x: 0, y: 0, width: width, height: height)) 236 | 237 | guard let buffer = context.data else { 238 | return nil 239 | } 240 | 241 | let pixelBuffer = buffer.bindMemory(to: UInt8.self, capacity: width * height) 242 | var byteIndex: Int = 0 243 | for _ in 0...width * height { 244 | if pixelBuffer[byteIndex] == 0 { 245 | pixelBuffer[byteIndex] = 255 246 | pixelBuffer[byteIndex+1] = 255 247 | pixelBuffer[byteIndex+2] = 255 248 | pixelBuffer[byteIndex+3] = 255 249 | } 250 | byteIndex += 4 251 | } 252 | let outputCGImage = context.makeImage()! 253 | let outputImage = UIImage(cgImage: outputCGImage, scale: image.scale, orientation: image.imageOrientation) 254 | return outputImage 255 | } 256 | } 257 | -------------------------------------------------------------------------------- /ScratchCard/result.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joehour/ScratchCard/dd5c34c8ee3214e7d1cfaae146d12ced602932a3/ScratchCard/result.gif -------------------------------------------------------------------------------- /ScratchCard/result.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joehour/ScratchCard/dd5c34c8ee3214e7d1cfaae146d12ced602932a3/ScratchCard/result.jpg --------------------------------------------------------------------------------