├── .gitignore ├── .swift-version ├── Example ├── .DS_Store ├── MCScratchImageView.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata └── MCScratchImageView │ ├── .DS_Store │ ├── AppDelegate.swift │ ├── Assets.xcassets │ ├── .DS_Store │ ├── AppIcon.appiconset │ │ ├── Contents.json │ │ ├── icon-1024.png │ │ ├── icon-20-ipad.png │ │ ├── icon-20@2x-ipad.png │ │ ├── icon-20@2x.png │ │ ├── icon-20@3x.png │ │ ├── icon-29-ipad.png │ │ ├── icon-29.png │ │ ├── icon-29@2x-ipad.png │ │ ├── icon-29@2x.png │ │ ├── icon-29@3x.png │ │ ├── icon-40.png │ │ ├── icon-40@2x.png │ │ ├── icon-40@3x.png │ │ ├── icon-50.png │ │ ├── icon-50@2x.png │ │ ├── icon-57.png │ │ ├── icon-57@2x.png │ │ ├── icon-60@2x.png │ │ ├── icon-60@3x.png │ │ ├── icon-72.png │ │ ├── icon-72@2x.png │ │ ├── icon-76.png │ │ ├── icon-76@2x.png │ │ └── icon-83.5@2x.png │ ├── Contents.json │ ├── barItem.imageset │ │ ├── Contents.json │ │ └── barItem.png │ ├── barItem_selected.imageset │ │ ├── Contents.json │ │ └── barItem_selected.png │ ├── iTunesArtwork.png │ └── iTunesArtwork@2x.png │ ├── Base.lproj │ └── LaunchScreen.storyboard │ ├── CustomScratchViewController.swift │ ├── Info.plist │ ├── MCScratchImageView │ └── MCScratchImageView.swift │ ├── Main.storyboard │ ├── MainTabBarController.swift │ ├── PopScratchViewController.swift │ ├── Resources │ ├── barItem.png │ ├── barrage_selected.png │ ├── bonus1-scratch.png │ ├── bonus1.png │ ├── bonus2-scratch.png │ └── bonus2.png │ └── ScratchViewController.swift ├── GIFShowcase ├── Showcase1.gif └── Showcase2.gif ├── LICENSE ├── MCScratchImageView.podspec ├── MCScratchImageView └── MCScratchImageView.swift └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xccheckout 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | ## Playgrounds 32 | timeline.xctimeline 33 | playground.xcworkspace 34 | 35 | # Swift Package Manager 36 | # 37 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 38 | # Packages/ 39 | # Package.pins 40 | .build/ 41 | 42 | # CocoaPods 43 | # 44 | # We recommend against adding the Pods directory to your .gitignore. However 45 | # you should judge for yourself, the pros and cons are mentioned at: 46 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 47 | # 48 | # Pods/ 49 | 50 | # Carthage 51 | # 52 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 53 | # Carthage/Checkouts 54 | 55 | Carthage/Build 56 | 57 | # fastlane 58 | # 59 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 60 | # screenshots whenever they are needed. 61 | # For more information about the recommended setup visit: 62 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 63 | 64 | fastlane/report.xml 65 | fastlane/Preview.html 66 | fastlane/screenshots 67 | fastlane/test_output 68 | -------------------------------------------------------------------------------- /.swift-version: -------------------------------------------------------------------------------- 1 | 4.0 2 | -------------------------------------------------------------------------------- /Example/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/.DS_Store -------------------------------------------------------------------------------- /Example/MCScratchImageView.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 48; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | E714024F1FF5FAD2003B1727 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = E714024E1FF5FAD2003B1727 /* README.md */; }; 11 | E7533F211FF3E58700FB3785 /* MainTabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7533F201FF3E58700FB3785 /* MainTabBarController.swift */; }; 12 | E7533F271FF40EAC00FB3785 /* CustomScratchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7533F261FF40EAC00FB3785 /* CustomScratchViewController.swift */; }; 13 | E7533F291FF4C78900FB3785 /* PopScratchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7533F281FF4C78900FB3785 /* PopScratchViewController.swift */; }; 14 | E7533F2B1FF4C8B300FB3785 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E7533F2A1FF4C8B300FB3785 /* Main.storyboard */; }; 15 | E758DA831FF3D7F7003239FC /* ScratchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E758DA821FF3D7F7003239FC /* ScratchViewController.swift */; }; 16 | E79058591FF25129000138BF /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E79058581FF25129000138BF /* AppDelegate.swift */; }; 17 | E79058601FF25129000138BF /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E790585F1FF25129000138BF /* Assets.xcassets */; }; 18 | E79058631FF25129000138BF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E79058611FF25129000138BF /* LaunchScreen.storyboard */; }; 19 | E790586C1FF25173000138BF /* MCScratchImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E790586B1FF25173000138BF /* MCScratchImageView.swift */; }; 20 | E7E8E6001FF3D46C0065E6E6 /* bonus1.png in Resources */ = {isa = PBXBuildFile; fileRef = E7E8E5FC1FF3D46C0065E6E6 /* bonus1.png */; }; 21 | E7E8E6011FF3D46C0065E6E6 /* bonus1-scratch.png in Resources */ = {isa = PBXBuildFile; fileRef = E7E8E5FD1FF3D46C0065E6E6 /* bonus1-scratch.png */; }; 22 | E7E8E6021FF3D46C0065E6E6 /* bonus2-scratch.png in Resources */ = {isa = PBXBuildFile; fileRef = E7E8E5FE1FF3D46C0065E6E6 /* bonus2-scratch.png */; }; 23 | E7E8E6031FF3D46C0065E6E6 /* bonus2.png in Resources */ = {isa = PBXBuildFile; fileRef = E7E8E5FF1FF3D46C0065E6E6 /* bonus2.png */; }; 24 | E7E8E6041FF3D4750065E6E6 /* bonus1-scratch.png in Sources */ = {isa = PBXBuildFile; fileRef = E7E8E5FD1FF3D46C0065E6E6 /* bonus1-scratch.png */; }; 25 | E7E8E6051FF3D4750065E6E6 /* bonus1.png in Sources */ = {isa = PBXBuildFile; fileRef = E7E8E5FC1FF3D46C0065E6E6 /* bonus1.png */; }; 26 | E7E8E6061FF3D4750065E6E6 /* bonus2-scratch.png in Sources */ = {isa = PBXBuildFile; fileRef = E7E8E5FE1FF3D46C0065E6E6 /* bonus2-scratch.png */; }; 27 | E7E8E6071FF3D4750065E6E6 /* bonus2.png in Sources */ = {isa = PBXBuildFile; fileRef = E7E8E5FF1FF3D46C0065E6E6 /* bonus2.png */; }; 28 | /* End PBXBuildFile section */ 29 | 30 | /* Begin PBXFileReference section */ 31 | E714024E1FF5FAD2003B1727 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; }; 32 | E7533F201FF3E58700FB3785 /* MainTabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTabBarController.swift; sourceTree = ""; }; 33 | E7533F261FF40EAC00FB3785 /* CustomScratchViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomScratchViewController.swift; sourceTree = ""; }; 34 | E7533F281FF4C78900FB3785 /* PopScratchViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PopScratchViewController.swift; sourceTree = ""; }; 35 | E7533F2A1FF4C8B300FB3785 /* Main.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = ""; }; 36 | E758DA821FF3D7F7003239FC /* ScratchViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScratchViewController.swift; sourceTree = ""; }; 37 | E79058551FF25129000138BF /* MCScratchImageView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MCScratchImageView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 38 | E79058581FF25129000138BF /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 39 | E790585F1FF25129000138BF /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 40 | E79058621FF25129000138BF /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 41 | E79058641FF25129000138BF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 42 | E790586B1FF25173000138BF /* MCScratchImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MCScratchImageView.swift; sourceTree = ""; }; 43 | E7E8E5FC1FF3D46C0065E6E6 /* bonus1.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = bonus1.png; sourceTree = ""; }; 44 | E7E8E5FD1FF3D46C0065E6E6 /* bonus1-scratch.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "bonus1-scratch.png"; sourceTree = ""; }; 45 | E7E8E5FE1FF3D46C0065E6E6 /* bonus2-scratch.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "bonus2-scratch.png"; sourceTree = ""; }; 46 | E7E8E5FF1FF3D46C0065E6E6 /* bonus2.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = bonus2.png; sourceTree = ""; }; 47 | /* End PBXFileReference section */ 48 | 49 | /* Begin PBXFrameworksBuildPhase section */ 50 | E79058521FF25129000138BF /* Frameworks */ = { 51 | isa = PBXFrameworksBuildPhase; 52 | buildActionMask = 2147483647; 53 | files = ( 54 | ); 55 | runOnlyForDeploymentPostprocessing = 0; 56 | }; 57 | /* End PBXFrameworksBuildPhase section */ 58 | 59 | /* Begin PBXGroup section */ 60 | E790584C1FF25129000138BF = { 61 | isa = PBXGroup; 62 | children = ( 63 | E714024E1FF5FAD2003B1727 /* README.md */, 64 | E79058571FF25129000138BF /* MCScratchImageView */, 65 | E79058561FF25129000138BF /* Products */, 66 | ); 67 | sourceTree = ""; 68 | }; 69 | E79058561FF25129000138BF /* Products */ = { 70 | isa = PBXGroup; 71 | children = ( 72 | E79058551FF25129000138BF /* MCScratchImageView.app */, 73 | ); 74 | name = Products; 75 | sourceTree = ""; 76 | }; 77 | E79058571FF25129000138BF /* MCScratchImageView */ = { 78 | isa = PBXGroup; 79 | children = ( 80 | E790586D1FF2B411000138BF /* Resources */, 81 | E790586A1FF25147000138BF /* MCScratchImageView */, 82 | E79058581FF25129000138BF /* AppDelegate.swift */, 83 | E7533F201FF3E58700FB3785 /* MainTabBarController.swift */, 84 | E758DA821FF3D7F7003239FC /* ScratchViewController.swift */, 85 | E7533F261FF40EAC00FB3785 /* CustomScratchViewController.swift */, 86 | E7533F281FF4C78900FB3785 /* PopScratchViewController.swift */, 87 | E7533F2A1FF4C8B300FB3785 /* Main.storyboard */, 88 | E790585F1FF25129000138BF /* Assets.xcassets */, 89 | E79058611FF25129000138BF /* LaunchScreen.storyboard */, 90 | E79058641FF25129000138BF /* Info.plist */, 91 | ); 92 | path = MCScratchImageView; 93 | sourceTree = ""; 94 | }; 95 | E790586A1FF25147000138BF /* MCScratchImageView */ = { 96 | isa = PBXGroup; 97 | children = ( 98 | E790586B1FF25173000138BF /* MCScratchImageView.swift */, 99 | ); 100 | path = MCScratchImageView; 101 | sourceTree = ""; 102 | }; 103 | E790586D1FF2B411000138BF /* Resources */ = { 104 | isa = PBXGroup; 105 | children = ( 106 | E7E8E5FD1FF3D46C0065E6E6 /* bonus1-scratch.png */, 107 | E7E8E5FC1FF3D46C0065E6E6 /* bonus1.png */, 108 | E7E8E5FE1FF3D46C0065E6E6 /* bonus2-scratch.png */, 109 | E7E8E5FF1FF3D46C0065E6E6 /* bonus2.png */, 110 | ); 111 | path = Resources; 112 | sourceTree = ""; 113 | }; 114 | /* End PBXGroup section */ 115 | 116 | /* Begin PBXNativeTarget section */ 117 | E79058541FF25129000138BF /* MCScratchImageView */ = { 118 | isa = PBXNativeTarget; 119 | buildConfigurationList = E79058671FF25129000138BF /* Build configuration list for PBXNativeTarget "MCScratchImageView" */; 120 | buildPhases = ( 121 | E79058511FF25129000138BF /* Sources */, 122 | E79058521FF25129000138BF /* Frameworks */, 123 | E79058531FF25129000138BF /* Resources */, 124 | ); 125 | buildRules = ( 126 | ); 127 | dependencies = ( 128 | ); 129 | name = MCScratchImageView; 130 | productName = MCScratchImageView; 131 | productReference = E79058551FF25129000138BF /* MCScratchImageView.app */; 132 | productType = "com.apple.product-type.application"; 133 | }; 134 | /* End PBXNativeTarget section */ 135 | 136 | /* Begin PBXProject section */ 137 | E790584D1FF25129000138BF /* Project object */ = { 138 | isa = PBXProject; 139 | attributes = { 140 | LastSwiftUpdateCheck = 0920; 141 | LastUpgradeCheck = 0920; 142 | ORGANIZATIONNAME = Minecode; 143 | TargetAttributes = { 144 | E79058541FF25129000138BF = { 145 | CreatedOnToolsVersion = 9.2; 146 | ProvisioningStyle = Automatic; 147 | }; 148 | }; 149 | }; 150 | buildConfigurationList = E79058501FF25129000138BF /* Build configuration list for PBXProject "MCScratchImageView" */; 151 | compatibilityVersion = "Xcode 8.0"; 152 | developmentRegion = en; 153 | hasScannedForEncodings = 0; 154 | knownRegions = ( 155 | en, 156 | Base, 157 | ); 158 | mainGroup = E790584C1FF25129000138BF; 159 | productRefGroup = E79058561FF25129000138BF /* Products */; 160 | projectDirPath = ""; 161 | projectRoot = ""; 162 | targets = ( 163 | E79058541FF25129000138BF /* MCScratchImageView */, 164 | ); 165 | }; 166 | /* End PBXProject section */ 167 | 168 | /* Begin PBXResourcesBuildPhase section */ 169 | E79058531FF25129000138BF /* Resources */ = { 170 | isa = PBXResourcesBuildPhase; 171 | buildActionMask = 2147483647; 172 | files = ( 173 | E7533F2B1FF4C8B300FB3785 /* Main.storyboard in Resources */, 174 | E7E8E6001FF3D46C0065E6E6 /* bonus1.png in Resources */, 175 | E79058631FF25129000138BF /* LaunchScreen.storyboard in Resources */, 176 | E7E8E6031FF3D46C0065E6E6 /* bonus2.png in Resources */, 177 | E7E8E6021FF3D46C0065E6E6 /* bonus2-scratch.png in Resources */, 178 | E7E8E6011FF3D46C0065E6E6 /* bonus1-scratch.png in Resources */, 179 | E714024F1FF5FAD2003B1727 /* README.md in Resources */, 180 | E79058601FF25129000138BF /* Assets.xcassets in Resources */, 181 | ); 182 | runOnlyForDeploymentPostprocessing = 0; 183 | }; 184 | /* End PBXResourcesBuildPhase section */ 185 | 186 | /* Begin PBXSourcesBuildPhase section */ 187 | E79058511FF25129000138BF /* Sources */ = { 188 | isa = PBXSourcesBuildPhase; 189 | buildActionMask = 2147483647; 190 | files = ( 191 | E7E8E6041FF3D4750065E6E6 /* bonus1-scratch.png in Sources */, 192 | E7E8E6051FF3D4750065E6E6 /* bonus1.png in Sources */, 193 | E7533F211FF3E58700FB3785 /* MainTabBarController.swift in Sources */, 194 | E7533F291FF4C78900FB3785 /* PopScratchViewController.swift in Sources */, 195 | E7533F271FF40EAC00FB3785 /* CustomScratchViewController.swift in Sources */, 196 | E7E8E6061FF3D4750065E6E6 /* bonus2-scratch.png in Sources */, 197 | E7E8E6071FF3D4750065E6E6 /* bonus2.png in Sources */, 198 | E758DA831FF3D7F7003239FC /* ScratchViewController.swift in Sources */, 199 | E790586C1FF25173000138BF /* MCScratchImageView.swift in Sources */, 200 | E79058591FF25129000138BF /* AppDelegate.swift in Sources */, 201 | ); 202 | runOnlyForDeploymentPostprocessing = 0; 203 | }; 204 | /* End PBXSourcesBuildPhase section */ 205 | 206 | /* Begin PBXVariantGroup section */ 207 | E79058611FF25129000138BF /* LaunchScreen.storyboard */ = { 208 | isa = PBXVariantGroup; 209 | children = ( 210 | E79058621FF25129000138BF /* Base */, 211 | ); 212 | name = LaunchScreen.storyboard; 213 | sourceTree = ""; 214 | }; 215 | /* End PBXVariantGroup section */ 216 | 217 | /* Begin XCBuildConfiguration section */ 218 | E79058651FF25129000138BF /* Debug */ = { 219 | isa = XCBuildConfiguration; 220 | buildSettings = { 221 | ALWAYS_SEARCH_USER_PATHS = NO; 222 | CLANG_ANALYZER_NONNULL = YES; 223 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 224 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 225 | CLANG_CXX_LIBRARY = "libc++"; 226 | CLANG_ENABLE_MODULES = YES; 227 | CLANG_ENABLE_OBJC_ARC = YES; 228 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 229 | CLANG_WARN_BOOL_CONVERSION = YES; 230 | CLANG_WARN_COMMA = YES; 231 | CLANG_WARN_CONSTANT_CONVERSION = 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_LITERAL_CONVERSION = YES; 240 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 241 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 242 | CLANG_WARN_STRICT_PROTOTYPES = YES; 243 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 244 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 245 | CLANG_WARN_UNREACHABLE_CODE = YES; 246 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 247 | CODE_SIGN_IDENTITY = "iPhone Developer"; 248 | COPY_PHASE_STRIP = NO; 249 | DEBUG_INFORMATION_FORMAT = dwarf; 250 | ENABLE_STRICT_OBJC_MSGSEND = YES; 251 | ENABLE_TESTABILITY = YES; 252 | GCC_C_LANGUAGE_STANDARD = gnu11; 253 | GCC_DYNAMIC_NO_PIC = NO; 254 | GCC_NO_COMMON_BLOCKS = YES; 255 | GCC_OPTIMIZATION_LEVEL = 0; 256 | GCC_PREPROCESSOR_DEFINITIONS = ( 257 | "DEBUG=1", 258 | "$(inherited)", 259 | ); 260 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 261 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 262 | GCC_WARN_UNDECLARED_SELECTOR = YES; 263 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 264 | GCC_WARN_UNUSED_FUNCTION = YES; 265 | GCC_WARN_UNUSED_VARIABLE = YES; 266 | IPHONEOS_DEPLOYMENT_TARGET = 11.2; 267 | MTL_ENABLE_DEBUG_INFO = YES; 268 | ONLY_ACTIVE_ARCH = YES; 269 | SDKROOT = iphoneos; 270 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 271 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 272 | }; 273 | name = Debug; 274 | }; 275 | E79058661FF25129000138BF /* Release */ = { 276 | isa = XCBuildConfiguration; 277 | buildSettings = { 278 | ALWAYS_SEARCH_USER_PATHS = NO; 279 | CLANG_ANALYZER_NONNULL = YES; 280 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 281 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 282 | CLANG_CXX_LIBRARY = "libc++"; 283 | CLANG_ENABLE_MODULES = YES; 284 | CLANG_ENABLE_OBJC_ARC = YES; 285 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 286 | CLANG_WARN_BOOL_CONVERSION = YES; 287 | CLANG_WARN_COMMA = YES; 288 | CLANG_WARN_CONSTANT_CONVERSION = YES; 289 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 290 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 291 | CLANG_WARN_EMPTY_BODY = YES; 292 | CLANG_WARN_ENUM_CONVERSION = YES; 293 | CLANG_WARN_INFINITE_RECURSION = YES; 294 | CLANG_WARN_INT_CONVERSION = YES; 295 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 296 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 297 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 298 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 299 | CLANG_WARN_STRICT_PROTOTYPES = YES; 300 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 301 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 302 | CLANG_WARN_UNREACHABLE_CODE = YES; 303 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 304 | CODE_SIGN_IDENTITY = "iPhone Developer"; 305 | COPY_PHASE_STRIP = NO; 306 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 307 | ENABLE_NS_ASSERTIONS = NO; 308 | ENABLE_STRICT_OBJC_MSGSEND = YES; 309 | GCC_C_LANGUAGE_STANDARD = gnu11; 310 | GCC_NO_COMMON_BLOCKS = YES; 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 = 11.2; 318 | MTL_ENABLE_DEBUG_INFO = NO; 319 | SDKROOT = iphoneos; 320 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 321 | VALIDATE_PRODUCT = YES; 322 | }; 323 | name = Release; 324 | }; 325 | E79058681FF25129000138BF /* Debug */ = { 326 | isa = XCBuildConfiguration; 327 | buildSettings = { 328 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 329 | CODE_SIGN_STYLE = Automatic; 330 | DEVELOPMENT_TEAM = XQ4VPYFFH5; 331 | INFOPLIST_FILE = MCScratchImageView/Info.plist; 332 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 333 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 334 | PRODUCT_BUNDLE_IDENTIFIER = link.minecode.MCScratchImageView; 335 | PRODUCT_NAME = "$(TARGET_NAME)"; 336 | SWIFT_VERSION = 4.0; 337 | TARGETED_DEVICE_FAMILY = 1; 338 | }; 339 | name = Debug; 340 | }; 341 | E79058691FF25129000138BF /* Release */ = { 342 | isa = XCBuildConfiguration; 343 | buildSettings = { 344 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 345 | CODE_SIGN_STYLE = Automatic; 346 | DEVELOPMENT_TEAM = XQ4VPYFFH5; 347 | INFOPLIST_FILE = MCScratchImageView/Info.plist; 348 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 349 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 350 | PRODUCT_BUNDLE_IDENTIFIER = link.minecode.MCScratchImageView; 351 | PRODUCT_NAME = "$(TARGET_NAME)"; 352 | SWIFT_VERSION = 4.0; 353 | TARGETED_DEVICE_FAMILY = 1; 354 | }; 355 | name = Release; 356 | }; 357 | /* End XCBuildConfiguration section */ 358 | 359 | /* Begin XCConfigurationList section */ 360 | E79058501FF25129000138BF /* Build configuration list for PBXProject "MCScratchImageView" */ = { 361 | isa = XCConfigurationList; 362 | buildConfigurations = ( 363 | E79058651FF25129000138BF /* Debug */, 364 | E79058661FF25129000138BF /* Release */, 365 | ); 366 | defaultConfigurationIsVisible = 0; 367 | defaultConfigurationName = Release; 368 | }; 369 | E79058671FF25129000138BF /* Build configuration list for PBXNativeTarget "MCScratchImageView" */ = { 370 | isa = XCConfigurationList; 371 | buildConfigurations = ( 372 | E79058681FF25129000138BF /* Debug */, 373 | E79058691FF25129000138BF /* Release */, 374 | ); 375 | defaultConfigurationIsVisible = 0; 376 | defaultConfigurationName = Release; 377 | }; 378 | /* End XCConfigurationList section */ 379 | }; 380 | rootObject = E790584D1FF25129000138BF /* Project object */; 381 | } 382 | -------------------------------------------------------------------------------- /Example/MCScratchImageView.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/MCScratchImageView/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/.DS_Store -------------------------------------------------------------------------------- /Example/MCScratchImageView/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // MCScratchImageView 4 | // 5 | // Created by Minecode on 2017/12/26. 6 | // Copyright © 2017年 Minecode. 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 | 20 | return true 21 | } 22 | 23 | func applicationWillResignActive(_ application: UIApplication) { 24 | // 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. 25 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 26 | } 27 | 28 | func applicationDidEnterBackground(_ application: UIApplication) { 29 | // 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. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | func applicationWillEnterForeground(_ application: UIApplication) { 34 | // 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. 35 | } 36 | 37 | func applicationDidBecomeActive(_ application: UIApplication) { 38 | // 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. 39 | } 40 | 41 | func applicationWillTerminate(_ application: UIApplication) { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | 46 | } 47 | 48 | -------------------------------------------------------------------------------- /Example/MCScratchImageView/Assets.xcassets/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Assets.xcassets/.DS_Store -------------------------------------------------------------------------------- /Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images": [ 3 | { 4 | "size": "20x20", 5 | "idiom": "iphone", 6 | "filename": "icon-20@2x.png", 7 | "scale": "2x" 8 | }, 9 | { 10 | "size": "20x20", 11 | "idiom": "iphone", 12 | "filename": "icon-20@3x.png", 13 | "scale": "3x" 14 | }, 15 | { 16 | "size": "29x29", 17 | "idiom": "iphone", 18 | "filename": "icon-29.png", 19 | "scale": "1x" 20 | }, 21 | { 22 | "size": "29x29", 23 | "idiom": "iphone", 24 | "filename": "icon-29@2x.png", 25 | "scale": "2x" 26 | }, 27 | { 28 | "size": "29x29", 29 | "idiom": "iphone", 30 | "filename": "icon-29@3x.png", 31 | "scale": "3x" 32 | }, 33 | { 34 | "size": "40x40", 35 | "idiom": "iphone", 36 | "filename": "icon-40@2x.png", 37 | "scale": "2x" 38 | }, 39 | { 40 | "size": "40x40", 41 | "idiom": "iphone", 42 | "filename": "icon-40@3x.png", 43 | "scale": "3x" 44 | }, 45 | { 46 | "size": "57x57", 47 | "idiom": "iphone", 48 | "filename": "icon-57.png", 49 | "scale": "1x" 50 | }, 51 | { 52 | "size": "57x57", 53 | "idiom": "iphone", 54 | "filename": "icon-57@2x.png", 55 | "scale": "2x" 56 | }, 57 | { 58 | "size": "60x60", 59 | "idiom": "iphone", 60 | "filename": "icon-60@2x.png", 61 | "scale": "2x" 62 | }, 63 | { 64 | "size": "60x60", 65 | "idiom": "iphone", 66 | "filename": "icon-60@3x.png", 67 | "scale": "3x" 68 | }, 69 | { 70 | "size": "20x20", 71 | "idiom": "ipad", 72 | "filename": "icon-20-ipad.png", 73 | "scale": "1x" 74 | }, 75 | { 76 | "size": "20x20", 77 | "idiom": "ipad", 78 | "filename": "icon-20@2x-ipad.png", 79 | "scale": "2x" 80 | }, 81 | { 82 | "size": "29x29", 83 | "idiom": "ipad", 84 | "filename": "icon-29-ipad.png", 85 | "scale": "1x" 86 | }, 87 | { 88 | "size": "29x29", 89 | "idiom": "ipad", 90 | "filename": "icon-29@2x-ipad.png", 91 | "scale": "2x" 92 | }, 93 | { 94 | "size": "40x40", 95 | "idiom": "ipad", 96 | "filename": "icon-40.png", 97 | "scale": "1x" 98 | }, 99 | { 100 | "size": "40x40", 101 | "idiom": "ipad", 102 | "filename": "icon-40@2x.png", 103 | "scale": "2x" 104 | }, 105 | { 106 | "size": "50x50", 107 | "idiom": "ipad", 108 | "filename": "icon-50.png", 109 | "scale": "1x" 110 | }, 111 | { 112 | "size": "50x50", 113 | "idiom": "ipad", 114 | "filename": "icon-50@2x.png", 115 | "scale": "2x" 116 | }, 117 | { 118 | "size": "72x72", 119 | "idiom": "ipad", 120 | "filename": "icon-72.png", 121 | "scale": "1x" 122 | }, 123 | { 124 | "size": "72x72", 125 | "idiom": "ipad", 126 | "filename": "icon-72@2x.png", 127 | "scale": "2x" 128 | }, 129 | { 130 | "size": "76x76", 131 | "idiom": "ipad", 132 | "filename": "icon-76.png", 133 | "scale": "1x" 134 | }, 135 | { 136 | "size": "76x76", 137 | "idiom": "ipad", 138 | "filename": "icon-76@2x.png", 139 | "scale": "2x" 140 | }, 141 | { 142 | "size": "83.5x83.5", 143 | "idiom": "ipad", 144 | "filename": "icon-83.5@2x.png", 145 | "scale": "2x" 146 | }, 147 | { 148 | "size": "1024x1024", 149 | "idiom": "ios-marketing", 150 | "filename": "icon-1024.png", 151 | "scale": "1x" 152 | } 153 | ], 154 | "info": { 155 | "version": 1, 156 | "author": "icon.wuruihong.com" 157 | } 158 | } -------------------------------------------------------------------------------- /Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-1024.png -------------------------------------------------------------------------------- /Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-20-ipad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-20-ipad.png -------------------------------------------------------------------------------- /Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-20@2x-ipad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-20@2x-ipad.png -------------------------------------------------------------------------------- /Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-20@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-20@2x.png -------------------------------------------------------------------------------- /Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-20@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-20@3x.png -------------------------------------------------------------------------------- /Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-29-ipad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-29-ipad.png -------------------------------------------------------------------------------- /Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-29.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-29.png -------------------------------------------------------------------------------- /Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-29@2x-ipad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-29@2x-ipad.png -------------------------------------------------------------------------------- /Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-29@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-29@2x.png -------------------------------------------------------------------------------- /Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-29@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-29@3x.png -------------------------------------------------------------------------------- /Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-40.png -------------------------------------------------------------------------------- /Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-40@2x.png -------------------------------------------------------------------------------- /Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-40@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-40@3x.png -------------------------------------------------------------------------------- /Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-50.png -------------------------------------------------------------------------------- /Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-50@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-50@2x.png -------------------------------------------------------------------------------- /Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-57.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-57.png -------------------------------------------------------------------------------- /Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-57@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-57@2x.png -------------------------------------------------------------------------------- /Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-60@2x.png -------------------------------------------------------------------------------- /Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-60@3x.png -------------------------------------------------------------------------------- /Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-72.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-72.png -------------------------------------------------------------------------------- /Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-72@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-72@2x.png -------------------------------------------------------------------------------- /Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-76.png -------------------------------------------------------------------------------- /Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-76@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-76@2x.png -------------------------------------------------------------------------------- /Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-83.5@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Assets.xcassets/AppIcon.appiconset/icon-83.5@2x.png -------------------------------------------------------------------------------- /Example/MCScratchImageView/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Example/MCScratchImageView/Assets.xcassets/barItem.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "barItem.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Example/MCScratchImageView/Assets.xcassets/barItem.imageset/barItem.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Assets.xcassets/barItem.imageset/barItem.png -------------------------------------------------------------------------------- /Example/MCScratchImageView/Assets.xcassets/barItem_selected.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "barItem_selected.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Example/MCScratchImageView/Assets.xcassets/barItem_selected.imageset/barItem_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Assets.xcassets/barItem_selected.imageset/barItem_selected.png -------------------------------------------------------------------------------- /Example/MCScratchImageView/Assets.xcassets/iTunesArtwork.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Assets.xcassets/iTunesArtwork.png -------------------------------------------------------------------------------- /Example/MCScratchImageView/Assets.xcassets/iTunesArtwork@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Assets.xcassets/iTunesArtwork@2x.png -------------------------------------------------------------------------------- /Example/MCScratchImageView/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 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Example/MCScratchImageView/CustomScratchViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CustomScratchViewController.swift 3 | // MCScratchImageView 4 | // 5 | // Created by Minecode on 2017/12/28. 6 | // Copyright © 2017年 Minecode. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class CustomScratchViewController: UIViewController { 12 | 13 | @IBOutlet weak var imageView: UIImageView! 14 | @IBOutlet weak var scratchImageView: MCScratchImageView! 15 | 16 | override func viewDidLoad() { 17 | super.viewDidLoad() 18 | 19 | self.view.backgroundColor = UIColor.white 20 | 21 | setupView() 22 | } 23 | 24 | func setupView() { 25 | imageView.image = UIImage(named: "bonus2.png") 26 | 27 | scratchImageView!.setMaskImage(UIImage(named: "bonus2-scratch.png")!, spotRadius: 100) 28 | scratchImageView!.delegate = self 29 | } 30 | 31 | @IBAction func scratchedHandler(_ sender: UIButton) { 32 | scratchImageView.scratchAll() 33 | print("Scratched") 34 | sender.isEnabled = false 35 | } 36 | 37 | } 38 | 39 | extension CustomScratchViewController: MCScratchImageViewDelegate { 40 | 41 | func mcScratchImageView(_ mcScratchImageView: MCScratchImageView, didChangeProgress progress: CGFloat) { 42 | print("Progress did changed: " + String(format: "%.2f", progress)) 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Example/MCScratchImageView/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | 35 | UISupportedInterfaceOrientations~ipad 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationPortraitUpsideDown 39 | UIInterfaceOrientationLandscapeLeft 40 | UIInterfaceOrientationLandscapeRight 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Example/MCScratchImageView/MCScratchImageView/MCScratchImageView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MCScratchImageView.swift 3 | // MCScratchImageView 4 | // 5 | // Created by Minecode on 2017/12/26. 6 | // Copyright © 2017年 Minecode. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | public protocol MCScratchImageViewDelegate { 12 | 13 | func mcScratchImageView(_ mcScratchImageView: MCScratchImageView, didChangeProgress progress: CGFloat) 14 | 15 | } 16 | 17 | public class MCScratchImageView: UIImageView { 18 | 19 | // MARK: Public stored properties 20 | public var delegate: MCScratchImageViewDelegate? 21 | // Determin the radius of the spot 22 | private(set) var spotRadius: CGFloat = 45.0 23 | 24 | // MARK: Public calculate properties 25 | // current scratched progress, 0.0(masked)~1.00(sharped) 26 | public var progress: CGFloat { 27 | get { 28 | return CGFloat(maskedMatrix.scratchedCount) / CGFloat(maskedMatrix.count) 29 | } 30 | } 31 | 32 | // MARK: Private properties 33 | // the martix to determine the grids of maskImage 34 | private var maskedMatrix: MCMatrix! 35 | private var imageContext: CGContext! 36 | private var colorSpace: CGColorSpace! 37 | private var touchedPoints: [CGPoint]! 38 | private let kSpotRadiusDefault: CGFloat = 45.0 39 | private let kBezierStepFactor: CGFloat = 0.2 40 | 41 | // MARK: Private caculate properties 42 | // the size of mask 43 | private var maskSize: MCSize { 44 | get { 45 | return self.maskedMatrix.size 46 | } 47 | } 48 | 49 | // MARK: - Init Function 50 | public override init(frame: CGRect) { 51 | super.init(frame: frame) 52 | 53 | commonInit() 54 | } 55 | 56 | public override init(image: UIImage?) { 57 | super.init(image: image) 58 | 59 | commonInit() 60 | } 61 | 62 | required public init?(coder aDecoder: NSCoder) { 63 | super.init(coder: aDecoder) 64 | 65 | commonInit() 66 | } 67 | 68 | private func commonInit() { 69 | isUserInteractionEnabled = false 70 | 71 | if (self.image != nil) { 72 | self.reset() 73 | } 74 | touchedPoints = [CGPoint]() 75 | } 76 | 77 | // Reminding: This function is to reset the environments, not reset the blured image 78 | // so do not call it outside 79 | private func reset() { 80 | 81 | guard let image = self.image else { 82 | isUserInteractionEnabled = false 83 | return 84 | } 85 | 86 | isUserInteractionEnabled = true 87 | touchedPoints.removeAll() 88 | // initalize the image context 89 | let imageWidth = image.size.width * image.scale 90 | let imageHeight = image.size.height * image.scale 91 | colorSpace = CGColorSpaceCreateDeviceRGB() 92 | imageContext = CGContext(data: nil, width: Int(imageWidth), height: Int(imageHeight), bitsPerComponent: 8, bytesPerRow: Int(imageWidth*4), space: colorSpace, bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue) 93 | // draw the hole blured image 94 | imageContext.draw(image.cgImage!, in: CGRect(x: 0, y: 0, width: imageWidth, height: imageHeight)) 95 | imageContext.setBlendMode(CGBlendMode.clear) 96 | 97 | // initialize the mask matrix 98 | self.maskedMatrix = MCMatrix(x: Int(imageWidth/(2*spotRadius)), y: Int(imageHeight/(2*spotRadius))) 99 | } 100 | 101 | public func setMaskImage(_ image: UIImage, spotRadius: CGFloat) { 102 | self.image = image 103 | self.spotRadius = spotRadius 104 | self.reset() 105 | } 106 | 107 | public func setMaskImage(_ image: UIImage) { 108 | self.setMaskImage(image, spotRadius: kSpotRadiusDefault) 109 | self.reset() 110 | } 111 | 112 | public func scratchAll() { 113 | // store current process 114 | let currentProgress = self.progress 115 | 116 | // reset masked matrix 117 | self.maskedMatrix.reset(status: true, scratched: maskedMatrix.count) 118 | 119 | let imageWidth = image!.size.width * image!.scale 120 | let imageHeight = image!.size.height * image!.scale 121 | imageContext = CGContext(data: nil, width: Int(imageWidth), height: Int(imageHeight), bitsPerComponent: 8, bytesPerRow: Int(imageWidth*4), space: colorSpace, bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue) 122 | self.image = UIImage(cgImage: imageContext.makeImage()!) 123 | 124 | if (currentProgress != self.progress) { 125 | self.delegate?.mcScratchImageView(self, didChangeProgress: self.progress) 126 | } 127 | } 128 | 129 | // MARK: - Core Graphic draw funtion 130 | private func addTouches(_ touches: Set) -> UIImage { 131 | let imageSize = CGSize(width: self.image!.size.width*self.image!.scale, height: self.image!.size.height*self.image!.scale) 132 | let currentProgress = self.progress 133 | 134 | // set image context 135 | let ctx = imageContext! 136 | ctx.setStrokeColor(UIColor.clear.cgColor) 137 | ctx.setFillColor(UIColor.clear.cgColor) 138 | ctx.setLineWidth(2*spotRadius) 139 | ctx.setLineCap(CGLineCap.round) 140 | 141 | for touch in touches { 142 | ctx.beginPath() 143 | let touchPoint = covertCoordinateToQuartz(touch.location(in: self), imageSize: imageSize) 144 | 145 | // deal with first touch 146 | if (touch.phase == .began) { 147 | touchedPoints.removeAll() 148 | touchedPoints.append(touchPoint) 149 | touchedPoints.append(touchPoint) 150 | 151 | // if current is touch begin, just add an ellipse 152 | let ellipseRect = CGRect(x: touchPoint.x-spotRadius, y: touchPoint.y-spotRadius, width: spotRadius*2, height: spotRadius*2) 153 | ctx.addEllipse(in: ellipseRect) 154 | ctx.fillPath() 155 | 156 | updateGrid(withPointX: ellipseRect.origin.x, pointY: ellipseRect.origin.y) 157 | } 158 | else if (touch.phase == .moved) { 159 | touchedPoints.append(touchPoint) 160 | 161 | // use touchpoints to draw a bezier path 162 | // using CGContextAddCurveToPoint with 4 point 163 | while (self.touchedPoints.count >= 4) { 164 | var points: [CGPoint] = [CGPoint](repeating: CGPoint(), count: 4) 165 | points[0] = touchedPoints[1] 166 | points[1] = touchedPoints[0] 167 | points[2] = touchedPoints[3] 168 | points[3] = touchedPoints[2] 169 | 170 | let centerMargin: CGFloat = sqrt(pow(points[3].x-points[0].x, 2) + pow(points[3].y-points[0].y, 2)) 171 | var xPointCursor: CGFloat = 0.0 172 | var yPointCursor: CGFloat = 0.0 173 | 174 | // scale the to other point 175 | xPointCursor = (points[0].x - points[1].x) - (points[0].x - points[3].x) 176 | yPointCursor = (points[0].y - points[1].y) - (points[0].y - points[3].y) 177 | points[1] = formPointToScale(x: xPointCursor, y: yPointCursor) 178 | points[1] = formPoint(points[1], margin: centerMargin, factor: kBezierStepFactor) 179 | points[1].x += points[0].x 180 | points[1].y += points[0].y 181 | 182 | xPointCursor = (points[3].x - points[2].x) - (points[3].x - points[0].x) 183 | yPointCursor = (points[3].y - points[2].y) - (points[3].y - points[0].y) 184 | points[2] = formPointToScale(x: xPointCursor, y: yPointCursor) 185 | points[2] = formPoint(points[2], margin: centerMargin, factor: kBezierStepFactor) 186 | points[2].x += points[3].x 187 | points[2].y += points[3].y 188 | 189 | ctx.move(to: points[0]) 190 | ctx.addCurve(to: points[1], control1: points[2], control2: points[3]) 191 | 192 | touchedPoints.remove(at: 0) 193 | } 194 | 195 | ctx.strokePath() 196 | let preTouchPoint = covertCoordinateToQuartz(touch.previousLocation(in: self), imageSize: imageSize) 197 | updateGrid(withBeginPoint: touchPoint, endPoint: preTouchPoint) 198 | } 199 | 200 | } 201 | 202 | if (currentProgress != self.progress) { 203 | self.delegate?.mcScratchImageView(self, didChangeProgress: self.progress) 204 | } 205 | 206 | let cgImage = ctx.makeImage() 207 | let resImage = UIImage(cgImage: cgImage!) 208 | return resImage 209 | } 210 | 211 | private func formPointToScale(x: CGFloat, y: CGFloat) -> CGPoint { 212 | let len = sqrt(x*x + y*y) 213 | if (len == 0) { 214 | return CGPoint.zero 215 | } 216 | return CGPoint(x: x/len, y: y/len) 217 | } 218 | 219 | private func formPoint(_ point: CGPoint, margin: CGFloat, factor: CGFloat) -> CGPoint { 220 | var res = point 221 | res.x *= margin 222 | res.y *= margin 223 | res.x *= factor 224 | res.y *= factor 225 | return res 226 | } 227 | 228 | // convert UI coordinate to Quartz coordinate 229 | private func covertCoordinateToQuartz(_ point: CGPoint, imageSize: CGSize) -> CGPoint { 230 | return CGPoint(x: imageSize.width * point.x / self.bounds.size.width, y: imageSize.height * (self.bounds.height-point.y) / self.bounds.size.height) 231 | } 232 | 233 | // MARK: - touch event handler 234 | override public func touchesBegan(_ touches: Set, with event: UIEvent?) { 235 | 236 | if (self.image == nil) {return} 237 | self.image = self.addTouches(touches) 238 | 239 | } 240 | 241 | override public func touchesMoved(_ touches: Set, with event: UIEvent?) { 242 | 243 | if (self.image == nil) {return} 244 | self.image = self.addTouches(touches) 245 | 246 | } 247 | 248 | // MARK: - Grid filled function 249 | // Reminder: This function is to update the data of matrix 250 | // The draw function has written above 251 | private func updateGrid(withPointX x: CGFloat, pointY y: CGFloat) { 252 | 253 | let imageWidth = image!.size.width * image!.scale 254 | let imageHeight = image!.size.height * image!.scale 255 | let xCursor = min(imageWidth-1, max(0, x)) 256 | let yCursor = min(imageHeight-1, max(0, y)) 257 | let xIdx = Int( xCursor * CGFloat(maskedMatrix.size.x) / imageWidth) 258 | let yIdx = Int( yCursor * CGFloat(maskedMatrix.size.y) / imageHeight) 259 | 260 | if (maskedMatrix.statusForGrid(x: xIdx, y: yIdx) == false) { 261 | maskedMatrix.setGrid(x: xIdx, y: yIdx, forStatus: true) 262 | } 263 | 264 | } 265 | 266 | private func updateGrid(withBeginPoint begin: CGPoint, endPoint end: CGPoint) { 267 | 268 | let imageWidth = image!.size.width * image!.scale 269 | let imageHeight = image!.size.height * image!.scale 270 | 271 | var idx = begin 272 | let kIncreaseStepX = (begin.x < end.x ? 1 : -1) * imageWidth / CGFloat(maskSize.x); 273 | let kIncreaseStepY = (begin.y < end.y ? 1 : -1) * imageHeight / CGFloat(maskSize.y); 274 | 275 | while (idx.x>=min(begin.x, end.x) && idx.x<=max(begin.x, end.x) && idx.y>=min(begin.y, end.y) && idx.y<=max(begin.y, end.y)) { 276 | updateGrid(withPointX: idx.x, pointY: idx.y) 277 | 278 | idx.x += kIncreaseStepX 279 | idx.y += kIncreaseStepY 280 | } 281 | updateGrid(withPointX: idx.x, pointY: idx.y) 282 | 283 | } 284 | } 285 | 286 | 287 | // MARK: - The matrix struct that determine the mask grids 288 | fileprivate struct MCMatrix { 289 | 290 | // stored properties 291 | private(set) var size: MCSize 292 | private(set) var gridScratched: [Bool]! 293 | 294 | // calculate properties 295 | var count: Int { 296 | get { 297 | return size.x*size.y 298 | } 299 | } 300 | private(set) var scratchedCount: Int 301 | 302 | init(_ size: MCSize) { 303 | self.size = size 304 | scratchedCount = 0 305 | gridScratched = [Bool](repeating: false, count: self.count) 306 | } 307 | 308 | init(x: Int, y: Int) { 309 | self.init(MCSize(x: x, y: y)) 310 | } 311 | 312 | public func statusForGrid(x: Int, y: Int) -> Bool { 313 | if (x*y >= count) {return true} 314 | return gridScratched[x + size.x*y] 315 | } 316 | 317 | public mutating func setGrid(x: Int, y: Int, forStatus status: Bool) { 318 | if (x*y >= count) {return} 319 | if (gridScratched[x + size.x*y] != status) { 320 | scratchedCount += status ? 1 : -1 321 | gridScratched[x + size.x*y] = status 322 | } 323 | } 324 | 325 | public mutating func reset( status: Bool = false, scratched: Int = 0) { 326 | gridScratched = [Bool](repeating: status, count: self.count) 327 | scratchedCount = scratched 328 | } 329 | 330 | } 331 | 332 | // MARK: - The Size struct 333 | fileprivate struct MCSize { 334 | 335 | public var x: Int 336 | public var y: Int 337 | 338 | init(x: Int, y: Int) { 339 | self.x = x 340 | self.y = y 341 | } 342 | 343 | } 344 | fileprivate typealias MCPoint = MCSize 345 | -------------------------------------------------------------------------------- /Example/MCScratchImageView/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 63 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 133 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 188 | 189 | 190 | 191 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | -------------------------------------------------------------------------------- /Example/MCScratchImageView/MainTabBarController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MainTabBarController.swift 3 | // MCScratchImageView 4 | // 5 | // Created by Minecode on 2017/12/27. 6 | // Copyright © 2017年 Minecode. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class MainTabBarController: UITabBarController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | 16 | setupChildView() 17 | } 18 | 19 | func setupChildView() { 20 | let storyBoard = UIStoryboard(name: "Main", bundle: nil) 21 | 22 | let vc1 = storyBoard.instantiateViewController(withIdentifier: "ScratchVC") 23 | vc1.tabBarItem.title = "Default" 24 | vc1.tabBarItem.image = UIImage(named: "barItem") 25 | vc1.tabBarItem.selectedImage = UIImage(named: "barItem_selected") 26 | self.addChildViewController(vc1) 27 | 28 | let vc2 = storyBoard.instantiateViewController(withIdentifier: "CustomScratchVC") 29 | vc2.tabBarItem.title = "Custom" 30 | vc2.tabBarItem.image = UIImage(named: "barItem") 31 | vc2.tabBarItem.selectedImage = UIImage(named: "barItem_selected") 32 | self.addChildViewController(vc2) 33 | 34 | let vc3 = storyBoard.instantiateViewController(withIdentifier: "PopScratchVC") 35 | vc3.tabBarItem.title = "ScratchVC" 36 | vc3.tabBarItem.image = UIImage(named: "barItem") 37 | vc3.tabBarItem.selectedImage = UIImage(named: "barItem_selected") 38 | self.addChildViewController(vc3) 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /Example/MCScratchImageView/PopScratchViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PopScratchViewController.swift 3 | // MCScratchImageView 4 | // 5 | // Created by Minecode on 2017/12/28. 6 | // Copyright © 2017年 Minecode. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class PopScratchViewController: UIViewController { 12 | 13 | @IBOutlet weak var popUpView: UIView! 14 | @IBOutlet weak var imageView: UIImageView! 15 | @IBOutlet weak var scratchImageView: MCScratchImageView! 16 | @IBOutlet weak var popUpViewTopCons: NSLayoutConstraint! 17 | @IBOutlet weak var popUpViewHeightCons: NSLayoutConstraint! 18 | 19 | 20 | override func viewDidLoad() { 21 | super.viewDidLoad() 22 | 23 | setupView() 24 | } 25 | 26 | func setupView() { 27 | imageView.image = UIImage(named: "bonus1.png") 28 | 29 | scratchImageView!.setMaskImage(UIImage(named: "bonus1-scratch.png")!, spotRadius: 30) 30 | scratchImageView!.delegate = self 31 | } 32 | 33 | @IBAction func popUpHandler(_ sender: UIButton) { 34 | self.popUpViewTopCons.constant = -self.popUpViewHeightCons.constant 35 | 36 | UIView.animate(withDuration: 0.5, delay: 0.0, options: .curveEaseInOut, animations: { 37 | self.view.layoutIfNeeded() 38 | }, completion: nil) 39 | 40 | sender.isEnabled = false 41 | } 42 | 43 | @IBAction func closeHandler(_ sender: UIButton) { 44 | self.popUpViewTopCons.constant = 50 45 | 46 | UIView.animate(withDuration: 0.5, delay: 0.0, options: .curveEaseInOut, animations: { 47 | self.view.layoutIfNeeded() 48 | }, completion: nil) 49 | 50 | sender.isEnabled = false 51 | } 52 | 53 | 54 | } 55 | 56 | extension PopScratchViewController: MCScratchImageViewDelegate { 57 | 58 | func mcScratchImageView(_ mcScratchImageView: MCScratchImageView, didChangeProgress progress: CGFloat) { 59 | 60 | print("Progress did changed: " + String(format: "%.2f", progress)) 61 | 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /Example/MCScratchImageView/Resources/barItem.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Resources/barItem.png -------------------------------------------------------------------------------- /Example/MCScratchImageView/Resources/barrage_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Resources/barrage_selected.png -------------------------------------------------------------------------------- /Example/MCScratchImageView/Resources/bonus1-scratch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Resources/bonus1-scratch.png -------------------------------------------------------------------------------- /Example/MCScratchImageView/Resources/bonus1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Resources/bonus1.png -------------------------------------------------------------------------------- /Example/MCScratchImageView/Resources/bonus2-scratch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Resources/bonus2-scratch.png -------------------------------------------------------------------------------- /Example/MCScratchImageView/Resources/bonus2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/Example/MCScratchImageView/Resources/bonus2.png -------------------------------------------------------------------------------- /Example/MCScratchImageView/ScratchViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ScratchViewController.swift 3 | // MCScratchImageView 4 | // 5 | // Created by Minecode on 2017/12/27. 6 | // Copyright © 2017年 Minecode. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ScratchViewController: UIViewController { 12 | 13 | @IBOutlet weak var imageView: UIImageView! 14 | @IBOutlet weak var scratchImageView: MCScratchImageView! 15 | 16 | override func viewDidLoad() { 17 | super.viewDidLoad() 18 | 19 | self.view.backgroundColor = UIColor.white 20 | 21 | setupView() 22 | } 23 | 24 | func setupView() { 25 | imageView.image = UIImage(named: "bonus2.png") 26 | 27 | scratchImageView!.setMaskImage(UIImage(named: "bonus2-scratch.png")!) 28 | scratchImageView!.delegate = self 29 | } 30 | 31 | @IBAction func scratchedHandler(_ sender: UIButton) { 32 | scratchImageView.scratchAll() 33 | print("Scratched") 34 | sender.isEnabled = false 35 | } 36 | 37 | } 38 | 39 | extension ScratchViewController: MCScratchImageViewDelegate { 40 | 41 | func mcScratchImageView(_ mcScratchImageView: MCScratchImageView, didChangeProgress progress: CGFloat) { 42 | 43 | print("Progress did changed: " + String(format: "%.2f", progress)) 44 | 45 | if (progress >= 0.8) { 46 | mcScratchImageView.scratchAll() 47 | } 48 | 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /GIFShowcase/Showcase1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/GIFShowcase/Showcase1.gif -------------------------------------------------------------------------------- /GIFShowcase/Showcase2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaylenCoding/MCScratchImageView/HEAD/GIFShowcase/Showcase2.gif -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 JunLin Bian 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 | -------------------------------------------------------------------------------- /MCScratchImageView.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # Be sure to run `pod spec lint MCScratchImageView.podspec' to ensure this is a 3 | # valid spec and to remove all comments including this before submitting the spec. 4 | # 5 | # To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html 6 | # To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/ 7 | # 8 | 9 | Pod::Spec.new do |s| 10 | 11 | # ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 12 | # 13 | # These will help people to find your library, and whilst it 14 | # can feel like a chore to fill in it's definitely to your advantage. The 15 | # summary should be tweet-length, and the description more in depth. 16 | # 17 | 18 | s.name = "MCScratchImageView" 19 | s.version = "1.0.0" 20 | s.summary = "Custom ImageView like scratch card" 21 | s.swift_version = "4.0" 22 | 23 | # This description is used to generate tags and improve search results. 24 | # * Think: What does it do? Why did you write it? What is the focus? 25 | # * Try to keep it short, snappy and to the point. 26 | # * Write the description between the DESC delimiters below. 27 | # * Finally, don't worry about the indent, CocoaPods strips it! 28 | s.description = <<-DESC 29 | A custom ImageView that is used to cover the surface of other view like a scratch card, user can swipe the mulch to see the view below. 30 | DESC 31 | 32 | s.homepage = "https://github.com/Minecodecraft/MCScratchImageView" 33 | # s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif" 34 | 35 | 36 | # ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 37 | # 38 | # Licensing your code is important. See http://choosealicense.com for more info. 39 | # CocoaPods will detect a license file if there is a named LICENSE* 40 | # Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'. 41 | # 42 | 43 | s.license = "MIT" 44 | # s.license = { :type => "MIT", :file => "FILE_LICENSE" } 45 | 46 | 47 | # ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 48 | # 49 | # Specify the authors of the library, with email addresses. Email addresses 50 | # of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also 51 | # accepts just a name if you'd rather not provide an email address. 52 | # 53 | # Specify a social_media_url where others can refer to, for example a twitter 54 | # profile URL. 55 | # 56 | 57 | s.author = { "Minecode" => "Minecoder@163.com" } 58 | # Or just: s.author = "JunLin Bian" 59 | # s.authors = { "JunLin Bian" => "Minecoder@163.com" } 60 | # s.social_media_url = "http://twitter.com/JunLin Bian" 61 | 62 | # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 63 | # 64 | # If this Pod runs only on iOS or OS X, then specify the platform and 65 | # the deployment target. You can optionally include the target after the platform. 66 | # 67 | 68 | # s.platform = :ios 69 | s.platform = :ios, "8.0" 70 | 71 | # When using multiple platforms 72 | # s.ios.deployment_target = "5.0" 73 | # s.osx.deployment_target = "10.7" 74 | # s.watchos.deployment_target = "2.0" 75 | # s.tvos.deployment_target = "9.0" 76 | 77 | 78 | # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 79 | # 80 | # Specify the location from where the source should be retrieved. 81 | # Supports git, hg, bzr, svn and HTTP. 82 | # 83 | 84 | s.source = { :git => "https://github.com/Minecodecraft/MCScratchImageView.git", :tag => "#{s.version}" } 85 | 86 | 87 | # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 88 | # 89 | # CocoaPods is smart about how it includes source code. For source files 90 | # giving a folder will include any swift, h, m, mm, c & cpp files. 91 | # For header files it will include any header in the folder. 92 | # Not including the public_header_files will make all headers public. 93 | # 94 | 95 | s.source_files = "MCScratchImageView/MCScratchImageView.swift" 96 | #s.exclude_files = "Classes/Exclude" 97 | 98 | # s.public_header_files = "Classes/**/*.h" 99 | 100 | 101 | # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 102 | # 103 | # A list of resources included with the Pod. These are copied into the 104 | # target bundle with a build phase script. Anything else will be cleaned. 105 | # You can preserve files from being cleaned, please don't preserve 106 | # non-essential files like tests, examples and documentation. 107 | # 108 | 109 | # s.resource = "icon.png" 110 | # s.resources = "Resources/*.png" 111 | 112 | # s.preserve_paths = "FilesToSave", "MoreFilesToSave" 113 | 114 | 115 | # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 116 | # 117 | # Link your library with frameworks, or libraries. Libraries do not include 118 | # the lib prefix of their name. 119 | # 120 | 121 | s.framework = "UIKit" 122 | # s.frameworks = "SomeFramework", "AnotherFramework" 123 | 124 | # s.library = "iconv" 125 | # s.libraries = "iconv", "xml2" 126 | 127 | 128 | # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 129 | # 130 | # If your library depends on compiler flags you can set them in the xcconfig hash 131 | # where they will only apply to your library. If you depend on other Podspecs 132 | # you can include multiple dependencies to ensure it works. 133 | 134 | # s.requires_arc = true 135 | 136 | # s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" } 137 | # s.dependency "JSONKit", "~> 1.4" 138 | 139 | end 140 | -------------------------------------------------------------------------------- /MCScratchImageView/MCScratchImageView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MCScratchImageView.swift 3 | // MCScratchImageView 4 | // 5 | // Created by Minecode on 2017/12/26. 6 | // Copyright © 2017年 Minecode. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | public protocol MCScratchImageViewDelegate { 12 | 13 | func mcScratchImageView(_ mcScratchImageView: MCScratchImageView, didChangeProgress progress: CGFloat) 14 | 15 | } 16 | 17 | public class MCScratchImageView: UIImageView { 18 | 19 | // MARK: Public stored properties 20 | public weak var delegate: MCScratchImageViewDelegate? 21 | // Determin the radius of the spot 22 | private(set) var spotRadius: CGFloat = 45.0 23 | 24 | // MARK: Public calculate properties 25 | // current scratched progress, 0.0(masked)~1.00(sharped) 26 | public var progress: CGFloat { 27 | get { 28 | return CGFloat(maskedMatrix.scratchedCount) / CGFloat(maskedMatrix.count) 29 | } 30 | } 31 | 32 | // MARK: Private properties 33 | // the martix to determine the grids of maskImage 34 | private var maskedMatrix: MCMatrix! 35 | private var imageContext: CGContext! 36 | private var colorSpace: CGColorSpace! 37 | private var touchedPoints: [CGPoint]! 38 | private let kSpotRadiusDefault: CGFloat = 45.0 39 | private let kBezierStepFactor: CGFloat = 0.2 40 | 41 | // MARK: Private caculate properties 42 | // the size of mask 43 | private var maskSize: MCSize { 44 | get { 45 | return self.maskedMatrix.size 46 | } 47 | } 48 | 49 | // MARK: - Init Function 50 | public override init(frame: CGRect) { 51 | super.init(frame: frame) 52 | 53 | commonInit() 54 | } 55 | 56 | public override init(image: UIImage?) { 57 | super.init(image: image) 58 | 59 | commonInit() 60 | } 61 | 62 | required public init?(coder aDecoder: NSCoder) { 63 | super.init(coder: aDecoder) 64 | 65 | commonInit() 66 | } 67 | 68 | private func commonInit() { 69 | isUserInteractionEnabled = false 70 | 71 | if (self.image != nil) { 72 | self.reset() 73 | } 74 | touchedPoints = [CGPoint]() 75 | } 76 | 77 | // Reminding: This function is to reset the environments, not reset the blured image 78 | // so do not call it outside 79 | private func reset() { 80 | 81 | guard let image = self.image else { 82 | isUserInteractionEnabled = false 83 | return 84 | } 85 | 86 | isUserInteractionEnabled = true 87 | touchedPoints.removeAll() 88 | // initalize the image context 89 | let imageWidth = image.size.width * image.scale 90 | let imageHeight = image.size.height * image.scale 91 | colorSpace = CGColorSpaceCreateDeviceRGB() 92 | imageContext = CGContext(data: nil, width: Int(imageWidth), height: Int(imageHeight), bitsPerComponent: 8, bytesPerRow: Int(imageWidth*4), space: colorSpace, bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue) 93 | // draw the hole blured image 94 | imageContext.draw(image.cgImage!, in: CGRect(x: 0, y: 0, width: imageWidth, height: imageHeight)) 95 | imageContext.setBlendMode(CGBlendMode.clear) 96 | 97 | // initialize the mask matrix 98 | self.maskedMatrix = MCMatrix(x: Int(imageWidth/(2*spotRadius)), y: Int(imageHeight/(2*spotRadius))) 99 | } 100 | 101 | public func setMaskImage(_ image: UIImage, spotRadius: CGFloat) { 102 | self.image = image 103 | self.spotRadius = spotRadius 104 | self.reset() 105 | } 106 | 107 | public func setMaskImage(_ image: UIImage) { 108 | self.setMaskImage(image, spotRadius: kSpotRadiusDefault) 109 | self.reset() 110 | } 111 | 112 | public func scratchAll() { 113 | // store current process 114 | let currentProgress = self.progress 115 | 116 | // reset masked matrix 117 | self.maskedMatrix.reset(status: true, scratched: maskedMatrix.count) 118 | 119 | let imageWidth = image!.size.width * image!.scale 120 | let imageHeight = image!.size.height * image!.scale 121 | imageContext = CGContext(data: nil, width: Int(imageWidth), height: Int(imageHeight), bitsPerComponent: 8, bytesPerRow: Int(imageWidth*4), space: colorSpace, bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue) 122 | self.image = UIImage(cgImage: imageContext.makeImage()!) 123 | 124 | if (currentProgress != self.progress) { 125 | self.delegate?.mcScratchImageView(self, didChangeProgress: self.progress) 126 | } 127 | } 128 | 129 | // MARK: - Core Graphic draw funtion 130 | private func addTouches(_ touches: Set) -> UIImage { 131 | let imageSize = CGSize(width: self.image!.size.width*self.image!.scale, height: self.image!.size.height*self.image!.scale) 132 | let currentProgress = self.progress 133 | 134 | // set image context 135 | let ctx = imageContext! 136 | ctx.setStrokeColor(UIColor.clear.cgColor) 137 | ctx.setFillColor(UIColor.clear.cgColor) 138 | ctx.setLineWidth(2*spotRadius) 139 | ctx.setLineCap(CGLineCap.round) 140 | 141 | for touch in touches { 142 | ctx.beginPath() 143 | let touchPoint = covertCoordinateToQuartz(touch.location(in: self), imageSize: imageSize) 144 | 145 | // deal with first touch 146 | if (touch.phase == .began) { 147 | touchedPoints.removeAll() 148 | touchedPoints.append(touchPoint) 149 | touchedPoints.append(touchPoint) 150 | 151 | // if current is touch begin, just add an ellipse 152 | let ellipseRect = CGRect(x: touchPoint.x-spotRadius, y: touchPoint.y-spotRadius, width: spotRadius*2, height: spotRadius*2) 153 | ctx.addEllipse(in: ellipseRect) 154 | ctx.fillPath() 155 | 156 | updateGrid(withPointX: ellipseRect.origin.x, pointY: ellipseRect.origin.y) 157 | } 158 | else if (touch.phase == .moved) { 159 | touchedPoints.append(touchPoint) 160 | 161 | // use touchpoints to draw a bezier path 162 | // using CGContextAddCurveToPoint with 4 point 163 | while (self.touchedPoints.count >= 4) { 164 | var points: [CGPoint] = [CGPoint](repeating: CGPoint(), count: 4) 165 | points[0] = touchedPoints[1] 166 | points[1] = touchedPoints[0] 167 | points[2] = touchedPoints[3] 168 | points[3] = touchedPoints[2] 169 | 170 | let centerMargin: CGFloat = sqrt(pow(points[3].x-points[0].x, 2) + pow(points[3].y-points[0].y, 2)) 171 | var xPointCursor: CGFloat = 0.0 172 | var yPointCursor: CGFloat = 0.0 173 | 174 | // scale the to other point 175 | xPointCursor = (points[0].x - points[1].x) - (points[0].x - points[3].x) 176 | yPointCursor = (points[0].y - points[1].y) - (points[0].y - points[3].y) 177 | points[1] = formPointToScale(x: xPointCursor, y: yPointCursor) 178 | points[1] = formPoint(points[1], margin: centerMargin, factor: kBezierStepFactor) 179 | points[1].x += points[0].x 180 | points[1].y += points[0].y 181 | 182 | xPointCursor = (points[3].x - points[2].x) - (points[3].x - points[0].x) 183 | yPointCursor = (points[3].y - points[2].y) - (points[3].y - points[0].y) 184 | points[2] = formPointToScale(x: xPointCursor, y: yPointCursor) 185 | points[2] = formPoint(points[2], margin: centerMargin, factor: kBezierStepFactor) 186 | points[2].x += points[3].x 187 | points[2].y += points[3].y 188 | 189 | ctx.move(to: points[0]) 190 | ctx.addCurve(to: points[1], control1: points[2], control2: points[3]) 191 | 192 | touchedPoints.remove(at: 0) 193 | } 194 | 195 | ctx.strokePath() 196 | let preTouchPoint = covertCoordinateToQuartz(touch.previousLocation(in: self), imageSize: imageSize) 197 | updateGrid(withBeginPoint: touchPoint, endPoint: preTouchPoint) 198 | } 199 | 200 | } 201 | 202 | if (currentProgress != self.progress) { 203 | self.delegate?.mcScratchImageView(self, didChangeProgress: self.progress) 204 | } 205 | 206 | let cgImage = ctx.makeImage() 207 | let resImage = UIImage(cgImage: cgImage!) 208 | return resImage 209 | } 210 | 211 | private func formPointToScale(x: CGFloat, y: CGFloat) -> CGPoint { 212 | let len = sqrt(x*x + y*y) 213 | if (len == 0) { 214 | return CGPoint.zero 215 | } 216 | return CGPoint(x: x/len, y: y/len) 217 | } 218 | 219 | private func formPoint(_ point: CGPoint, margin: CGFloat, factor: CGFloat) -> CGPoint { 220 | var res = point 221 | res.x *= margin 222 | res.y *= margin 223 | res.x *= factor 224 | res.y *= factor 225 | return res 226 | } 227 | 228 | // convert UI coordinate to Quartz coordinate 229 | private func covertCoordinateToQuartz(_ point: CGPoint, imageSize: CGSize) -> CGPoint { 230 | return CGPoint(x: imageSize.width * point.x / self.bounds.size.width, y: imageSize.height * (self.bounds.height-point.y) / self.bounds.size.height) 231 | } 232 | 233 | // MARK: - touch event handler 234 | override public func touchesBegan(_ touches: Set, with event: UIEvent?) { 235 | 236 | if (self.image == nil) {return} 237 | self.image = self.addTouches(touches) 238 | 239 | } 240 | 241 | override public func touchesMoved(_ touches: Set, with event: UIEvent?) { 242 | 243 | if (self.image == nil) {return} 244 | self.image = self.addTouches(touches) 245 | 246 | } 247 | 248 | // MARK: - Grid filled function 249 | // Reminder: This function is to update the data of matrix 250 | // The draw function has written above 251 | private func updateGrid(withPointX x: CGFloat, pointY y: CGFloat) { 252 | 253 | let imageWidth = image!.size.width * image!.scale 254 | let imageHeight = image!.size.height * image!.scale 255 | let xCursor = min(imageWidth-1, max(0, x)) 256 | let yCursor = min(imageHeight-1, max(0, y)) 257 | let xIdx = Int( xCursor * CGFloat(maskedMatrix.size.x) / imageWidth) 258 | let yIdx = Int( yCursor * CGFloat(maskedMatrix.size.y) / imageHeight) 259 | 260 | if (maskedMatrix.statusForGrid(x: xIdx, y: yIdx) == false) { 261 | maskedMatrix.setGrid(x: xIdx, y: yIdx, forStatus: true) 262 | } 263 | 264 | } 265 | 266 | private func updateGrid(withBeginPoint begin: CGPoint, endPoint end: CGPoint) { 267 | 268 | let imageWidth = image!.size.width * image!.scale 269 | let imageHeight = image!.size.height * image!.scale 270 | 271 | var idx = begin 272 | let kIncreaseStepX = (begin.x < end.x ? 1 : -1) * imageWidth / CGFloat(maskSize.x); 273 | let kIncreaseStepY = (begin.y < end.y ? 1 : -1) * imageHeight / CGFloat(maskSize.y); 274 | 275 | while (idx.x>=min(begin.x, end.x) && idx.x<=max(begin.x, end.x) && idx.y>=min(begin.y, end.y) && idx.y<=max(begin.y, end.y)) { 276 | updateGrid(withPointX: idx.x, pointY: idx.y) 277 | 278 | idx.x += kIncreaseStepX 279 | idx.y += kIncreaseStepY 280 | } 281 | updateGrid(withPointX: idx.x, pointY: idx.y) 282 | 283 | } 284 | } 285 | 286 | 287 | // MARK: - The matrix struct that determine the mask grids 288 | fileprivate struct MCMatrix { 289 | 290 | // stored properties 291 | private(set) var size: MCSize 292 | private(set) var gridScratched: [Bool]! 293 | 294 | // calculate properties 295 | var count: Int { 296 | get { 297 | return size.x*size.y 298 | } 299 | } 300 | private(set) var scratchedCount: Int 301 | 302 | init(_ size: MCSize) { 303 | self.size = size 304 | scratchedCount = 0 305 | gridScratched = [Bool](repeating: false, count: self.count) 306 | } 307 | 308 | init(x: Int, y: Int) { 309 | self.init(MCSize(x: x, y: y)) 310 | } 311 | 312 | public func statusForGrid(x: Int, y: Int) -> Bool { 313 | if (x*y >= count) {return true} 314 | return gridScratched[x + size.x*y] 315 | } 316 | 317 | public mutating func setGrid(x: Int, y: Int, forStatus status: Bool) { 318 | if (x*y >= count) {return} 319 | if (gridScratched[x + size.x*y] != status) { 320 | scratchedCount += status ? 1 : -1 321 | gridScratched[x + size.x*y] = status 322 | } 323 | } 324 | 325 | public mutating func reset( status: Bool = false, scratched: Int = 0) { 326 | gridScratched = [Bool](repeating: status, count: self.count) 327 | scratchedCount = scratched 328 | } 329 | 330 | } 331 | 332 | // MARK: - The Size struct 333 | fileprivate struct MCSize { 334 | 335 | public var x: Int 336 | public var y: Int 337 | 338 | init(x: Int, y: Int) { 339 | self.x = x 340 | self.y = y 341 | } 342 | 343 | } 344 | fileprivate typealias MCPoint = MCSize 345 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MCScratchImageView 2 | 3 | ![MCScratchImageView](http://cdn.minecode.link/MCScratchImageView_MCScratchViewHeader.png) 4 | 5 | [![platform](https://img.shields.io/badge/platform-iOS-blue.svg)](https://developer.apple.com/) [![Swift](https://img.shields.io/badge/Swift-4.0-orange.svg)](https://developer.apple.com/swift/) [![license](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://github.com/Minecodecraft/MCScratchImageView/blob/master/LICENSE) 6 | 7 | --- 8 | ### GIF Showcase 9 | ![Showcase1](https://github.com/Minecodecraft/MCScratchImageView/blob/master/GIFShowcase/Showcase1.gif) 10 | 11 | ![Showcase2](https://github.com/Minecodecraft/MCScratchImageView/blob/master/GIFShowcase/Showcase2.gif) 12 | 13 | --- 14 | 15 | ## Requirments 16 | iOS 8.0+ 17 | Xcode 7.2+ 18 | Swift 4.0 19 | 20 | ## Installation 21 | 22 | #### CocoaPods 23 | 24 | ```ruby 25 | pod "MCScratchImageView" 26 | ``` 27 | 28 | #### Manually 29 | 30 | Just drag `MCScratchImageView.swift` to the project tree 31 | 32 | ## Usage 33 | 34 | #### Import 35 | 36 | If you use CocoaPods, first import MCScratchImageView 37 | ```Swift 38 | import MCScratchImageView 39 | ``` 40 | 41 | #### Define the class variables 42 | 43 | ```Swift 44 | var scratchImageView: MCScratchImageView! 45 | ``` 46 | 47 | #### Initialize it 48 | 49 | ```Swift 50 | // init() 51 | scratchImageView = MCScratchImageView() 52 | // init(frame:) 53 | scratchImageView = MCScratchImageView(frame: yourRect) 54 | ``` 55 | Or use StoryBoard. 56 | 57 | #### Set the mask image & radius 58 | 59 | ```Swift 60 | // use default touch point radius 61 | scratchImageView.setMaskImage(yourUIImage) 62 | // use custom touch point radius 63 | scratchImageView.setMaskImage(yourUIImage, spotRadius: 100) 64 | ``` 65 | 66 | #### Implement the delegate methods: 67 | 68 | ```Swift 69 | // set the delegate 70 | scratchImageView.delegate = *** 71 | 72 | /* ... */ 73 | 74 | // implement the MCScratchImageViewDelegate method 75 | extension YourController: MCScratchImageViewDelegate { 76 | 77 | func mcScratchImageView(_ mcScratchImageView: MCScratchImageView, didChangeProgress progress: CGFloat) { 78 | print("Progress did changed: " + String(format: "%.2f", progress)) 79 | if (progress >= 0.8) { 80 | mcScratchImageView.scratchAll() 81 | } 82 | } 83 | 84 | } 85 | ``` 86 | 87 | #### API declaration 88 | 89 | ```Swift 90 | // current scratched progress 91 | public var progress: CGFloat 92 | // Determin the radius of the touch point 93 | private(set) var spotRadius: CGFloat = 45.0 94 | 95 | // set the mask image & radius 96 | public func setMaskImage(_ image: UIImage) 97 | public func setMaskImage(_ image: UIImage, spotRadius: CGFloat) 98 | 99 | // scratch all mask fields 100 | public func scratchAll() 101 | ``` 102 | 103 | #### Example Project 104 | In "Example" folder. 105 | 106 | #### Tips 107 | 108 | - Don't set the scratchImageView.image directlly, you need to use setMaskImage(paras) to set the mask image. 109 | - Don't set the touch point radius (var spotRadius: CGFloat) directlly. 110 | - The contentMode should use default resize mode. 111 | 112 | ## Author 113 | 114 | Minecode, [minecoder@163.com](mailto:minecoder@163.com) 115 | 116 | ## License 117 | 118 | MCScratchImageView is available under the MIT license. See the LICENSE file for more info. --------------------------------------------------------------------------------