├── AFMaskView.gif ├── AFMaskView.mov ├── AFMaskView.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── Afry.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── Afry.xcuserdatad │ └── xcschemes │ ├── AFMaskView.xcscheme │ └── xcschememanagement.plist ├── AFMaskView ├── AFMaskView │ ├── AFMaskView.swift │ └── UIImage+ImageEffects │ │ ├── AFMaskView-Bridging-Header.h │ │ ├── UIImage+ImageEffects.h │ │ └── UIImage+ImageEffects.m ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ └── thanks.imageset │ │ ├── Contents.json │ │ └── u=1280033783,1095040343&fm=21&gp=0.jpg ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist └── ViewController.swift └── README.md /AFMaskView.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AfryMask/AFMaskView/bce50bcc83c0dff0886571af2baffc1e80213ebe/AFMaskView.gif -------------------------------------------------------------------------------- /AFMaskView.mov: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AfryMask/AFMaskView/bce50bcc83c0dff0886571af2baffc1e80213ebe/AFMaskView.mov -------------------------------------------------------------------------------- /AFMaskView.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | E80FB27F1C4A24CF003BF2E3 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E80FB27E1C4A24CF003BF2E3 /* AppDelegate.swift */; }; 11 | E80FB2811C4A24CF003BF2E3 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E80FB2801C4A24CF003BF2E3 /* ViewController.swift */; }; 12 | E80FB2841C4A24CF003BF2E3 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E80FB2821C4A24CF003BF2E3 /* Main.storyboard */; }; 13 | E80FB2861C4A24CF003BF2E3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E80FB2851C4A24CF003BF2E3 /* Assets.xcassets */; }; 14 | E80FB2891C4A24CF003BF2E3 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E80FB2871C4A24CF003BF2E3 /* LaunchScreen.storyboard */; }; 15 | E80FB2961C4A2525003BF2E3 /* AFMaskView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E80FB2951C4A2525003BF2E3 /* AFMaskView.swift */; }; 16 | E80FB2991C4A256C003BF2E3 /* UIImage+ImageEffects.m in Sources */ = {isa = PBXBuildFile; fileRef = E80FB2981C4A256C003BF2E3 /* UIImage+ImageEffects.m */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | E80FB27B1C4A24CF003BF2E3 /* AFMaskView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AFMaskView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 21 | E80FB27E1C4A24CF003BF2E3 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 22 | E80FB2801C4A24CF003BF2E3 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 23 | E80FB2831C4A24CF003BF2E3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 24 | E80FB2851C4A24CF003BF2E3 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 25 | E80FB2881C4A24CF003BF2E3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 26 | E80FB28A1C4A24CF003BF2E3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 27 | E80FB2921C4A2516003BF2E3 /* UIImage+ImageEffects.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+ImageEffects.h"; sourceTree = ""; }; 28 | E80FB2951C4A2525003BF2E3 /* AFMaskView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AFMaskView.swift; sourceTree = ""; }; 29 | E80FB2971C4A256B003BF2E3 /* AFMaskView-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "AFMaskView-Bridging-Header.h"; sourceTree = ""; }; 30 | E80FB2981C4A256C003BF2E3 /* UIImage+ImageEffects.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+ImageEffects.m"; sourceTree = ""; }; 31 | /* End PBXFileReference section */ 32 | 33 | /* Begin PBXFrameworksBuildPhase section */ 34 | E80FB2781C4A24CF003BF2E3 /* Frameworks */ = { 35 | isa = PBXFrameworksBuildPhase; 36 | buildActionMask = 2147483647; 37 | files = ( 38 | ); 39 | runOnlyForDeploymentPostprocessing = 0; 40 | }; 41 | /* End PBXFrameworksBuildPhase section */ 42 | 43 | /* Begin PBXGroup section */ 44 | E80FB2721C4A24CF003BF2E3 = { 45 | isa = PBXGroup; 46 | children = ( 47 | E80FB27D1C4A24CF003BF2E3 /* AFMaskView */, 48 | E80FB27C1C4A24CF003BF2E3 /* Products */, 49 | ); 50 | sourceTree = ""; 51 | }; 52 | E80FB27C1C4A24CF003BF2E3 /* Products */ = { 53 | isa = PBXGroup; 54 | children = ( 55 | E80FB27B1C4A24CF003BF2E3 /* AFMaskView.app */, 56 | ); 57 | name = Products; 58 | sourceTree = ""; 59 | }; 60 | E80FB27D1C4A24CF003BF2E3 /* AFMaskView */ = { 61 | isa = PBXGroup; 62 | children = ( 63 | E80FB2901C4A2516003BF2E3 /* AFMaskView */, 64 | E80FB27E1C4A24CF003BF2E3 /* AppDelegate.swift */, 65 | E80FB2801C4A24CF003BF2E3 /* ViewController.swift */, 66 | E80FB2821C4A24CF003BF2E3 /* Main.storyboard */, 67 | E80FB2851C4A24CF003BF2E3 /* Assets.xcassets */, 68 | E80FB2871C4A24CF003BF2E3 /* LaunchScreen.storyboard */, 69 | E80FB28A1C4A24CF003BF2E3 /* Info.plist */, 70 | ); 71 | path = AFMaskView; 72 | sourceTree = ""; 73 | }; 74 | E80FB2901C4A2516003BF2E3 /* AFMaskView */ = { 75 | isa = PBXGroup; 76 | children = ( 77 | E80FB2911C4A2516003BF2E3 /* UIImage+ImageEffects */, 78 | E80FB2951C4A2525003BF2E3 /* AFMaskView.swift */, 79 | ); 80 | path = AFMaskView; 81 | sourceTree = ""; 82 | }; 83 | E80FB2911C4A2516003BF2E3 /* UIImage+ImageEffects */ = { 84 | isa = PBXGroup; 85 | children = ( 86 | E80FB2921C4A2516003BF2E3 /* UIImage+ImageEffects.h */, 87 | E80FB2981C4A256C003BF2E3 /* UIImage+ImageEffects.m */, 88 | E80FB2971C4A256B003BF2E3 /* AFMaskView-Bridging-Header.h */, 89 | ); 90 | path = "UIImage+ImageEffects"; 91 | sourceTree = ""; 92 | }; 93 | /* End PBXGroup section */ 94 | 95 | /* Begin PBXNativeTarget section */ 96 | E80FB27A1C4A24CF003BF2E3 /* AFMaskView */ = { 97 | isa = PBXNativeTarget; 98 | buildConfigurationList = E80FB28D1C4A24CF003BF2E3 /* Build configuration list for PBXNativeTarget "AFMaskView" */; 99 | buildPhases = ( 100 | E80FB2771C4A24CF003BF2E3 /* Sources */, 101 | E80FB2781C4A24CF003BF2E3 /* Frameworks */, 102 | E80FB2791C4A24CF003BF2E3 /* Resources */, 103 | ); 104 | buildRules = ( 105 | ); 106 | dependencies = ( 107 | ); 108 | name = AFMaskView; 109 | productName = AFMaskView; 110 | productReference = E80FB27B1C4A24CF003BF2E3 /* AFMaskView.app */; 111 | productType = "com.apple.product-type.application"; 112 | }; 113 | /* End PBXNativeTarget section */ 114 | 115 | /* Begin PBXProject section */ 116 | E80FB2731C4A24CF003BF2E3 /* Project object */ = { 117 | isa = PBXProject; 118 | attributes = { 119 | LastSwiftUpdateCheck = 0720; 120 | LastUpgradeCheck = 0720; 121 | ORGANIZATIONNAME = AfryMasker; 122 | TargetAttributes = { 123 | E80FB27A1C4A24CF003BF2E3 = { 124 | CreatedOnToolsVersion = 7.2; 125 | DevelopmentTeam = MG63G9T3GS; 126 | }; 127 | }; 128 | }; 129 | buildConfigurationList = E80FB2761C4A24CF003BF2E3 /* Build configuration list for PBXProject "AFMaskView" */; 130 | compatibilityVersion = "Xcode 3.2"; 131 | developmentRegion = English; 132 | hasScannedForEncodings = 0; 133 | knownRegions = ( 134 | en, 135 | Base, 136 | ); 137 | mainGroup = E80FB2721C4A24CF003BF2E3; 138 | productRefGroup = E80FB27C1C4A24CF003BF2E3 /* Products */; 139 | projectDirPath = ""; 140 | projectRoot = ""; 141 | targets = ( 142 | E80FB27A1C4A24CF003BF2E3 /* AFMaskView */, 143 | ); 144 | }; 145 | /* End PBXProject section */ 146 | 147 | /* Begin PBXResourcesBuildPhase section */ 148 | E80FB2791C4A24CF003BF2E3 /* Resources */ = { 149 | isa = PBXResourcesBuildPhase; 150 | buildActionMask = 2147483647; 151 | files = ( 152 | E80FB2891C4A24CF003BF2E3 /* LaunchScreen.storyboard in Resources */, 153 | E80FB2861C4A24CF003BF2E3 /* Assets.xcassets in Resources */, 154 | E80FB2841C4A24CF003BF2E3 /* Main.storyboard in Resources */, 155 | ); 156 | runOnlyForDeploymentPostprocessing = 0; 157 | }; 158 | /* End PBXResourcesBuildPhase section */ 159 | 160 | /* Begin PBXSourcesBuildPhase section */ 161 | E80FB2771C4A24CF003BF2E3 /* Sources */ = { 162 | isa = PBXSourcesBuildPhase; 163 | buildActionMask = 2147483647; 164 | files = ( 165 | E80FB2991C4A256C003BF2E3 /* UIImage+ImageEffects.m in Sources */, 166 | E80FB2811C4A24CF003BF2E3 /* ViewController.swift in Sources */, 167 | E80FB2961C4A2525003BF2E3 /* AFMaskView.swift in Sources */, 168 | E80FB27F1C4A24CF003BF2E3 /* AppDelegate.swift in Sources */, 169 | ); 170 | runOnlyForDeploymentPostprocessing = 0; 171 | }; 172 | /* End PBXSourcesBuildPhase section */ 173 | 174 | /* Begin PBXVariantGroup section */ 175 | E80FB2821C4A24CF003BF2E3 /* Main.storyboard */ = { 176 | isa = PBXVariantGroup; 177 | children = ( 178 | E80FB2831C4A24CF003BF2E3 /* Base */, 179 | ); 180 | name = Main.storyboard; 181 | sourceTree = ""; 182 | }; 183 | E80FB2871C4A24CF003BF2E3 /* LaunchScreen.storyboard */ = { 184 | isa = PBXVariantGroup; 185 | children = ( 186 | E80FB2881C4A24CF003BF2E3 /* Base */, 187 | ); 188 | name = LaunchScreen.storyboard; 189 | sourceTree = ""; 190 | }; 191 | /* End PBXVariantGroup section */ 192 | 193 | /* Begin XCBuildConfiguration section */ 194 | E80FB28B1C4A24CF003BF2E3 /* Debug */ = { 195 | isa = XCBuildConfiguration; 196 | buildSettings = { 197 | ALWAYS_SEARCH_USER_PATHS = NO; 198 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 199 | CLANG_CXX_LIBRARY = "libc++"; 200 | CLANG_ENABLE_MODULES = YES; 201 | CLANG_ENABLE_OBJC_ARC = YES; 202 | CLANG_WARN_BOOL_CONVERSION = YES; 203 | CLANG_WARN_CONSTANT_CONVERSION = YES; 204 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 205 | CLANG_WARN_EMPTY_BODY = YES; 206 | CLANG_WARN_ENUM_CONVERSION = YES; 207 | CLANG_WARN_INT_CONVERSION = YES; 208 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 209 | CLANG_WARN_UNREACHABLE_CODE = YES; 210 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 211 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 212 | COPY_PHASE_STRIP = NO; 213 | DEBUG_INFORMATION_FORMAT = dwarf; 214 | ENABLE_STRICT_OBJC_MSGSEND = YES; 215 | ENABLE_TESTABILITY = YES; 216 | GCC_C_LANGUAGE_STANDARD = gnu99; 217 | GCC_DYNAMIC_NO_PIC = NO; 218 | GCC_NO_COMMON_BLOCKS = YES; 219 | GCC_OPTIMIZATION_LEVEL = 0; 220 | GCC_PREPROCESSOR_DEFINITIONS = ( 221 | "DEBUG=1", 222 | "$(inherited)", 223 | ); 224 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 225 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 226 | GCC_WARN_UNDECLARED_SELECTOR = YES; 227 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 228 | GCC_WARN_UNUSED_FUNCTION = YES; 229 | GCC_WARN_UNUSED_VARIABLE = YES; 230 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 231 | MTL_ENABLE_DEBUG_INFO = YES; 232 | ONLY_ACTIVE_ARCH = YES; 233 | SDKROOT = iphoneos; 234 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 235 | }; 236 | name = Debug; 237 | }; 238 | E80FB28C1C4A24CF003BF2E3 /* Release */ = { 239 | isa = XCBuildConfiguration; 240 | buildSettings = { 241 | ALWAYS_SEARCH_USER_PATHS = NO; 242 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 243 | CLANG_CXX_LIBRARY = "libc++"; 244 | CLANG_ENABLE_MODULES = YES; 245 | CLANG_ENABLE_OBJC_ARC = YES; 246 | CLANG_WARN_BOOL_CONVERSION = YES; 247 | CLANG_WARN_CONSTANT_CONVERSION = YES; 248 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 249 | CLANG_WARN_EMPTY_BODY = YES; 250 | CLANG_WARN_ENUM_CONVERSION = YES; 251 | CLANG_WARN_INT_CONVERSION = YES; 252 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 253 | CLANG_WARN_UNREACHABLE_CODE = YES; 254 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 255 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 256 | COPY_PHASE_STRIP = NO; 257 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 258 | ENABLE_NS_ASSERTIONS = NO; 259 | ENABLE_STRICT_OBJC_MSGSEND = YES; 260 | GCC_C_LANGUAGE_STANDARD = gnu99; 261 | GCC_NO_COMMON_BLOCKS = YES; 262 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 263 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 264 | GCC_WARN_UNDECLARED_SELECTOR = YES; 265 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 266 | GCC_WARN_UNUSED_FUNCTION = YES; 267 | GCC_WARN_UNUSED_VARIABLE = YES; 268 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 269 | MTL_ENABLE_DEBUG_INFO = NO; 270 | SDKROOT = iphoneos; 271 | VALIDATE_PRODUCT = YES; 272 | }; 273 | name = Release; 274 | }; 275 | E80FB28E1C4A24CF003BF2E3 /* Debug */ = { 276 | isa = XCBuildConfiguration; 277 | buildSettings = { 278 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 279 | CLANG_ENABLE_MODULES = YES; 280 | INFOPLIST_FILE = AFMaskView/Info.plist; 281 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 282 | PRODUCT_BUNDLE_IDENTIFIER = com.Afry.AFMaskView; 283 | PRODUCT_NAME = "$(TARGET_NAME)"; 284 | SWIFT_OBJC_BRIDGING_HEADER = "AFMaskView/AFMaskView/UIImage+ImageEffects/AFMaskView-Bridging-Header.h"; 285 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 286 | }; 287 | name = Debug; 288 | }; 289 | E80FB28F1C4A24CF003BF2E3 /* Release */ = { 290 | isa = XCBuildConfiguration; 291 | buildSettings = { 292 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 293 | CLANG_ENABLE_MODULES = YES; 294 | INFOPLIST_FILE = AFMaskView/Info.plist; 295 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 296 | PRODUCT_BUNDLE_IDENTIFIER = com.Afry.AFMaskView; 297 | PRODUCT_NAME = "$(TARGET_NAME)"; 298 | SWIFT_OBJC_BRIDGING_HEADER = "AFMaskView/AFMaskView/UIImage+ImageEffects/AFMaskView-Bridging-Header.h"; 299 | }; 300 | name = Release; 301 | }; 302 | /* End XCBuildConfiguration section */ 303 | 304 | /* Begin XCConfigurationList section */ 305 | E80FB2761C4A24CF003BF2E3 /* Build configuration list for PBXProject "AFMaskView" */ = { 306 | isa = XCConfigurationList; 307 | buildConfigurations = ( 308 | E80FB28B1C4A24CF003BF2E3 /* Debug */, 309 | E80FB28C1C4A24CF003BF2E3 /* Release */, 310 | ); 311 | defaultConfigurationIsVisible = 0; 312 | defaultConfigurationName = Release; 313 | }; 314 | E80FB28D1C4A24CF003BF2E3 /* Build configuration list for PBXNativeTarget "AFMaskView" */ = { 315 | isa = XCConfigurationList; 316 | buildConfigurations = ( 317 | E80FB28E1C4A24CF003BF2E3 /* Debug */, 318 | E80FB28F1C4A24CF003BF2E3 /* Release */, 319 | ); 320 | defaultConfigurationIsVisible = 0; 321 | }; 322 | /* End XCConfigurationList section */ 323 | }; 324 | rootObject = E80FB2731C4A24CF003BF2E3 /* Project object */; 325 | } 326 | -------------------------------------------------------------------------------- /AFMaskView.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /AFMaskView.xcodeproj/project.xcworkspace/xcuserdata/Afry.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AfryMask/AFMaskView/bce50bcc83c0dff0886571af2baffc1e80213ebe/AFMaskView.xcodeproj/project.xcworkspace/xcuserdata/Afry.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /AFMaskView.xcodeproj/xcuserdata/Afry.xcuserdatad/xcschemes/AFMaskView.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /AFMaskView.xcodeproj/xcuserdata/Afry.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | AFMaskView.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | E80FB27A1C4A24CF003BF2E3 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /AFMaskView/AFMaskView/AFMaskView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AFMaskView.swift 3 | // AFMaskView 4 | // 5 | // Created by Afry on 16/1/16. 6 | // Copyright © 2016年 AfryMasker. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | // 向遮罩view传入的的图片 12 | var dynamicMaskViewColor: UIColor? 13 | // 目标点的数组 14 | var targetPoints: [CGPoint]? 15 | // 目标点是否已被扫过的数组 16 | var targetPointMarks: [Bool]? 17 | 18 | class AFView: UIView { 19 | 20 | 21 | /** 22 | 禁用原生init 23 | */ 24 | private override init(frame: CGRect) { 25 | super.init(frame: frame) 26 | } 27 | 28 | 29 | /** 30 | 初始化方法 31 | */ 32 | init(frame: CGRect, imageName: String, points: [CGPoint]) { 33 | super.init(frame: frame) 34 | 35 | // 初始化 36 | targetPoints = points 37 | targetPointMarks = [Bool]() 38 | for _ in targetPoints! { 39 | targetPointMarks!.append(false) 40 | } 41 | 42 | // 背景view,缩放 43 | let image = UIImage(named: imageName) 44 | UIGraphicsBeginImageContext(frame.size) 45 | image!.drawInRect(self.bounds) 46 | let resizeImage = UIGraphicsGetImageFromCurrentImageContext() 47 | UIGraphicsEndImageContext() 48 | 49 | backgroundColor = UIColor(patternImage: resizeImage) 50 | 51 | // 初始MaskView 52 | dynamicMaskView = AFMaskView(frame: self.bounds) 53 | dynamicMaskView!.backgroundColor = UIColor.clearColor() 54 | addSubview(dynamicMaskView!) 55 | dynamicMaskViewColor = UIColor(patternImage: resizeImage.applyLightEffect()) 56 | 57 | NSNotificationCenter.defaultCenter().addObserver(self, selector:"finishDrag", name: "finishDrag", object: nil) 58 | } 59 | 60 | 61 | /** 62 | 重置dynamicMaskView 63 | */ 64 | func finishDrag() { 65 | 66 | // 清空所有路径 67 | self.dynamicMaskView!.path = UIBezierPath() 68 | self.dynamicMaskView!.paths = [UIBezierPath]() 69 | 70 | targetPointMarks = [Bool]() 71 | for _ in targetPoints! { 72 | targetPointMarks!.append(false) 73 | } 74 | 75 | self.dynamicMaskView!.setNeedsDisplay() 76 | 77 | } 78 | 79 | var dynamicMaskView: AFMaskView? 80 | 81 | required init?(coder aDecoder: NSCoder) {fatalError("init(coder:) has not been implemented")} 82 | 83 | 84 | } 85 | 86 | /** 87 | 遮罩View 88 | */ 89 | class AFMaskView: UIView { 90 | 91 | // 当前点,线,线s 92 | var p: CGPoint = CGPointZero 93 | var path: UIBezierPath? 94 | var paths: [UIBezierPath] = [UIBezierPath]() 95 | 96 | 97 | override func drawRect(rect: CGRect) { 98 | 99 | let ctx = UIGraphicsGetCurrentContext() 100 | 101 | // 毛玻璃图片绘制 102 | CGContextSetFillColorWithColor(ctx, dynamicMaskViewColor!.CGColor) 103 | CGContextAddRect(ctx, self.frame) 104 | CGContextFillPath(ctx) 105 | 106 | 107 | // 文字绘制 108 | CGContextSetBlendMode(ctx, CGBlendMode.Normal); 109 | let str = "试试手气吧" as NSString 110 | str.drawInRect(CGRectMake(self.bounds.width/2-50, self.bounds.height/2+40,100,30) , withAttributes: [NSFontAttributeName: UIFont.systemFontOfSize(20)]) 111 | 112 | 113 | // 当前线条和历史线条绘制 114 | CGContextSetBlendMode(ctx, CGBlendMode.Clear); 115 | 116 | if p != CGPointZero { 117 | path!.lineJoinStyle = .Round 118 | path!.lineCapStyle = .Round 119 | path!.lineWidth = 20; 120 | 121 | path!.stroke() 122 | } 123 | 124 | if paths.count != 0 { 125 | for oldpath in paths { 126 | 127 | oldpath.lineJoinStyle = .Round 128 | oldpath.lineCapStyle = .Round 129 | oldpath.lineWidth = 20; 130 | 131 | oldpath.stroke() 132 | } 133 | } 134 | 135 | // // 设置画线模式 136 | // CGContextSetBlendMode(ctx, CGBlendMode.Normal); 137 | // 138 | // // 显示需要经过的点(可省略) 139 | // for point in targetPoints!{ 140 | // 141 | // let reachPath = UIBezierPath() 142 | // reachPath.moveToPoint(point) 143 | // reachPath.addLineToPoint(CGPointMake(point.x+10, point.y)) 144 | // reachPath.addLineToPoint(CGPointMake(point.x+10, point.y+10)) 145 | // reachPath.addLineToPoint(CGPointMake(point.x, point.y+10)) 146 | // reachPath.closePath() 147 | // UIColor.redColor().setFill() 148 | // reachPath.fill() 149 | // 150 | // } 151 | 152 | 153 | } 154 | 155 | override func touchesBegan(touches: Set, withEvent event: UIEvent?) { 156 | 157 | let touch = touches.first 158 | p = touch!.locationInView(self) 159 | 160 | path = UIBezierPath() 161 | path!.moveToPoint(p) 162 | path!.addLineToPoint(p) 163 | self.setNeedsDisplay() 164 | 165 | // 判断是否到达某点 166 | for (idx, point) in targetPoints!.enumerate(){ 167 | if abs(point.x - p.x)<20 && abs(point.y - p.y)<20 && !targetPointMarks![idx]{ 168 | targetPointMarks![idx] = true 169 | } 170 | } 171 | } 172 | 173 | override func touchesMoved(touches: Set, withEvent event: UIEvent?) { 174 | 175 | let touch = touches.first 176 | p = touch!.locationInView(self) 177 | 178 | path?.addLineToPoint(p) 179 | self.setNeedsDisplay() 180 | 181 | // 判断是否到达某点 182 | for (idx, point) in targetPoints!.enumerate(){ 183 | // 减少计算量,但是降低精确度的做法 184 | if abs(point.x - p.x)<20 && abs(point.y - p.y)<20 && !targetPointMarks![idx]{ 185 | targetPointMarks![idx] = true 186 | } 187 | } 188 | 189 | } 190 | 191 | override func touchesEnded(touches: Set, withEvent event: UIEvent?) { 192 | 193 | let touch = touches.first 194 | p = touch!.locationInView(self) 195 | 196 | path?.addLineToPoint(p) 197 | paths.append(path!) 198 | 199 | // 判断是否完成寻点 200 | self.setNeedsDisplay() 201 | 202 | finishDrag() 203 | } 204 | 205 | 206 | // 完成寻点 207 | func finishDrag(){ 208 | 209 | for (idx, _) in targetPoints!.enumerate(){ 210 | if !targetPointMarks![idx]{ 211 | return 212 | } 213 | } 214 | 215 | let alert = UIAlertController(title: "Message", message: "你永远都抽不到,略略略", preferredStyle: .Alert) 216 | alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: { (_) -> Void in 217 | 218 | NSNotificationCenter.defaultCenter().postNotificationName("finishDrag", object: nil, userInfo: nil) 219 | })) 220 | window!.rootViewController!.presentViewController(alert, animated: true) { () -> Void in 221 | 222 | } 223 | 224 | } 225 | 226 | } -------------------------------------------------------------------------------- /AFMaskView/AFMaskView/UIImage+ImageEffects/AFMaskView-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | #import "UIImage+ImageEffects.h" -------------------------------------------------------------------------------- /AFMaskView/AFMaskView/UIImage+ImageEffects/UIImage+ImageEffects.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: UIImage+ImageEffects.h 3 | Abstract: This is a category of UIImage that adds methods to apply blur and tint effects to an image. This is the code you’ll want to look out to find out how to use vImage to efficiently calculate a blur. 4 | Version: 1.0 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2013 Apple Inc. All Rights Reserved. 45 | 46 | 47 | Copyright © 2013 Apple Inc. All rights reserved. 48 | WWDC 2013 License 49 | 50 | NOTE: This Apple Software was supplied by Apple as part of a WWDC 2013 51 | Session. Please refer to the applicable WWDC 2013 Session for further 52 | information. 53 | 54 | IMPORTANT: This Apple software is supplied to you by Apple Inc. 55 | ("Apple") in consideration of your agreement to the following terms, and 56 | your use, installation, modification or redistribution of this Apple 57 | software constitutes acceptance of these terms. If you do not agree with 58 | these terms, please do not use, install, modify or redistribute this 59 | Apple software. 60 | 61 | In consideration of your agreement to abide by the following terms, and 62 | subject to these terms, Apple grants you a non-exclusive license, under 63 | Apple's copyrights in this original Apple software (the "Apple 64 | Software"), to use, reproduce, modify and redistribute the Apple 65 | Software, with or without modifications, in source and/or binary forms; 66 | provided that if you redistribute the Apple Software in its entirety and 67 | without modifications, you must retain this notice and the following 68 | text and disclaimers in all such redistributions of the Apple Software. 69 | Neither the name, trademarks, service marks or logos of Apple Inc. may 70 | be used to endorse or promote products derived from the Apple Software 71 | without specific prior written permission from Apple. Except as 72 | expressly stated in this notice, no other rights or licenses, express or 73 | implied, are granted by Apple herein, including but not limited to any 74 | patent rights that may be infringed by your derivative works or by other 75 | works in which the Apple Software may be incorporated. 76 | 77 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES 78 | NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE 79 | IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR 80 | A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 81 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 82 | 83 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 84 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 85 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 86 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 87 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 88 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 89 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 90 | POSSIBILITY OF SUCH DAMAGE. 91 | 92 | EA1002 93 | 5/3/2013 94 | */ 95 | 96 | @import UIKit; 97 | 98 | @interface UIImage (ImageEffects) 99 | 100 | - (UIImage *)applyLightEffect; 101 | - (UIImage *)applyExtraLightEffect; 102 | - (UIImage *)applyDarkEffect; 103 | - (UIImage *)applyTintEffectWithColor:(UIColor *)tintColor; 104 | 105 | - (UIImage *)applyBlurWithRadius:(CGFloat)blurRadius tintColor:(UIColor *)tintColor saturationDeltaFactor:(CGFloat)saturationDeltaFactor maskImage:(UIImage *)maskImage; 106 | 107 | @end 108 | -------------------------------------------------------------------------------- /AFMaskView/AFMaskView/UIImage+ImageEffects/UIImage+ImageEffects.m: -------------------------------------------------------------------------------- 1 | /* 2 | File: UIImage+ImageEffects.m 3 | Abstract: This is a category of UIImage that adds methods to apply blur and tint effects to an image. This is the code you’ll want to look out to find out how to use vImage to efficiently calculate a blur. 4 | Version: 1.0 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2013 Apple Inc. All Rights Reserved. 45 | 46 | 47 | Copyright © 2013 Apple Inc. All rights reserved. 48 | WWDC 2013 License 49 | 50 | NOTE: This Apple Software was supplied by Apple as part of a WWDC 2013 51 | Session. Please refer to the applicable WWDC 2013 Session for further 52 | information. 53 | 54 | IMPORTANT: This Apple software is supplied to you by Apple Inc. 55 | ("Apple") in consideration of your agreement to the following terms, and 56 | your use, installation, modification or redistribution of this Apple 57 | software constitutes acceptance of these terms. If you do not agree with 58 | these terms, please do not use, install, modify or redistribute this 59 | Apple software. 60 | 61 | In consideration of your agreement to abide by the following terms, and 62 | subject to these terms, Apple grants you a non-exclusive license, under 63 | Apple's copyrights in this original Apple software (the "Apple 64 | Software"), to use, reproduce, modify and redistribute the Apple 65 | Software, with or without modifications, in source and/or binary forms; 66 | provided that if you redistribute the Apple Software in its entirety and 67 | without modifications, you must retain this notice and the following 68 | text and disclaimers in all such redistributions of the Apple Software. 69 | Neither the name, trademarks, service marks or logos of Apple Inc. may 70 | be used to endorse or promote products derived from the Apple Software 71 | without specific prior written permission from Apple. Except as 72 | expressly stated in this notice, no other rights or licenses, express or 73 | implied, are granted by Apple herein, including but not limited to any 74 | patent rights that may be infringed by your derivative works or by other 75 | works in which the Apple Software may be incorporated. 76 | 77 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES 78 | NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE 79 | IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR 80 | A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 81 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 82 | 83 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 84 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 85 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 86 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 87 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 88 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 89 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 90 | POSSIBILITY OF SUCH DAMAGE. 91 | 92 | EA1002 93 | 5/3/2013 94 | */ 95 | 96 | #import "UIImage+ImageEffects.h" 97 | 98 | @import Accelerate; 99 | #import 100 | 101 | 102 | @implementation UIImage (ImageEffects) 103 | 104 | 105 | - (UIImage *)applyLightEffect 106 | { 107 | UIColor *tintColor = [UIColor colorWithWhite:1.0 alpha:0.3]; 108 | return [self applyBlurWithRadius:30 tintColor:tintColor saturationDeltaFactor:1.8 maskImage:nil]; 109 | } 110 | 111 | 112 | - (UIImage *)applyExtraLightEffect 113 | { 114 | UIColor *tintColor = [UIColor colorWithWhite:0.97 alpha:0.82]; 115 | return [self applyBlurWithRadius:20 tintColor:tintColor saturationDeltaFactor:1.8 maskImage:nil]; 116 | } 117 | 118 | 119 | - (UIImage *)applyDarkEffect 120 | { 121 | UIColor *tintColor = [UIColor colorWithWhite:0.11 alpha:0.73]; 122 | return [self applyBlurWithRadius:20 tintColor:tintColor saturationDeltaFactor:1.8 maskImage:nil]; 123 | } 124 | 125 | 126 | - (UIImage *)applyTintEffectWithColor:(UIColor *)tintColor 127 | { 128 | const CGFloat EffectColorAlpha = 0.6; 129 | UIColor *effectColor = tintColor; 130 | int componentCount = CGColorGetNumberOfComponents(tintColor.CGColor); 131 | if (componentCount == 2) { 132 | CGFloat b; 133 | if ([tintColor getWhite:&b alpha:NULL]) { 134 | effectColor = [UIColor colorWithWhite:b alpha:EffectColorAlpha]; 135 | } 136 | } 137 | else { 138 | CGFloat r, g, b; 139 | if ([tintColor getRed:&r green:&g blue:&b alpha:NULL]) { 140 | effectColor = [UIColor colorWithRed:r green:g blue:b alpha:EffectColorAlpha]; 141 | } 142 | } 143 | return [self applyBlurWithRadius:10 tintColor:effectColor saturationDeltaFactor:-1.0 maskImage:nil]; 144 | } 145 | 146 | 147 | - (UIImage *)applyBlurWithRadius:(CGFloat)blurRadius tintColor:(UIColor *)tintColor saturationDeltaFactor:(CGFloat)saturationDeltaFactor maskImage:(UIImage *)maskImage 148 | { 149 | // Check pre-conditions. 150 | if (self.size.width < 1 || self.size.height < 1) { 151 | NSLog (@"*** error: invalid size: (%.2f x %.2f). Both dimensions must be >= 1: %@", self.size.width, self.size.height, self); 152 | return nil; 153 | } 154 | if (!self.CGImage) { 155 | NSLog (@"*** error: image must be backed by a CGImage: %@", self); 156 | return nil; 157 | } 158 | if (maskImage && !maskImage.CGImage) { 159 | NSLog (@"*** error: maskImage must be backed by a CGImage: %@", maskImage); 160 | return nil; 161 | } 162 | 163 | CGRect imageRect = { CGPointZero, self.size }; 164 | UIImage *effectImage = self; 165 | 166 | BOOL hasBlur = blurRadius > __FLT_EPSILON__; 167 | BOOL hasSaturationChange = fabs(saturationDeltaFactor - 1.) > __FLT_EPSILON__; 168 | 169 | if (hasBlur || hasSaturationChange) { 170 | UIGraphicsBeginImageContextWithOptions(self.size, NO, [[UIScreen mainScreen] scale]); 171 | CGContextRef effectInContext = UIGraphicsGetCurrentContext(); 172 | CGContextScaleCTM(effectInContext, 1.0, -1.0); 173 | CGContextTranslateCTM(effectInContext, 0, -self.size.height); 174 | CGContextDrawImage(effectInContext, imageRect, self.CGImage); 175 | 176 | vImage_Buffer effectInBuffer; 177 | effectInBuffer.data = CGBitmapContextGetData(effectInContext); 178 | effectInBuffer.width = CGBitmapContextGetWidth(effectInContext); 179 | effectInBuffer.height = CGBitmapContextGetHeight(effectInContext); 180 | effectInBuffer.rowBytes = CGBitmapContextGetBytesPerRow(effectInContext); 181 | 182 | UIGraphicsBeginImageContextWithOptions(self.size, NO, [[UIScreen mainScreen] scale]); 183 | CGContextRef effectOutContext = UIGraphicsGetCurrentContext(); 184 | vImage_Buffer effectOutBuffer; 185 | effectOutBuffer.data = CGBitmapContextGetData(effectOutContext); 186 | effectOutBuffer.width = CGBitmapContextGetWidth(effectOutContext); 187 | effectOutBuffer.height = CGBitmapContextGetHeight(effectOutContext); 188 | effectOutBuffer.rowBytes = CGBitmapContextGetBytesPerRow(effectOutContext); 189 | 190 | if (hasBlur) { 191 | // A description of how to compute the box kernel width from the Gaussian 192 | // radius (aka standard deviation) appears in the SVG spec: 193 | // http://www.w3.org/TR/SVG/filters.html#feGaussianBlurElement 194 | // 195 | // For larger values of 's' (s >= 2.0), an approximation can be used: Three 196 | // successive box-blurs build a piece-wise quadratic convolution kernel, which 197 | // approximates the Gaussian kernel to within roughly 3%. 198 | // 199 | // let d = floor(s * 3*sqrt(2*pi)/4 + 0.5) 200 | // 201 | // ... if d is odd, use three box-blurs of size 'd', centered on the output pixel. 202 | // 203 | CGFloat inputRadius = blurRadius * [[UIScreen mainScreen] scale]; 204 | NSUInteger radius = floor(inputRadius * 3. * sqrt(2 * M_PI) / 4 + 0.5); 205 | if (radius % 2 != 1) { 206 | radius += 1; // force radius to be odd so that the three box-blur methodology works. 207 | } 208 | vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, NULL, 0, 0, radius, radius, 0, kvImageEdgeExtend); 209 | vImageBoxConvolve_ARGB8888(&effectOutBuffer, &effectInBuffer, NULL, 0, 0, radius, radius, 0, kvImageEdgeExtend); 210 | vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, NULL, 0, 0, radius, radius, 0, kvImageEdgeExtend); 211 | } 212 | BOOL effectImageBuffersAreSwapped = NO; 213 | if (hasSaturationChange) { 214 | CGFloat s = saturationDeltaFactor; 215 | CGFloat floatingPointSaturationMatrix[] = { 216 | 0.0722 + 0.9278 * s, 0.0722 - 0.0722 * s, 0.0722 - 0.0722 * s, 0, 217 | 0.7152 - 0.7152 * s, 0.7152 + 0.2848 * s, 0.7152 - 0.7152 * s, 0, 218 | 0.2126 - 0.2126 * s, 0.2126 - 0.2126 * s, 0.2126 + 0.7873 * s, 0, 219 | 0, 0, 0, 1, 220 | }; 221 | const int32_t divisor = 256; 222 | NSUInteger matrixSize = sizeof(floatingPointSaturationMatrix)/sizeof(floatingPointSaturationMatrix[0]); 223 | int16_t saturationMatrix[matrixSize]; 224 | for (NSUInteger i = 0; i < matrixSize; ++i) { 225 | saturationMatrix[i] = (int16_t)roundf(floatingPointSaturationMatrix[i] * divisor); 226 | } 227 | if (hasBlur) { 228 | vImageMatrixMultiply_ARGB8888(&effectOutBuffer, &effectInBuffer, saturationMatrix, divisor, NULL, NULL, kvImageNoFlags); 229 | effectImageBuffersAreSwapped = YES; 230 | } 231 | else { 232 | vImageMatrixMultiply_ARGB8888(&effectInBuffer, &effectOutBuffer, saturationMatrix, divisor, NULL, NULL, kvImageNoFlags); 233 | } 234 | } 235 | if (!effectImageBuffersAreSwapped) 236 | effectImage = UIGraphicsGetImageFromCurrentImageContext(); 237 | UIGraphicsEndImageContext(); 238 | 239 | if (effectImageBuffersAreSwapped) 240 | effectImage = UIGraphicsGetImageFromCurrentImageContext(); 241 | UIGraphicsEndImageContext(); 242 | } 243 | 244 | // Set up output context. 245 | UIGraphicsBeginImageContextWithOptions(self.size, NO, [[UIScreen mainScreen] scale]); 246 | CGContextRef outputContext = UIGraphicsGetCurrentContext(); 247 | CGContextScaleCTM(outputContext, 1.0, -1.0); 248 | CGContextTranslateCTM(outputContext, 0, -self.size.height); 249 | 250 | // Draw base image. 251 | CGContextDrawImage(outputContext, imageRect, self.CGImage); 252 | 253 | // Draw effect image. 254 | if (hasBlur) { 255 | CGContextSaveGState(outputContext); 256 | if (maskImage) { 257 | CGContextClipToMask(outputContext, imageRect, maskImage.CGImage); 258 | } 259 | CGContextDrawImage(outputContext, imageRect, effectImage.CGImage); 260 | CGContextRestoreGState(outputContext); 261 | } 262 | 263 | // Add in color tint. 264 | if (tintColor) { 265 | CGContextSaveGState(outputContext); 266 | CGContextSetFillColorWithColor(outputContext, tintColor.CGColor); 267 | CGContextFillRect(outputContext, imageRect); 268 | CGContextRestoreGState(outputContext); 269 | } 270 | 271 | // Output image is ready. 272 | UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext(); 273 | UIGraphicsEndImageContext(); 274 | 275 | return outputImage; 276 | } 277 | 278 | 279 | @end 280 | -------------------------------------------------------------------------------- /AFMaskView/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // AFMaskView 4 | // 5 | // Created by Afry on 16/1/16. 6 | // Copyright © 2016年 AfryMasker. 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: [NSObject: AnyObject]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(application: UIApplication) { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /AFMaskView/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /AFMaskView/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /AFMaskView/Assets.xcassets/thanks.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "u=1280033783,1095040343&fm=21&gp=0.jpg", 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 | } -------------------------------------------------------------------------------- /AFMaskView/Assets.xcassets/thanks.imageset/u=1280033783,1095040343&fm=21&gp=0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AfryMask/AFMaskView/bce50bcc83c0dff0886571af2baffc1e80213ebe/AFMaskView/Assets.xcassets/thanks.imageset/u=1280033783,1095040343&fm=21&gp=0.jpg -------------------------------------------------------------------------------- /AFMaskView/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 | -------------------------------------------------------------------------------- /AFMaskView/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /AFMaskView/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | NSAppTransportSecurity 26 | 27 | NSAllowsArbitraryLoads 28 | 29 | 30 | UILaunchStoryboardName 31 | LaunchScreen 32 | UIMainStoryboardFile 33 | Main 34 | UIRequiredDeviceCapabilities 35 | 36 | armv7 37 | 38 | UISupportedInterfaceOrientations 39 | 40 | UIInterfaceOrientationPortrait 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /AFMaskView/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // AFMaskView 4 | // 5 | // Created by Afry on 16/1/16. 6 | // Copyright © 2016年 AfryMasker. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | 16 | // 设置基本信息 17 | let screenSize = UIScreen.mainScreen().bounds.size 18 | let maskViewFrame = CGRectMake(0, screenSize.height/2 - 100, screenSize.width, 200) 19 | let maskViewImageName = "thanks" 20 | let targetPoints = [CGPointMake(94, 90), CGPointMake(160, 90), CGPointMake(220, 90), CGPointMake(280, 90)] 21 | 22 | // 初始化,并添加到view中 23 | let maskView = AFView(frame: maskViewFrame, imageName:maskViewImageName, points:targetPoints) 24 | self.view.addSubview(maskView) 25 | 26 | } 27 | 28 | 29 | } 30 | 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AFMaskView 2 | 仿刮刮卡效果(上层使用了毛玻璃效果) 3 | 4 | 5 | ![](https://github.com/AfryMask/AFMaskView/blob/master/AFMaskView.gif) 6 | --------------------------------------------------------------------------------