├── OttoScratchView.gif ├── OttoScratchView ├── .DS_Store ├── OttoScratchView.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ └── halo.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── halo.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist └── OttoScratchView │ ├── .DS_Store │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ ├── .DS_Store │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ └── btn_scratch_normal.imageset │ │ ├── Contents.json │ │ └── btn_scratch_normal@2x.png │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ ├── MainViewController.h │ ├── MainViewController.m │ ├── MainViewController.xib │ ├── OttoScratchView │ ├── OttoScratchView.h │ └── OttoScratchView.m │ ├── TableViewController.h │ ├── TableViewController.m │ ├── ViewController.h │ ├── ViewController.m │ └── main.m └── README.md /OttoScratchView.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WuOtto/OttoScratchView/1a1b19e7fb54d2587ffe202912465acae6961ac5/OttoScratchView.gif -------------------------------------------------------------------------------- /OttoScratchView/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WuOtto/OttoScratchView/1a1b19e7fb54d2587ffe202912465acae6961ac5/OttoScratchView/.DS_Store -------------------------------------------------------------------------------- /OttoScratchView/OttoScratchView.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 2C8439092255F35E00B1936C /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C8439082255F35E00B1936C /* AppDelegate.m */; }; 11 | 2C84390C2255F35E00B1936C /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C84390B2255F35E00B1936C /* ViewController.m */; }; 12 | 2C84390F2255F35E00B1936C /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 2C84390D2255F35E00B1936C /* Main.storyboard */; }; 13 | 2C8439112255F36000B1936C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2C8439102255F36000B1936C /* Assets.xcassets */; }; 14 | 2C8439142255F36000B1936C /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 2C8439122255F36000B1936C /* LaunchScreen.storyboard */; }; 15 | 2C8439172255F36000B1936C /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C8439162255F36000B1936C /* main.m */; }; 16 | 2C8439202255F39400B1936C /* OttoScratchView.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C84391F2255F39400B1936C /* OttoScratchView.m */; }; 17 | 2C84392B2255FEB100B1936C /* MainViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C8439292255FEB000B1936C /* MainViewController.m */; }; 18 | 2C84392C2255FEB100B1936C /* MainViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2C84392A2255FEB000B1936C /* MainViewController.xib */; }; 19 | 2CEFF76E225B243F00117CCA /* TableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2CEFF76D225B243F00117CCA /* TableViewController.m */; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXFileReference section */ 23 | 2C8439042255F35E00B1936C /* OttoScratchView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = OttoScratchView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 24 | 2C8439072255F35E00B1936C /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 25 | 2C8439082255F35E00B1936C /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 26 | 2C84390A2255F35E00B1936C /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 27 | 2C84390B2255F35E00B1936C /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 28 | 2C84390E2255F35E00B1936C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 29 | 2C8439102255F36000B1936C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 30 | 2C8439132255F36000B1936C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 31 | 2C8439152255F36000B1936C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 32 | 2C8439162255F36000B1936C /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 33 | 2C84391E2255F39400B1936C /* OttoScratchView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OttoScratchView.h; sourceTree = ""; }; 34 | 2C84391F2255F39400B1936C /* OttoScratchView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OttoScratchView.m; sourceTree = ""; }; 35 | 2C8439282255FEB000B1936C /* MainViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MainViewController.h; sourceTree = ""; }; 36 | 2C8439292255FEB000B1936C /* MainViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MainViewController.m; sourceTree = ""; }; 37 | 2C84392A2255FEB000B1936C /* MainViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MainViewController.xib; sourceTree = ""; }; 38 | 2CEFF76C225B243F00117CCA /* TableViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TableViewController.h; sourceTree = ""; }; 39 | 2CEFF76D225B243F00117CCA /* TableViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TableViewController.m; sourceTree = ""; }; 40 | /* End PBXFileReference section */ 41 | 42 | /* Begin PBXFrameworksBuildPhase section */ 43 | 2C8439012255F35E00B1936C /* Frameworks */ = { 44 | isa = PBXFrameworksBuildPhase; 45 | buildActionMask = 2147483647; 46 | files = ( 47 | ); 48 | runOnlyForDeploymentPostprocessing = 0; 49 | }; 50 | /* End PBXFrameworksBuildPhase section */ 51 | 52 | /* Begin PBXGroup section */ 53 | 2C8438FB2255F35E00B1936C = { 54 | isa = PBXGroup; 55 | children = ( 56 | 2C8439062255F35E00B1936C /* OttoScratchView */, 57 | 2C8439052255F35E00B1936C /* Products */, 58 | ); 59 | sourceTree = ""; 60 | }; 61 | 2C8439052255F35E00B1936C /* Products */ = { 62 | isa = PBXGroup; 63 | children = ( 64 | 2C8439042255F35E00B1936C /* OttoScratchView.app */, 65 | ); 66 | name = Products; 67 | sourceTree = ""; 68 | }; 69 | 2C8439062255F35E00B1936C /* OttoScratchView */ = { 70 | isa = PBXGroup; 71 | children = ( 72 | 2C84391D2255F38200B1936C /* OttoScratchView */, 73 | 2C8439072255F35E00B1936C /* AppDelegate.h */, 74 | 2C8439082255F35E00B1936C /* AppDelegate.m */, 75 | 2CEFF76C225B243F00117CCA /* TableViewController.h */, 76 | 2CEFF76D225B243F00117CCA /* TableViewController.m */, 77 | 2C84390A2255F35E00B1936C /* ViewController.h */, 78 | 2C84390B2255F35E00B1936C /* ViewController.m */, 79 | 2C8439282255FEB000B1936C /* MainViewController.h */, 80 | 2C8439292255FEB000B1936C /* MainViewController.m */, 81 | 2C84392A2255FEB000B1936C /* MainViewController.xib */, 82 | 2C84390D2255F35E00B1936C /* Main.storyboard */, 83 | 2C8439102255F36000B1936C /* Assets.xcassets */, 84 | 2C8439122255F36000B1936C /* LaunchScreen.storyboard */, 85 | 2C8439152255F36000B1936C /* Info.plist */, 86 | 2C8439162255F36000B1936C /* main.m */, 87 | ); 88 | path = OttoScratchView; 89 | sourceTree = ""; 90 | }; 91 | 2C84391D2255F38200B1936C /* OttoScratchView */ = { 92 | isa = PBXGroup; 93 | children = ( 94 | 2C84391E2255F39400B1936C /* OttoScratchView.h */, 95 | 2C84391F2255F39400B1936C /* OttoScratchView.m */, 96 | ); 97 | path = OttoScratchView; 98 | sourceTree = ""; 99 | }; 100 | /* End PBXGroup section */ 101 | 102 | /* Begin PBXNativeTarget section */ 103 | 2C8439032255F35E00B1936C /* OttoScratchView */ = { 104 | isa = PBXNativeTarget; 105 | buildConfigurationList = 2C84391A2255F36000B1936C /* Build configuration list for PBXNativeTarget "OttoScratchView" */; 106 | buildPhases = ( 107 | 2C8439002255F35E00B1936C /* Sources */, 108 | 2C8439012255F35E00B1936C /* Frameworks */, 109 | 2C8439022255F35E00B1936C /* Resources */, 110 | ); 111 | buildRules = ( 112 | ); 113 | dependencies = ( 114 | ); 115 | name = OttoScratchView; 116 | productName = OttoScratchView; 117 | productReference = 2C8439042255F35E00B1936C /* OttoScratchView.app */; 118 | productType = "com.apple.product-type.application"; 119 | }; 120 | /* End PBXNativeTarget section */ 121 | 122 | /* Begin PBXProject section */ 123 | 2C8438FC2255F35E00B1936C /* Project object */ = { 124 | isa = PBXProject; 125 | attributes = { 126 | LastUpgradeCheck = 1020; 127 | ORGANIZATIONNAME = otto; 128 | TargetAttributes = { 129 | 2C8439032255F35E00B1936C = { 130 | CreatedOnToolsVersion = 10.2; 131 | }; 132 | }; 133 | }; 134 | buildConfigurationList = 2C8438FF2255F35E00B1936C /* Build configuration list for PBXProject "OttoScratchView" */; 135 | compatibilityVersion = "Xcode 9.3"; 136 | developmentRegion = en; 137 | hasScannedForEncodings = 0; 138 | knownRegions = ( 139 | en, 140 | Base, 141 | ); 142 | mainGroup = 2C8438FB2255F35E00B1936C; 143 | productRefGroup = 2C8439052255F35E00B1936C /* Products */; 144 | projectDirPath = ""; 145 | projectRoot = ""; 146 | targets = ( 147 | 2C8439032255F35E00B1936C /* OttoScratchView */, 148 | ); 149 | }; 150 | /* End PBXProject section */ 151 | 152 | /* Begin PBXResourcesBuildPhase section */ 153 | 2C8439022255F35E00B1936C /* Resources */ = { 154 | isa = PBXResourcesBuildPhase; 155 | buildActionMask = 2147483647; 156 | files = ( 157 | 2C8439142255F36000B1936C /* LaunchScreen.storyboard in Resources */, 158 | 2C84392C2255FEB100B1936C /* MainViewController.xib in Resources */, 159 | 2C8439112255F36000B1936C /* Assets.xcassets in Resources */, 160 | 2C84390F2255F35E00B1936C /* Main.storyboard in Resources */, 161 | ); 162 | runOnlyForDeploymentPostprocessing = 0; 163 | }; 164 | /* End PBXResourcesBuildPhase section */ 165 | 166 | /* Begin PBXSourcesBuildPhase section */ 167 | 2C8439002255F35E00B1936C /* Sources */ = { 168 | isa = PBXSourcesBuildPhase; 169 | buildActionMask = 2147483647; 170 | files = ( 171 | 2C84390C2255F35E00B1936C /* ViewController.m in Sources */, 172 | 2CEFF76E225B243F00117CCA /* TableViewController.m in Sources */, 173 | 2C8439202255F39400B1936C /* OttoScratchView.m in Sources */, 174 | 2C8439172255F36000B1936C /* main.m in Sources */, 175 | 2C84392B2255FEB100B1936C /* MainViewController.m in Sources */, 176 | 2C8439092255F35E00B1936C /* AppDelegate.m in Sources */, 177 | ); 178 | runOnlyForDeploymentPostprocessing = 0; 179 | }; 180 | /* End PBXSourcesBuildPhase section */ 181 | 182 | /* Begin PBXVariantGroup section */ 183 | 2C84390D2255F35E00B1936C /* Main.storyboard */ = { 184 | isa = PBXVariantGroup; 185 | children = ( 186 | 2C84390E2255F35E00B1936C /* Base */, 187 | ); 188 | name = Main.storyboard; 189 | sourceTree = ""; 190 | }; 191 | 2C8439122255F36000B1936C /* LaunchScreen.storyboard */ = { 192 | isa = PBXVariantGroup; 193 | children = ( 194 | 2C8439132255F36000B1936C /* Base */, 195 | ); 196 | name = LaunchScreen.storyboard; 197 | sourceTree = ""; 198 | }; 199 | /* End PBXVariantGroup section */ 200 | 201 | /* Begin XCBuildConfiguration section */ 202 | 2C8439182255F36000B1936C /* Debug */ = { 203 | isa = XCBuildConfiguration; 204 | buildSettings = { 205 | ALWAYS_SEARCH_USER_PATHS = NO; 206 | CLANG_ANALYZER_NONNULL = YES; 207 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 208 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 209 | CLANG_CXX_LIBRARY = "libc++"; 210 | CLANG_ENABLE_MODULES = YES; 211 | CLANG_ENABLE_OBJC_ARC = YES; 212 | CLANG_ENABLE_OBJC_WEAK = YES; 213 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 214 | CLANG_WARN_BOOL_CONVERSION = YES; 215 | CLANG_WARN_COMMA = YES; 216 | CLANG_WARN_CONSTANT_CONVERSION = YES; 217 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 218 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 219 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 220 | CLANG_WARN_EMPTY_BODY = YES; 221 | CLANG_WARN_ENUM_CONVERSION = YES; 222 | CLANG_WARN_INFINITE_RECURSION = YES; 223 | CLANG_WARN_INT_CONVERSION = YES; 224 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 225 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 226 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 227 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 228 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 229 | CLANG_WARN_STRICT_PROTOTYPES = YES; 230 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 231 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 232 | CLANG_WARN_UNREACHABLE_CODE = YES; 233 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 234 | CODE_SIGN_IDENTITY = "iPhone Developer"; 235 | COPY_PHASE_STRIP = NO; 236 | DEBUG_INFORMATION_FORMAT = dwarf; 237 | ENABLE_STRICT_OBJC_MSGSEND = YES; 238 | ENABLE_TESTABILITY = YES; 239 | GCC_C_LANGUAGE_STANDARD = gnu11; 240 | GCC_DYNAMIC_NO_PIC = NO; 241 | GCC_NO_COMMON_BLOCKS = YES; 242 | GCC_OPTIMIZATION_LEVEL = 0; 243 | GCC_PREPROCESSOR_DEFINITIONS = ( 244 | "DEBUG=1", 245 | "$(inherited)", 246 | ); 247 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 248 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 249 | GCC_WARN_UNDECLARED_SELECTOR = YES; 250 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 251 | GCC_WARN_UNUSED_FUNCTION = YES; 252 | GCC_WARN_UNUSED_VARIABLE = YES; 253 | IPHONEOS_DEPLOYMENT_TARGET = 12.2; 254 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 255 | MTL_FAST_MATH = YES; 256 | ONLY_ACTIVE_ARCH = YES; 257 | SDKROOT = iphoneos; 258 | }; 259 | name = Debug; 260 | }; 261 | 2C8439192255F36000B1936C /* Release */ = { 262 | isa = XCBuildConfiguration; 263 | buildSettings = { 264 | ALWAYS_SEARCH_USER_PATHS = NO; 265 | CLANG_ANALYZER_NONNULL = YES; 266 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 267 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 268 | CLANG_CXX_LIBRARY = "libc++"; 269 | CLANG_ENABLE_MODULES = YES; 270 | CLANG_ENABLE_OBJC_ARC = YES; 271 | CLANG_ENABLE_OBJC_WEAK = YES; 272 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 273 | CLANG_WARN_BOOL_CONVERSION = YES; 274 | CLANG_WARN_COMMA = YES; 275 | CLANG_WARN_CONSTANT_CONVERSION = YES; 276 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 277 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 278 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 279 | CLANG_WARN_EMPTY_BODY = YES; 280 | CLANG_WARN_ENUM_CONVERSION = YES; 281 | CLANG_WARN_INFINITE_RECURSION = YES; 282 | CLANG_WARN_INT_CONVERSION = YES; 283 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 284 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 285 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 286 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 287 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 288 | CLANG_WARN_STRICT_PROTOTYPES = YES; 289 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 290 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 291 | CLANG_WARN_UNREACHABLE_CODE = YES; 292 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 293 | CODE_SIGN_IDENTITY = "iPhone Developer"; 294 | COPY_PHASE_STRIP = NO; 295 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 296 | ENABLE_NS_ASSERTIONS = NO; 297 | ENABLE_STRICT_OBJC_MSGSEND = YES; 298 | GCC_C_LANGUAGE_STANDARD = gnu11; 299 | GCC_NO_COMMON_BLOCKS = YES; 300 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 301 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 302 | GCC_WARN_UNDECLARED_SELECTOR = YES; 303 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 304 | GCC_WARN_UNUSED_FUNCTION = YES; 305 | GCC_WARN_UNUSED_VARIABLE = YES; 306 | IPHONEOS_DEPLOYMENT_TARGET = 12.2; 307 | MTL_ENABLE_DEBUG_INFO = NO; 308 | MTL_FAST_MATH = YES; 309 | SDKROOT = iphoneos; 310 | VALIDATE_PRODUCT = YES; 311 | }; 312 | name = Release; 313 | }; 314 | 2C84391B2255F36000B1936C /* Debug */ = { 315 | isa = XCBuildConfiguration; 316 | buildSettings = { 317 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 318 | CODE_SIGN_STYLE = Automatic; 319 | DEVELOPMENT_TEAM = 7D6HATSF7M; 320 | INFOPLIST_FILE = OttoScratchView/Info.plist; 321 | LD_RUNPATH_SEARCH_PATHS = ( 322 | "$(inherited)", 323 | "@executable_path/Frameworks", 324 | ); 325 | PRODUCT_BUNDLE_IDENTIFIER = otto.OttoScratchView; 326 | PRODUCT_NAME = "$(TARGET_NAME)"; 327 | TARGETED_DEVICE_FAMILY = "1,2"; 328 | }; 329 | name = Debug; 330 | }; 331 | 2C84391C2255F36000B1936C /* Release */ = { 332 | isa = XCBuildConfiguration; 333 | buildSettings = { 334 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 335 | CODE_SIGN_STYLE = Automatic; 336 | DEVELOPMENT_TEAM = 7D6HATSF7M; 337 | INFOPLIST_FILE = OttoScratchView/Info.plist; 338 | LD_RUNPATH_SEARCH_PATHS = ( 339 | "$(inherited)", 340 | "@executable_path/Frameworks", 341 | ); 342 | PRODUCT_BUNDLE_IDENTIFIER = otto.OttoScratchView; 343 | PRODUCT_NAME = "$(TARGET_NAME)"; 344 | TARGETED_DEVICE_FAMILY = "1,2"; 345 | }; 346 | name = Release; 347 | }; 348 | /* End XCBuildConfiguration section */ 349 | 350 | /* Begin XCConfigurationList section */ 351 | 2C8438FF2255F35E00B1936C /* Build configuration list for PBXProject "OttoScratchView" */ = { 352 | isa = XCConfigurationList; 353 | buildConfigurations = ( 354 | 2C8439182255F36000B1936C /* Debug */, 355 | 2C8439192255F36000B1936C /* Release */, 356 | ); 357 | defaultConfigurationIsVisible = 0; 358 | defaultConfigurationName = Release; 359 | }; 360 | 2C84391A2255F36000B1936C /* Build configuration list for PBXNativeTarget "OttoScratchView" */ = { 361 | isa = XCConfigurationList; 362 | buildConfigurations = ( 363 | 2C84391B2255F36000B1936C /* Debug */, 364 | 2C84391C2255F36000B1936C /* Release */, 365 | ); 366 | defaultConfigurationIsVisible = 0; 367 | defaultConfigurationName = Release; 368 | }; 369 | /* End XCConfigurationList section */ 370 | }; 371 | rootObject = 2C8438FC2255F35E00B1936C /* Project object */; 372 | } 373 | -------------------------------------------------------------------------------- /OttoScratchView/OttoScratchView.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /OttoScratchView/OttoScratchView.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /OttoScratchView/OttoScratchView.xcodeproj/project.xcworkspace/xcuserdata/halo.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WuOtto/OttoScratchView/1a1b19e7fb54d2587ffe202912465acae6961ac5/OttoScratchView/OttoScratchView.xcodeproj/project.xcworkspace/xcuserdata/halo.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /OttoScratchView/OttoScratchView.xcodeproj/xcuserdata/halo.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /OttoScratchView/OttoScratchView.xcodeproj/xcuserdata/halo.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | OttoScratchView.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /OttoScratchView/OttoScratchView/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WuOtto/OttoScratchView/1a1b19e7fb54d2587ffe202912465acae6961ac5/OttoScratchView/OttoScratchView/.DS_Store -------------------------------------------------------------------------------- /OttoScratchView/OttoScratchView/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // OttoScratchView 4 | // 5 | // Created by halo on 2019/4/4. 6 | // Copyright © 2019 otto. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /OttoScratchView/OttoScratchView/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // OttoScratchView 4 | // 5 | // Created by halo on 2019/4/4. 6 | // Copyright © 2019 otto. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "TableViewController.h" 11 | 12 | @interface AppDelegate () 13 | 14 | @end 15 | 16 | @implementation AppDelegate 17 | 18 | 19 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 20 | // Override point for customization after application launch. 21 | UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[[TableViewController alloc] init]]; 22 | self.window.rootViewController = nav; 23 | [self.window makeKeyAndVisible]; 24 | 25 | return YES; 26 | } 27 | 28 | 29 | - (void)applicationWillResignActive:(UIApplication *)application { 30 | // 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. 31 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 32 | } 33 | 34 | 35 | - (void)applicationDidEnterBackground:(UIApplication *)application { 36 | // 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. 37 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 38 | } 39 | 40 | 41 | - (void)applicationWillEnterForeground:(UIApplication *)application { 42 | // 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. 43 | } 44 | 45 | 46 | - (void)applicationDidBecomeActive:(UIApplication *)application { 47 | // 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. 48 | } 49 | 50 | 51 | - (void)applicationWillTerminate:(UIApplication *)application { 52 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 53 | } 54 | 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /OttoScratchView/OttoScratchView/Assets.xcassets/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WuOtto/OttoScratchView/1a1b19e7fb54d2587ffe202912465acae6961ac5/OttoScratchView/OttoScratchView/Assets.xcassets/.DS_Store -------------------------------------------------------------------------------- /OttoScratchView/OttoScratchView/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /OttoScratchView/OttoScratchView/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /OttoScratchView/OttoScratchView/Assets.xcassets/btn_scratch_normal.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "btn_scratch_normal@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /OttoScratchView/OttoScratchView/Assets.xcassets/btn_scratch_normal.imageset/btn_scratch_normal@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WuOtto/OttoScratchView/1a1b19e7fb54d2587ffe202912465acae6961ac5/OttoScratchView/OttoScratchView/Assets.xcassets/btn_scratch_normal.imageset/btn_scratch_normal@2x.png -------------------------------------------------------------------------------- /OttoScratchView/OttoScratchView/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 | -------------------------------------------------------------------------------- /OttoScratchView/OttoScratchView/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 | -------------------------------------------------------------------------------- /OttoScratchView/OttoScratchView/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /OttoScratchView/OttoScratchView/MainViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // MainViewController.h 3 | // OttoScratchView 4 | // 5 | // Created by halo on 2019/4/4. 6 | // Copyright © 2019 otto. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MainViewController : UIViewController 12 | @property (weak, nonatomic) IBOutlet UIView *scratchView; 13 | @property (weak, nonatomic) IBOutlet UILabel *answerLabel; 14 | @property (weak, nonatomic) IBOutlet UIButton *showButton; 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /OttoScratchView/OttoScratchView/MainViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // MainViewController.m 3 | // OttoScratchView 4 | // 5 | // Created by halo on 2019/4/4. 6 | // Copyright © 2019 otto. All rights reserved. 7 | // 8 | 9 | #import "MainViewController.h" 10 | #import "OttoScratchView.h" 11 | 12 | @interface MainViewController () 13 | 14 | @property (nonatomic,strong) OttoScratchView * ottoScratchView; 15 | @property (nonatomic,copy) NSString * answer; 16 | @property (nonatomic,strong) UILabel *aLabel; 17 | 18 | 19 | @end 20 | 21 | @implementation MainViewController 22 | 23 | - (void)viewDidLoad { 24 | [super viewDidLoad]; 25 | // Do any additional setup after loading the view from its nib. 26 | 27 | self.answer = @"~大西几~"; 28 | 29 | [self ottoSetScratchView]; 30 | } 31 | 32 | - (void)scratchViewDone{ 33 | [self.ottoScratchView removeFromSuperview]; 34 | [self.answerLabel setHidden:NO]; 35 | } 36 | 37 | - (void)ottoSetScratchView{ 38 | [self.ottoScratchView removeFromSuperview]; 39 | [self.answerLabel setHidden:YES]; 40 | self.ottoScratchView = [[OttoScratchView alloc] initWithFrame:CGRectMake(0, 0, self.scratchView.frame.size.width, self.scratchView.frame.size.height)]; 41 | self.ottoScratchView.delegate = self; 42 | 43 | self.ottoScratchView.scratchLineWidth = 14; 44 | self.ottoScratchView.passCount = 9; 45 | self.aLabel = [[UILabel alloc] initWithFrame:self.ottoScratchView.frame]; 46 | self.aLabel.text = self.answer; 47 | self.answerLabel.text = self.answer; 48 | self.aLabel.font = [UIFont boldSystemFontOfSize:30]; 49 | self.aLabel.backgroundColor = [UIColor colorWithRed:254/255.0 green:194/255.0 blue:12/255.0 alpha:1.0]; 50 | self.aLabel.textColor = [UIColor whiteColor]; 51 | self.aLabel.numberOfLines = 0; 52 | [self.aLabel setTextAlignment:(NSTextAlignmentCenter)]; 53 | self.aLabel.adjustsFontSizeToFitWidth = YES; 54 | [self.ottoScratchView addSubview:self.aLabel]; 55 | 56 | [self.scratchView insertSubview:self.ottoScratchView belowSubview:self.showButton]; 57 | [self.showButton setHidden:NO]; 58 | } 59 | 60 | - (IBAction)clickShowButton:(UIButton *)sender { 61 | [self.showButton setHidden:YES]; 62 | } 63 | 64 | - (IBAction)recoveryAction:(UIButton *)sender { 65 | [self ottoSetScratchView]; 66 | } 67 | 68 | /* 69 | #pragma mark - Navigation 70 | 71 | // In a storyboard-based application, you will often want to do a little preparation before navigation 72 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 73 | // Get the new view controller using [segue destinationViewController]. 74 | // Pass the selected object to the new view controller. 75 | } 76 | */ 77 | 78 | @end 79 | -------------------------------------------------------------------------------- /OttoScratchView/OttoScratchView/MainViewController.xib: -------------------------------------------------------------------------------- 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 | 39 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /OttoScratchView/OttoScratchView/OttoScratchView/OttoScratchView.h: -------------------------------------------------------------------------------- 1 | // 2 | // OttoScratchView.h 3 | // OttoScratchView 4 | // 5 | // Created by halo on 2019/4/4. 6 | // Copyright © 2019 otto. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol OttoScratchViewDelegate 12 | 13 | - (void)scratchViewDone; 14 | 15 | @end 16 | 17 | @interface OttoScratchView : UIView 18 | 19 | @property (nonatomic,assign) id delegate; 20 | 21 | /** 22 | * 轨迹的宽度,默认为14 23 | */ 24 | @property (nonatomic,assign) CGFloat scratchLineWidth; 25 | /** 26 | * 经过多少块撤销图层,默认为10.0,最大为16 27 | */ 28 | @property (nonatomic,assign) NSInteger passCount; 29 | 30 | //- (void)initView; 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /OttoScratchView/OttoScratchView/OttoScratchView/OttoScratchView.m: -------------------------------------------------------------------------------- 1 | // 2 | // OttoScratchView.m 3 | // OttoScratchView 4 | // 5 | // Created by halo on 2019/4/4. 6 | // Copyright © 2019 otto. All rights reserved. 7 | // 8 | 9 | #import "OttoScratchView.h" 10 | 11 | @interface OttoScratchView () 12 | 13 | @property (nonatomic, strong) CALayer * maskLayer; 14 | 15 | @property (nonatomic, assign) CGPoint startPoint;; 16 | 17 | @property (nonatomic, strong) NSMutableArray *rectArr; 18 | @property (nonatomic, strong) NSMutableArray *passRectArr; 19 | 20 | @end 21 | 22 | @implementation OttoScratchView 23 | 24 | - (instancetype)initWithFrame:(CGRect)frame{ 25 | 26 | self = [super initWithFrame:frame]; 27 | 28 | if (self) { 29 | [self initView]; 30 | } 31 | return self; 32 | } 33 | 34 | - (void)awakeFromNib{ 35 | [super awakeFromNib]; 36 | [self initView]; 37 | } 38 | 39 | - (void)initView{ 40 | self.layer.mask = [CALayer new]; 41 | self.scratchLineWidth = 14; 42 | self.passCount = 10.0; 43 | CGFloat rectW = self.frame.size.width / 4; 44 | CGFloat rectH = self.frame.size.height / 4; 45 | for (int i = 0; i < 4; i++) { 46 | for (int j = 0; j < 4; j++) { 47 | CGRect rect = CGRectMake(j * rectW, i * rectH, rectW, rectH); 48 | [self.rectArr addObject:[NSValue valueWithCGRect:rect]]; 49 | } 50 | } 51 | } 52 | 53 | 54 | - (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 55 | { 56 | UITouch *touch = [[event allTouches] anyObject]; 57 | CGPoint touchLocation = [touch locationInView:self]; 58 | self.startPoint = touchLocation; 59 | 60 | //获取touch对象 61 | UITouch * t = touches.anyObject; 62 | [self recordPassRect:t]; 63 | } 64 | 65 | - (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 66 | { 67 | UITouch *touch = [[event allTouches] anyObject]; 68 | CGPoint touchLocation = [touch locationInView:self]; 69 | CAShapeLayer * layer = [CAShapeLayer new]; 70 | layer.path = [self getPathFromPointA:self.startPoint toPointB:touchLocation].CGPath; 71 | if(!_maskLayer){ 72 | _maskLayer = [CALayer new]; 73 | } 74 | [_maskLayer addSublayer:layer]; 75 | 76 | self.layer.mask = _maskLayer; 77 | self.startPoint = touchLocation; 78 | 79 | //获取touch对象 80 | UITouch *t = touches.anyObject; 81 | [self recordPassRect:t]; 82 | } 83 | 84 | - (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 85 | { 86 | UITouch *touch = [[event allTouches] anyObject]; 87 | CGPoint touchLocation = [touch locationInView:self]; 88 | CAShapeLayer * layer = [CAShapeLayer new]; 89 | layer.path = [self getPathFromPointA:self.startPoint toPointB:touchLocation].CGPath; 90 | if(!_maskLayer){ 91 | _maskLayer = [CALayer new]; 92 | } 93 | [_maskLayer addSublayer:layer]; 94 | 95 | self.layer.mask = _maskLayer; 96 | 97 | //获取touch对象 98 | UITouch *t = touches.anyObject; 99 | [self recordPassRect:t]; 100 | } 101 | 102 | - (UIBezierPath *) getPathFromPointA:(CGPoint)a toPointB : (CGPoint) b 103 | { 104 | UIBezierPath * path = [UIBezierPath new]; 105 | UIBezierPath * curv1 = [UIBezierPath bezierPathWithArcCenter:a radius:self.scratchLineWidth startAngle:angleBetweenPoints(a, b)+M_PI_2 endAngle:angleBetweenPoints(a, b)+M_PI+M_PI_2 clockwise:b.x >= a.x]; 106 | [path appendPath:curv1]; 107 | UIBezierPath * curv2 = [UIBezierPath bezierPathWithArcCenter:b radius:self.scratchLineWidth startAngle:angleBetweenPoints(a, b)-M_PI_2 endAngle:angleBetweenPoints(a, b)+M_PI_2 clockwise:b.x >= a.x]; 108 | [path addLineToPoint:CGPointMake(b.x * 2 - curv2.currentPoint.x, b.y * 2 - curv2.currentPoint.y)]; 109 | [path appendPath:curv2]; 110 | [path addLineToPoint:CGPointMake(a.x * 2 - curv1.currentPoint.x, a.y * 2 - curv1.currentPoint.y)]; 111 | [path closePath]; 112 | return path; 113 | } 114 | 115 | CGFloat angleBetweenPoints(CGPoint first, CGPoint second) { 116 | CGFloat height = second.y - first.y; 117 | if(height == 0){ 118 | return 0; 119 | } 120 | CGFloat width = first.x - second.x; 121 | if(width == 0){ 122 | return M_PI_2; 123 | } 124 | CGFloat rads = atan(height/width); 125 | return -rads; 126 | } 127 | 128 | 129 | #pragma mark --记录走过的区域 130 | - (void)recordPassRect:(UITouch *)touch { 131 | //获取点击的点 132 | CGPoint point =[touch locationInView:touch.view]; 133 | // 遍历所有的区域,判断是否包含了点击的点 134 | for (int i=0; i < self.rectArr.count; i++) { 135 | CGRect rect = [self.rectArr[i] CGRectValue]; 136 | if (CGRectContainsPoint(rect, point)) { 137 | if (![self.passRectArr containsObject:self.rectArr[i]]) { 138 | //把触摸到区域添加到数组 139 | [self.passRectArr addObject:self.rectArr[i]]; 140 | //经过了一半的区域,则移除自身 141 | if (self.passRectArr.count >= self.passCount) { 142 | [self dismiss]; 143 | } 144 | } 145 | 146 | } 147 | } 148 | } 149 | 150 | - (void)dismiss { 151 | // NSLog(@"dismiss"); 152 | if ([self.delegate respondsToSelector:@selector(scratchViewDone)]) { 153 | [self.delegate scratchViewDone]; 154 | } 155 | } 156 | 157 | 158 | - (NSMutableArray *)rectArr{ 159 | if (_rectArr == nil) { 160 | _rectArr = [NSMutableArray array]; 161 | } 162 | return _rectArr; 163 | } 164 | 165 | - (NSMutableArray *)passRectArr { 166 | if (_passRectArr == nil) { 167 | _passRectArr = [NSMutableArray array]; 168 | } 169 | return _passRectArr; 170 | } 171 | 172 | @end 173 | -------------------------------------------------------------------------------- /OttoScratchView/OttoScratchView/TableViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // TableViewController.h 3 | // OttoScratchView 4 | // 5 | // Created by halo on 2019/4/8. 6 | // Copyright © 2019 otto. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface TableViewController : UITableViewController 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /OttoScratchView/OttoScratchView/TableViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // TableViewController.m 3 | // OttoScratchView 4 | // 5 | // Created by halo on 2019/4/8. 6 | // Copyright © 2019 otto. All rights reserved. 7 | // 8 | 9 | #import "TableViewController.h" 10 | #import "ViewController.h" 11 | #import "MainViewController.h" 12 | 13 | @interface TableViewController () 14 | 15 | @end 16 | 17 | @implementation TableViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | 22 | self.tableView.tableFooterView = [[UIView alloc] init]; 23 | } 24 | 25 | #pragma mark - Table view data source 26 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 27 | return 1; 28 | } 29 | 30 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 31 | return 2; 32 | } 33 | 34 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 35 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; 36 | if (!cell) { 37 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; 38 | } 39 | cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 40 | if (indexPath.row == 0){ 41 | cell.textLabel.text = @"纯代码实现"; 42 | }else if (indexPath.row == 1){ 43 | cell.textLabel.text = @"Xib实现"; 44 | } 45 | 46 | return cell; 47 | } 48 | 49 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 50 | if (indexPath.row == 0){ 51 | [self.navigationController pushViewController:[ViewController new] animated:YES]; 52 | }else if (indexPath.row == 1){ 53 | [self.navigationController pushViewController:[MainViewController new] animated:YES]; 54 | } 55 | } 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /OttoScratchView/OttoScratchView/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // OttoScratchView 4 | // 5 | // Created by halo on 2019/4/4. 6 | // Copyright © 2019 otto. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /OttoScratchView/OttoScratchView/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // OttoScratchView 4 | // 5 | // Created by halo on 2019/4/4. 6 | // Copyright © 2019 otto. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "OttoScratchView.h" 11 | 12 | @interface ViewController () 13 | 14 | @property (nonatomic,strong) OttoScratchView * ottoScratchView; 15 | @property (nonatomic,copy) NSString * answer; 16 | @property (nonatomic,strong) UILabel *aLabel; 17 | @property (nonatomic,strong) UILabel *answerLabel; 18 | @property (nonatomic,strong) UIImageView *coverImageView; 19 | 20 | 21 | @end 22 | 23 | @implementation ViewController 24 | 25 | - (void)viewDidLoad { 26 | [super viewDidLoad]; 27 | 28 | self.view.backgroundColor = [UIColor whiteColor]; 29 | 30 | self.answer = @"小脑斧"; 31 | 32 | CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width; 33 | CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height; 34 | 35 | self.coverImageView = [[UIImageView alloc] initWithFrame:CGRectMake((screenWidth - 272) / 2.0, (screenHeight - 82) / 2.0, 272, 82)]; 36 | 37 | self.coverImageView.image = [UIImage imageNamed:@"btn_scratch_normal"]; 38 | [self.view addSubview:self.coverImageView]; 39 | 40 | self.answerLabel = [[UILabel alloc] initWithFrame:self.coverImageView.frame]; 41 | self.answerLabel.font = [UIFont boldSystemFontOfSize:30]; 42 | self.answerLabel.backgroundColor = [UIColor colorWithRed:254/255.0 green:194/255.0 blue:12/255.0 alpha:1.0]; 43 | self.answerLabel.textColor = [UIColor whiteColor]; 44 | self.answerLabel.numberOfLines = 0; 45 | [self.answerLabel setTextAlignment:(NSTextAlignmentCenter)]; 46 | self.answerLabel.adjustsFontSizeToFitWidth = YES; 47 | [self.view addSubview:self.answerLabel]; 48 | 49 | UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; 50 | btn.frame = CGRectMake((screenWidth - 136) / 2.0, CGRectGetMaxY(self.coverImageView.frame) + 40, 136, 41); 51 | btn.titleLabel.font = [UIFont systemFontOfSize:18]; 52 | [btn setBackgroundColor:[UIColor colorWithRed:103/255.0 green:170/255.0 blue:246/255.0 alpha:1]]; 53 | [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 54 | [btn setTitle:@"再刮一次" forState:UIControlStateNormal]; 55 | [btn addTarget:self action:@selector(againAction) forControlEvents:UIControlEventTouchUpInside]; 56 | [self.view addSubview:btn]; 57 | //103 170 246 58 | [self ottoSetScratchView]; 59 | } 60 | 61 | - (void)againAction{ 62 | [self ottoSetScratchView]; 63 | } 64 | 65 | - (void)scratchViewDone{ 66 | [self.ottoScratchView removeFromSuperview]; 67 | [self.answerLabel setHidden:NO]; 68 | } 69 | 70 | - (void)ottoSetScratchView{ 71 | [self.ottoScratchView removeFromSuperview]; 72 | [self.answerLabel setHidden:YES]; 73 | self.ottoScratchView = [[OttoScratchView alloc] initWithFrame:self.coverImageView.frame]; 74 | self.ottoScratchView.delegate = self; 75 | self.ottoScratchView.scratchLineWidth = 14; 76 | self.ottoScratchView.passCount = 9; 77 | self.aLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.coverImageView.frame.size.width, self.coverImageView.frame.size.height)]; 78 | self.aLabel.text = self.answer; 79 | self.answerLabel.text = self.answer; 80 | self.aLabel.font = [UIFont boldSystemFontOfSize:30]; 81 | self.aLabel.backgroundColor = [UIColor colorWithRed:254/255.0 green:194/255.0 blue:12/255.0 alpha:1.0]; 82 | self.aLabel.textColor = [UIColor whiteColor]; 83 | self.aLabel.numberOfLines = 0; 84 | [self.aLabel setTextAlignment:(NSTextAlignmentCenter)]; 85 | self.aLabel.adjustsFontSizeToFitWidth = YES; 86 | [self.ottoScratchView addSubview:self.aLabel]; 87 | 88 | [self.view addSubview:self.ottoScratchView]; 89 | } 90 | 91 | @end 92 | -------------------------------------------------------------------------------- /OttoScratchView/OttoScratchView/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // OttoScratchView 4 | // 5 | // Created by halo on 2019/4/4. 6 | // Copyright © 2019 otto. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OttoScratchView 2 | iOS刮刮乐的效果实现 3 | 4 | 效果如下: 5 | ![](./OttoScratchView.gif) --------------------------------------------------------------------------------