├── 1.png ├── 2.png ├── AliPayDemo.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── AliPayDemo.xccheckout │ └── xcuserdata │ │ └── Paul.xcuserdatad │ │ └── WorkspaceSettings.xcsettings └── xcuserdata │ └── Paul.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── AliPayDemo.xcscheme │ └── xcschememanagement.plist ├── AliPayDemo ├── AliSDK │ ├── AliPayItem.h │ ├── AliPayItem.m │ ├── AliPayViews.h │ ├── AliPayViews.m │ ├── AlipaySubItem.h │ ├── AlipaySubItem.m │ ├── Header.h │ ├── KeychainData.h │ ├── KeychainData.m │ ├── KeychainItemWrapper.h │ └── KeychainItemWrapper.m ├── AppDelegate.h ├── AppDelegate.m ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard ├── Images.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Info.plist ├── MBProgressHUD.h ├── MBProgressHUD.m ├── SetpasswordViewController.h ├── SetpasswordViewController.m ├── ViewController.h ├── ViewController.m └── main.m ├── AliPayDemoTests ├── AliPayDemoTests.m └── Info.plist ├── PGGPic.gif └── README.md /1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guoxianlongw/PGGestureViews/9b55b382ab89e0e8dacf7aca90a9883976b88f65/1.png -------------------------------------------------------------------------------- /2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guoxianlongw/PGGestureViews/9b55b382ab89e0e8dacf7aca90a9883976b88f65/2.png -------------------------------------------------------------------------------- /AliPayDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | DA576F991B5C96BF0010BD97 /* MBProgressHUD.m in Sources */ = {isa = PBXBuildFile; fileRef = DA576F981B5C96BF0010BD97 /* MBProgressHUD.m */; }; 11 | DA6CD42D1B4F712B00C0B22E /* AliPayItem.m in Sources */ = {isa = PBXBuildFile; fileRef = DA6CD42C1B4F712B00C0B22E /* AliPayItem.m */; }; 12 | DAB6A6561B550CA90080C483 /* AlipaySubItem.m in Sources */ = {isa = PBXBuildFile; fileRef = DAB6A6551B550CA90080C483 /* AlipaySubItem.m */; }; 13 | DAB724861B4D11AD00E78655 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = DAB724851B4D11AD00E78655 /* main.m */; }; 14 | DAB724891B4D11AD00E78655 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = DAB724881B4D11AD00E78655 /* AppDelegate.m */; }; 15 | DAB7248C1B4D11AD00E78655 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DAB7248B1B4D11AD00E78655 /* ViewController.m */; }; 16 | DAB7248F1B4D11AD00E78655 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DAB7248D1B4D11AD00E78655 /* Main.storyboard */; }; 17 | DAB724911B4D11AD00E78655 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DAB724901B4D11AD00E78655 /* Images.xcassets */; }; 18 | DAB724941B4D11AD00E78655 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = DAB724921B4D11AD00E78655 /* LaunchScreen.xib */; }; 19 | DAB724A01B4D11AD00E78655 /* AliPayDemoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DAB7249F1B4D11AD00E78655 /* AliPayDemoTests.m */; }; 20 | DAB784021B565CB100DBB327 /* KeychainItemWrapper.m in Sources */ = {isa = PBXBuildFile; fileRef = DAB783FF1B565CB100DBB327 /* KeychainItemWrapper.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; 21 | DAB784061B565CD700DBB327 /* KeychainData.m in Sources */ = {isa = PBXBuildFile; fileRef = DAB784051B565CD700DBB327 /* KeychainData.m */; }; 22 | DAB784091B56714000DBB327 /* SetpasswordViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DAB784081B56714000DBB327 /* SetpasswordViewController.m */; }; 23 | DABA83581B4E7A310039A83D /* AliPayViews.m in Sources */ = {isa = PBXBuildFile; fileRef = DABA83571B4E7A310039A83D /* AliPayViews.m */; }; 24 | /* End PBXBuildFile section */ 25 | 26 | /* Begin PBXContainerItemProxy section */ 27 | DAB7249A1B4D11AD00E78655 /* PBXContainerItemProxy */ = { 28 | isa = PBXContainerItemProxy; 29 | containerPortal = DAB724781B4D11AD00E78655 /* Project object */; 30 | proxyType = 1; 31 | remoteGlobalIDString = DAB7247F1B4D11AD00E78655; 32 | remoteInfo = AliPayDemo; 33 | }; 34 | /* End PBXContainerItemProxy section */ 35 | 36 | /* Begin PBXFileReference section */ 37 | DA576F971B5C96BF0010BD97 /* MBProgressHUD.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MBProgressHUD.h; sourceTree = ""; }; 38 | DA576F981B5C96BF0010BD97 /* MBProgressHUD.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MBProgressHUD.m; sourceTree = ""; }; 39 | DA6CD42B1B4F712B00C0B22E /* AliPayItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AliPayItem.h; sourceTree = ""; }; 40 | DA6CD42C1B4F712B00C0B22E /* AliPayItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AliPayItem.m; sourceTree = ""; }; 41 | DA6CD42E1B4F768C00C0B22E /* Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Header.h; sourceTree = ""; }; 42 | DAB6A6541B550CA90080C483 /* AlipaySubItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AlipaySubItem.h; sourceTree = ""; }; 43 | DAB6A6551B550CA90080C483 /* AlipaySubItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AlipaySubItem.m; sourceTree = ""; }; 44 | DAB724801B4D11AD00E78655 /* AliPayDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AliPayDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 45 | DAB724841B4D11AD00E78655 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 46 | DAB724851B4D11AD00E78655 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 47 | DAB724871B4D11AD00E78655 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 48 | DAB724881B4D11AD00E78655 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 49 | DAB7248A1B4D11AD00E78655 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 50 | DAB7248B1B4D11AD00E78655 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 51 | DAB7248E1B4D11AD00E78655 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 52 | DAB724901B4D11AD00E78655 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 53 | DAB724931B4D11AD00E78655 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 54 | DAB724991B4D11AD00E78655 /* AliPayDemoTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AliPayDemoTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 55 | DAB7249E1B4D11AD00E78655 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 56 | DAB7249F1B4D11AD00E78655 /* AliPayDemoTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AliPayDemoTests.m; sourceTree = ""; }; 57 | DAB783FE1B565CB100DBB327 /* KeychainItemWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KeychainItemWrapper.h; sourceTree = ""; }; 58 | DAB783FF1B565CB100DBB327 /* KeychainItemWrapper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KeychainItemWrapper.m; sourceTree = ""; }; 59 | DAB784041B565CD700DBB327 /* KeychainData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KeychainData.h; sourceTree = ""; }; 60 | DAB784051B565CD700DBB327 /* KeychainData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KeychainData.m; sourceTree = ""; }; 61 | DAB784071B56714000DBB327 /* SetpasswordViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SetpasswordViewController.h; sourceTree = ""; }; 62 | DAB784081B56714000DBB327 /* SetpasswordViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SetpasswordViewController.m; sourceTree = ""; }; 63 | DABA83561B4E7A310039A83D /* AliPayViews.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AliPayViews.h; sourceTree = ""; }; 64 | DABA83571B4E7A310039A83D /* AliPayViews.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AliPayViews.m; sourceTree = ""; }; 65 | /* End PBXFileReference section */ 66 | 67 | /* Begin PBXFrameworksBuildPhase section */ 68 | DAB7247D1B4D11AD00E78655 /* Frameworks */ = { 69 | isa = PBXFrameworksBuildPhase; 70 | buildActionMask = 2147483647; 71 | files = ( 72 | ); 73 | runOnlyForDeploymentPostprocessing = 0; 74 | }; 75 | DAB724961B4D11AD00E78655 /* Frameworks */ = { 76 | isa = PBXFrameworksBuildPhase; 77 | buildActionMask = 2147483647; 78 | files = ( 79 | ); 80 | runOnlyForDeploymentPostprocessing = 0; 81 | }; 82 | /* End PBXFrameworksBuildPhase section */ 83 | 84 | /* Begin PBXGroup section */ 85 | DA6CD42A1B4F640900C0B22E /* AliSDK */ = { 86 | isa = PBXGroup; 87 | children = ( 88 | DABA83561B4E7A310039A83D /* AliPayViews.h */, 89 | DABA83571B4E7A310039A83D /* AliPayViews.m */, 90 | DA6CD42B1B4F712B00C0B22E /* AliPayItem.h */, 91 | DA6CD42C1B4F712B00C0B22E /* AliPayItem.m */, 92 | DAB6A6541B550CA90080C483 /* AlipaySubItem.h */, 93 | DAB6A6551B550CA90080C483 /* AlipaySubItem.m */, 94 | DAB783FE1B565CB100DBB327 /* KeychainItemWrapper.h */, 95 | DAB783FF1B565CB100DBB327 /* KeychainItemWrapper.m */, 96 | DAB784041B565CD700DBB327 /* KeychainData.h */, 97 | DAB784051B565CD700DBB327 /* KeychainData.m */, 98 | DA6CD42E1B4F768C00C0B22E /* Header.h */, 99 | ); 100 | path = AliSDK; 101 | sourceTree = ""; 102 | }; 103 | DAB724771B4D11AD00E78655 = { 104 | isa = PBXGroup; 105 | children = ( 106 | DAB724821B4D11AD00E78655 /* AliPayDemo */, 107 | DAB7249C1B4D11AD00E78655 /* AliPayDemoTests */, 108 | DAB724811B4D11AD00E78655 /* Products */, 109 | ); 110 | sourceTree = ""; 111 | }; 112 | DAB724811B4D11AD00E78655 /* Products */ = { 113 | isa = PBXGroup; 114 | children = ( 115 | DAB724801B4D11AD00E78655 /* AliPayDemo.app */, 116 | DAB724991B4D11AD00E78655 /* AliPayDemoTests.xctest */, 117 | ); 118 | name = Products; 119 | sourceTree = ""; 120 | }; 121 | DAB724821B4D11AD00E78655 /* AliPayDemo */ = { 122 | isa = PBXGroup; 123 | children = ( 124 | DAB724871B4D11AD00E78655 /* AppDelegate.h */, 125 | DAB724881B4D11AD00E78655 /* AppDelegate.m */, 126 | DAB7248A1B4D11AD00E78655 /* ViewController.h */, 127 | DAB7248B1B4D11AD00E78655 /* ViewController.m */, 128 | DAB784071B56714000DBB327 /* SetpasswordViewController.h */, 129 | DAB784081B56714000DBB327 /* SetpasswordViewController.m */, 130 | DA576F971B5C96BF0010BD97 /* MBProgressHUD.h */, 131 | DA576F981B5C96BF0010BD97 /* MBProgressHUD.m */, 132 | DA6CD42A1B4F640900C0B22E /* AliSDK */, 133 | DAB7248D1B4D11AD00E78655 /* Main.storyboard */, 134 | DAB724901B4D11AD00E78655 /* Images.xcassets */, 135 | DAB724921B4D11AD00E78655 /* LaunchScreen.xib */, 136 | DAB724831B4D11AD00E78655 /* Supporting Files */, 137 | ); 138 | path = AliPayDemo; 139 | sourceTree = ""; 140 | }; 141 | DAB724831B4D11AD00E78655 /* Supporting Files */ = { 142 | isa = PBXGroup; 143 | children = ( 144 | DAB724841B4D11AD00E78655 /* Info.plist */, 145 | DAB724851B4D11AD00E78655 /* main.m */, 146 | ); 147 | name = "Supporting Files"; 148 | sourceTree = ""; 149 | }; 150 | DAB7249C1B4D11AD00E78655 /* AliPayDemoTests */ = { 151 | isa = PBXGroup; 152 | children = ( 153 | DAB7249F1B4D11AD00E78655 /* AliPayDemoTests.m */, 154 | DAB7249D1B4D11AD00E78655 /* Supporting Files */, 155 | ); 156 | path = AliPayDemoTests; 157 | sourceTree = ""; 158 | }; 159 | DAB7249D1B4D11AD00E78655 /* Supporting Files */ = { 160 | isa = PBXGroup; 161 | children = ( 162 | DAB7249E1B4D11AD00E78655 /* Info.plist */, 163 | ); 164 | name = "Supporting Files"; 165 | sourceTree = ""; 166 | }; 167 | /* End PBXGroup section */ 168 | 169 | /* Begin PBXNativeTarget section */ 170 | DAB7247F1B4D11AD00E78655 /* AliPayDemo */ = { 171 | isa = PBXNativeTarget; 172 | buildConfigurationList = DAB724A31B4D11AD00E78655 /* Build configuration list for PBXNativeTarget "AliPayDemo" */; 173 | buildPhases = ( 174 | DAB7247C1B4D11AD00E78655 /* Sources */, 175 | DAB7247D1B4D11AD00E78655 /* Frameworks */, 176 | DAB7247E1B4D11AD00E78655 /* Resources */, 177 | ); 178 | buildRules = ( 179 | ); 180 | dependencies = ( 181 | ); 182 | name = AliPayDemo; 183 | productName = AliPayDemo; 184 | productReference = DAB724801B4D11AD00E78655 /* AliPayDemo.app */; 185 | productType = "com.apple.product-type.application"; 186 | }; 187 | DAB724981B4D11AD00E78655 /* AliPayDemoTests */ = { 188 | isa = PBXNativeTarget; 189 | buildConfigurationList = DAB724A61B4D11AD00E78655 /* Build configuration list for PBXNativeTarget "AliPayDemoTests" */; 190 | buildPhases = ( 191 | DAB724951B4D11AD00E78655 /* Sources */, 192 | DAB724961B4D11AD00E78655 /* Frameworks */, 193 | DAB724971B4D11AD00E78655 /* Resources */, 194 | ); 195 | buildRules = ( 196 | ); 197 | dependencies = ( 198 | DAB7249B1B4D11AD00E78655 /* PBXTargetDependency */, 199 | ); 200 | name = AliPayDemoTests; 201 | productName = AliPayDemoTests; 202 | productReference = DAB724991B4D11AD00E78655 /* AliPayDemoTests.xctest */; 203 | productType = "com.apple.product-type.bundle.unit-test"; 204 | }; 205 | /* End PBXNativeTarget section */ 206 | 207 | /* Begin PBXProject section */ 208 | DAB724781B4D11AD00E78655 /* Project object */ = { 209 | isa = PBXProject; 210 | attributes = { 211 | LastUpgradeCheck = 0630; 212 | ORGANIZATIONNAME = guoxianlong; 213 | TargetAttributes = { 214 | DAB7247F1B4D11AD00E78655 = { 215 | CreatedOnToolsVersion = 6.3.1; 216 | }; 217 | DAB724981B4D11AD00E78655 = { 218 | CreatedOnToolsVersion = 6.3.1; 219 | TestTargetID = DAB7247F1B4D11AD00E78655; 220 | }; 221 | }; 222 | }; 223 | buildConfigurationList = DAB7247B1B4D11AD00E78655 /* Build configuration list for PBXProject "AliPayDemo" */; 224 | compatibilityVersion = "Xcode 3.2"; 225 | developmentRegion = English; 226 | hasScannedForEncodings = 0; 227 | knownRegions = ( 228 | en, 229 | Base, 230 | ); 231 | mainGroup = DAB724771B4D11AD00E78655; 232 | productRefGroup = DAB724811B4D11AD00E78655 /* Products */; 233 | projectDirPath = ""; 234 | projectRoot = ""; 235 | targets = ( 236 | DAB7247F1B4D11AD00E78655 /* AliPayDemo */, 237 | DAB724981B4D11AD00E78655 /* AliPayDemoTests */, 238 | ); 239 | }; 240 | /* End PBXProject section */ 241 | 242 | /* Begin PBXResourcesBuildPhase section */ 243 | DAB7247E1B4D11AD00E78655 /* Resources */ = { 244 | isa = PBXResourcesBuildPhase; 245 | buildActionMask = 2147483647; 246 | files = ( 247 | DAB7248F1B4D11AD00E78655 /* Main.storyboard in Resources */, 248 | DAB724941B4D11AD00E78655 /* LaunchScreen.xib in Resources */, 249 | DAB724911B4D11AD00E78655 /* Images.xcassets in Resources */, 250 | ); 251 | runOnlyForDeploymentPostprocessing = 0; 252 | }; 253 | DAB724971B4D11AD00E78655 /* Resources */ = { 254 | isa = PBXResourcesBuildPhase; 255 | buildActionMask = 2147483647; 256 | files = ( 257 | ); 258 | runOnlyForDeploymentPostprocessing = 0; 259 | }; 260 | /* End PBXResourcesBuildPhase section */ 261 | 262 | /* Begin PBXSourcesBuildPhase section */ 263 | DAB7247C1B4D11AD00E78655 /* Sources */ = { 264 | isa = PBXSourcesBuildPhase; 265 | buildActionMask = 2147483647; 266 | files = ( 267 | DAB784091B56714000DBB327 /* SetpasswordViewController.m in Sources */, 268 | DA6CD42D1B4F712B00C0B22E /* AliPayItem.m in Sources */, 269 | DAB6A6561B550CA90080C483 /* AlipaySubItem.m in Sources */, 270 | DAB7248C1B4D11AD00E78655 /* ViewController.m in Sources */, 271 | DAB724891B4D11AD00E78655 /* AppDelegate.m in Sources */, 272 | DAB784021B565CB100DBB327 /* KeychainItemWrapper.m in Sources */, 273 | DABA83581B4E7A310039A83D /* AliPayViews.m in Sources */, 274 | DA576F991B5C96BF0010BD97 /* MBProgressHUD.m in Sources */, 275 | DAB724861B4D11AD00E78655 /* main.m in Sources */, 276 | DAB784061B565CD700DBB327 /* KeychainData.m in Sources */, 277 | ); 278 | runOnlyForDeploymentPostprocessing = 0; 279 | }; 280 | DAB724951B4D11AD00E78655 /* Sources */ = { 281 | isa = PBXSourcesBuildPhase; 282 | buildActionMask = 2147483647; 283 | files = ( 284 | DAB724A01B4D11AD00E78655 /* AliPayDemoTests.m in Sources */, 285 | ); 286 | runOnlyForDeploymentPostprocessing = 0; 287 | }; 288 | /* End PBXSourcesBuildPhase section */ 289 | 290 | /* Begin PBXTargetDependency section */ 291 | DAB7249B1B4D11AD00E78655 /* PBXTargetDependency */ = { 292 | isa = PBXTargetDependency; 293 | target = DAB7247F1B4D11AD00E78655 /* AliPayDemo */; 294 | targetProxy = DAB7249A1B4D11AD00E78655 /* PBXContainerItemProxy */; 295 | }; 296 | /* End PBXTargetDependency section */ 297 | 298 | /* Begin PBXVariantGroup section */ 299 | DAB7248D1B4D11AD00E78655 /* Main.storyboard */ = { 300 | isa = PBXVariantGroup; 301 | children = ( 302 | DAB7248E1B4D11AD00E78655 /* Base */, 303 | ); 304 | name = Main.storyboard; 305 | sourceTree = ""; 306 | }; 307 | DAB724921B4D11AD00E78655 /* LaunchScreen.xib */ = { 308 | isa = PBXVariantGroup; 309 | children = ( 310 | DAB724931B4D11AD00E78655 /* Base */, 311 | ); 312 | name = LaunchScreen.xib; 313 | sourceTree = ""; 314 | }; 315 | /* End PBXVariantGroup section */ 316 | 317 | /* Begin XCBuildConfiguration section */ 318 | DAB724A11B4D11AD00E78655 /* Debug */ = { 319 | isa = XCBuildConfiguration; 320 | buildSettings = { 321 | ALWAYS_SEARCH_USER_PATHS = NO; 322 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 323 | CLANG_CXX_LIBRARY = "libc++"; 324 | CLANG_ENABLE_MODULES = YES; 325 | CLANG_ENABLE_OBJC_ARC = YES; 326 | CLANG_WARN_BOOL_CONVERSION = YES; 327 | CLANG_WARN_CONSTANT_CONVERSION = YES; 328 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 329 | CLANG_WARN_EMPTY_BODY = YES; 330 | CLANG_WARN_ENUM_CONVERSION = YES; 331 | CLANG_WARN_INT_CONVERSION = YES; 332 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 333 | CLANG_WARN_UNREACHABLE_CODE = YES; 334 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 335 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 336 | COPY_PHASE_STRIP = NO; 337 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 338 | ENABLE_STRICT_OBJC_MSGSEND = YES; 339 | GCC_C_LANGUAGE_STANDARD = gnu99; 340 | GCC_DYNAMIC_NO_PIC = NO; 341 | GCC_NO_COMMON_BLOCKS = YES; 342 | GCC_OPTIMIZATION_LEVEL = 0; 343 | GCC_PREPROCESSOR_DEFINITIONS = ( 344 | "DEBUG=1", 345 | "$(inherited)", 346 | ); 347 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 348 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 349 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 350 | GCC_WARN_UNDECLARED_SELECTOR = YES; 351 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 352 | GCC_WARN_UNUSED_FUNCTION = YES; 353 | GCC_WARN_UNUSED_VARIABLE = YES; 354 | IPHONEOS_DEPLOYMENT_TARGET = 8.3; 355 | MTL_ENABLE_DEBUG_INFO = YES; 356 | ONLY_ACTIVE_ARCH = YES; 357 | SDKROOT = iphoneos; 358 | TARGETED_DEVICE_FAMILY = "1,2"; 359 | }; 360 | name = Debug; 361 | }; 362 | DAB724A21B4D11AD00E78655 /* Release */ = { 363 | isa = XCBuildConfiguration; 364 | buildSettings = { 365 | ALWAYS_SEARCH_USER_PATHS = NO; 366 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 367 | CLANG_CXX_LIBRARY = "libc++"; 368 | CLANG_ENABLE_MODULES = YES; 369 | CLANG_ENABLE_OBJC_ARC = YES; 370 | CLANG_WARN_BOOL_CONVERSION = YES; 371 | CLANG_WARN_CONSTANT_CONVERSION = YES; 372 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 373 | CLANG_WARN_EMPTY_BODY = YES; 374 | CLANG_WARN_ENUM_CONVERSION = YES; 375 | CLANG_WARN_INT_CONVERSION = YES; 376 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 377 | CLANG_WARN_UNREACHABLE_CODE = YES; 378 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 379 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 380 | COPY_PHASE_STRIP = NO; 381 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 382 | ENABLE_NS_ASSERTIONS = NO; 383 | ENABLE_STRICT_OBJC_MSGSEND = YES; 384 | GCC_C_LANGUAGE_STANDARD = gnu99; 385 | GCC_NO_COMMON_BLOCKS = YES; 386 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 387 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 388 | GCC_WARN_UNDECLARED_SELECTOR = YES; 389 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 390 | GCC_WARN_UNUSED_FUNCTION = YES; 391 | GCC_WARN_UNUSED_VARIABLE = YES; 392 | IPHONEOS_DEPLOYMENT_TARGET = 8.3; 393 | MTL_ENABLE_DEBUG_INFO = NO; 394 | SDKROOT = iphoneos; 395 | TARGETED_DEVICE_FAMILY = "1,2"; 396 | VALIDATE_PRODUCT = YES; 397 | }; 398 | name = Release; 399 | }; 400 | DAB724A41B4D11AD00E78655 /* Debug */ = { 401 | isa = XCBuildConfiguration; 402 | buildSettings = { 403 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 404 | INFOPLIST_FILE = AliPayDemo/Info.plist; 405 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 406 | PRODUCT_NAME = "$(TARGET_NAME)"; 407 | }; 408 | name = Debug; 409 | }; 410 | DAB724A51B4D11AD00E78655 /* Release */ = { 411 | isa = XCBuildConfiguration; 412 | buildSettings = { 413 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 414 | INFOPLIST_FILE = AliPayDemo/Info.plist; 415 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 416 | PRODUCT_NAME = "$(TARGET_NAME)"; 417 | }; 418 | name = Release; 419 | }; 420 | DAB724A71B4D11AD00E78655 /* Debug */ = { 421 | isa = XCBuildConfiguration; 422 | buildSettings = { 423 | BUNDLE_LOADER = "$(TEST_HOST)"; 424 | FRAMEWORK_SEARCH_PATHS = ( 425 | "$(SDKROOT)/Developer/Library/Frameworks", 426 | "$(inherited)", 427 | ); 428 | GCC_PREPROCESSOR_DEFINITIONS = ( 429 | "DEBUG=1", 430 | "$(inherited)", 431 | ); 432 | INFOPLIST_FILE = AliPayDemoTests/Info.plist; 433 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 434 | PRODUCT_NAME = "$(TARGET_NAME)"; 435 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/AliPayDemo.app/AliPayDemo"; 436 | }; 437 | name = Debug; 438 | }; 439 | DAB724A81B4D11AD00E78655 /* Release */ = { 440 | isa = XCBuildConfiguration; 441 | buildSettings = { 442 | BUNDLE_LOADER = "$(TEST_HOST)"; 443 | FRAMEWORK_SEARCH_PATHS = ( 444 | "$(SDKROOT)/Developer/Library/Frameworks", 445 | "$(inherited)", 446 | ); 447 | INFOPLIST_FILE = AliPayDemoTests/Info.plist; 448 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 449 | PRODUCT_NAME = "$(TARGET_NAME)"; 450 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/AliPayDemo.app/AliPayDemo"; 451 | }; 452 | name = Release; 453 | }; 454 | /* End XCBuildConfiguration section */ 455 | 456 | /* Begin XCConfigurationList section */ 457 | DAB7247B1B4D11AD00E78655 /* Build configuration list for PBXProject "AliPayDemo" */ = { 458 | isa = XCConfigurationList; 459 | buildConfigurations = ( 460 | DAB724A11B4D11AD00E78655 /* Debug */, 461 | DAB724A21B4D11AD00E78655 /* Release */, 462 | ); 463 | defaultConfigurationIsVisible = 0; 464 | defaultConfigurationName = Release; 465 | }; 466 | DAB724A31B4D11AD00E78655 /* Build configuration list for PBXNativeTarget "AliPayDemo" */ = { 467 | isa = XCConfigurationList; 468 | buildConfigurations = ( 469 | DAB724A41B4D11AD00E78655 /* Debug */, 470 | DAB724A51B4D11AD00E78655 /* Release */, 471 | ); 472 | defaultConfigurationIsVisible = 0; 473 | defaultConfigurationName = Release; 474 | }; 475 | DAB724A61B4D11AD00E78655 /* Build configuration list for PBXNativeTarget "AliPayDemoTests" */ = { 476 | isa = XCConfigurationList; 477 | buildConfigurations = ( 478 | DAB724A71B4D11AD00E78655 /* Debug */, 479 | DAB724A81B4D11AD00E78655 /* Release */, 480 | ); 481 | defaultConfigurationIsVisible = 0; 482 | defaultConfigurationName = Release; 483 | }; 484 | /* End XCConfigurationList section */ 485 | }; 486 | rootObject = DAB724781B4D11AD00E78655 /* Project object */; 487 | } 488 | -------------------------------------------------------------------------------- /AliPayDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /AliPayDemo.xcodeproj/project.xcworkspace/xcshareddata/AliPayDemo.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | 04CB1C7E-6704-440F-B087-3521CA13DEA0 9 | IDESourceControlProjectName 10 | AliPayDemo 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | 02937104858487EDB3C86F0AE6D05A39E8F67C1F 14 | https://github.com/guoxianlongw/PGGestureViews.git 15 | 844FA71F52D3515E8B000EE0002BFC4876EB4C11 16 | https://github.com/guoxianlongw/PGScView.git 17 | 18 | IDESourceControlProjectPath 19 | AliPayDemo.xcodeproj 20 | IDESourceControlProjectRelativeInstallPathDictionary 21 | 22 | 02937104858487EDB3C86F0AE6D05A39E8F67C1F 23 | ../.. 24 | 844FA71F52D3515E8B000EE0002BFC4876EB4C11 25 | ../../.. 26 | 27 | IDESourceControlProjectURL 28 | https://github.com/guoxianlongw/PGGestureViews.git 29 | IDESourceControlProjectVersion 30 | 111 31 | IDESourceControlProjectWCCIdentifier 32 | 02937104858487EDB3C86F0AE6D05A39E8F67C1F 33 | IDESourceControlProjectWCConfigurations 34 | 35 | 36 | IDESourceControlRepositoryExtensionIdentifierKey 37 | public.vcs.git 38 | IDESourceControlWCCIdentifierKey 39 | 844FA71F52D3515E8B000EE0002BFC4876EB4C11 40 | IDESourceControlWCCName 41 | 42 | 43 | 44 | IDESourceControlRepositoryExtensionIdentifierKey 45 | public.vcs.git 46 | IDESourceControlWCCIdentifierKey 47 | 02937104858487EDB3C86F0AE6D05A39E8F67C1F 48 | IDESourceControlWCCName 49 | AliPayDemo 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /AliPayDemo.xcodeproj/project.xcworkspace/xcuserdata/Paul.xcuserdatad/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges 6 | 7 | SnapshotAutomaticallyBeforeSignificantChanges 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /AliPayDemo.xcodeproj/xcuserdata/Paul.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 14 | 15 | 16 | 18 | 30 | 31 | 32 | 34 | 46 | 47 | 48 | 50 | 62 | 63 | 64 | 66 | 78 | 79 | 80 | 82 | 94 | 95 | 96 | 98 | 110 | 111 | 112 | 114 | 126 | 127 | 128 | 130 | 142 | 143 | 144 | 146 | 158 | 159 | 160 | 162 | 174 | 175 | 176 | 178 | 190 | 191 | 192 | 193 | 194 | -------------------------------------------------------------------------------- /AliPayDemo.xcodeproj/xcuserdata/Paul.xcuserdatad/xcschemes/AliPayDemo.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 75 | 77 | 83 | 84 | 85 | 86 | 87 | 88 | 94 | 96 | 102 | 103 | 104 | 105 | 107 | 108 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /AliPayDemo.xcodeproj/xcuserdata/Paul.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | AliPayDemo.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | DAB7247F1B4D11AD00E78655 16 | 17 | primary 18 | 19 | 20 | DAB724981B4D11AD00E78655 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /AliPayDemo/AliSDK/AliPayItem.h: -------------------------------------------------------------------------------- 1 | // 2 | // AliPayItem.h 3 | // AliPayDemo 4 | // 5 | // Created by pg on 15/7/10. 6 | // Copyright (c) 2015年 pg. All rights reserved. 7 | // 8 | 9 | #import 10 | typedef enum { 11 | wrongStyle , 12 | selectStyle , 13 | normalStyle 14 | } selectStyleModel; 15 | 16 | 17 | 18 | 19 | @interface AliPayItem : UIView 20 | 21 | @property(nonatomic , assign)selectStyleModel model; 22 | 23 | @property(nonatomic , strong)CAShapeLayer *outterLayer; 24 | @property(nonatomic , strong)CAShapeLayer *innerLayer; 25 | @property(nonatomic , strong)CAShapeLayer *triangleLayer; 26 | 27 | @property(nonatomic , assign)BOOL isSelect; 28 | 29 | - (void)judegeDirectionActionx1:(CGFloat)x1 y1:(CGFloat)y1 x2:(CGFloat)x2 y2:(CGFloat)y2 isHidden:(BOOL)isHidden; 30 | 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /AliPayDemo/AliSDK/AliPayItem.m: -------------------------------------------------------------------------------- 1 | // 2 | // AliPayItem.m 3 | // AliPayDemo 4 | // 5 | // Created by pg on 15/7/10. 6 | // Copyright (c) 2015年 pg. All rights reserved. 7 | // 8 | 9 | #import "AliPayItem.h" 10 | #import "Header.h" 11 | 12 | 13 | 14 | 15 | @implementation AliPayItem 16 | 17 | - (instancetype)initWithFrame:(CGRect)frame 18 | { 19 | self = [super initWithFrame:frame]; 20 | if (self) { 21 | 22 | 23 | [self initViewsss]; 24 | 25 | } 26 | return self; 27 | } 28 | 29 | - (CAShapeLayer *)innerLayer 30 | { 31 | if (_innerLayer==nil) { 32 | _innerLayer = [CAShapeLayer layer]; 33 | _innerLayer.frame = CGRectMake((self.frame.size.width-ITEMRADIUS_INNER)/2 , (self.frame.size.width-ITEMRADIUS_INNER)/2 , ITEMRADIUS_INNER, ITEMRADIUS_INNER); 34 | _innerLayer.fillColor = [UIColor clearColor].CGColor; 35 | 36 | UIBezierPath *innerLayer = [UIBezierPath bezierPathWithOvalInRect:self.innerLayer.bounds]; 37 | _innerLayer.path = innerLayer.CGPath; 38 | 39 | } 40 | return _innerLayer; 41 | } 42 | 43 | - (CAShapeLayer *)outterLayer 44 | { 45 | if (_outterLayer==nil) { 46 | _outterLayer = [CAShapeLayer layer]; 47 | _outterLayer.frame = CGRectMake( (self.frame.size.width-ITEMRADIUS_OUTTER)/2 , (self.frame.size.width-ITEMRADIUS_OUTTER)/2 , ITEMRADIUS_OUTTER , ITEMRADIUS_OUTTER); 48 | _outterLayer.fillColor = BACKGROUNDCOLOR.CGColor; 49 | _outterLayer.strokeColor = [UIColor whiteColor].CGColor; 50 | _outterLayer.lineWidth = ITEMRADIUS_LINEWIDTH; 51 | 52 | UIBezierPath *outterLayer = [UIBezierPath bezierPathWithOvalInRect:self.outterLayer.bounds]; 53 | _outterLayer.path = outterLayer.CGPath; 54 | 55 | } 56 | return _outterLayer; 57 | } 58 | 59 | - (CAShapeLayer *)triangleLayer 60 | { 61 | if (_triangleLayer==nil) { 62 | _triangleLayer = [CAShapeLayer layer]; 63 | _triangleLayer.frame = CGRectZero; 64 | _triangleLayer.fillColor = SELECTCOLOR.CGColor; 65 | 66 | UIBezierPath *path = [UIBezierPath bezierPath]; 67 | [path moveToPoint:CGPointMake(self.frame.size.width/2 , self.innerLayer.frame.origin.y-10 )]; 68 | [path addLineToPoint:CGPointMake(self.frame.size.width/2-5, self.innerLayer.frame.origin.y-3)]; 69 | [path addLineToPoint:CGPointMake(self.frame.size.width/2+5, self.innerLayer.frame.origin.y-3)]; 70 | _triangleLayer.path = path.CGPath; 71 | 72 | } 73 | 74 | return _triangleLayer; 75 | } 76 | 77 | 78 | 79 | /** 80 | * init 81 | */ 82 | - (void)initViewsss 83 | { 84 | [self.layer addSublayer:self.outterLayer]; 85 | [self.layer addSublayer:self.innerLayer]; 86 | [self.layer addSublayer:self.triangleLayer]; 87 | self.triangleLayer.hidden = YES; 88 | } 89 | 90 | 91 | 92 | 93 | 94 | - (void)setModel:(selectStyleModel)model 95 | { 96 | switch (model) 97 | { 98 | case normalStyle: 99 | [self normalUI]; 100 | break; 101 | 102 | case selectStyle: 103 | [self selectUI]; 104 | break; 105 | 106 | case wrongStyle: 107 | [self wrongUI]; 108 | break; 109 | 110 | default: 111 | break; 112 | } 113 | } 114 | 115 | 116 | 117 | - (void)normalUI 118 | { 119 | self.innerLayer.fillColor = [UIColor clearColor].CGColor; 120 | self.outterLayer.strokeColor = [UIColor whiteColor].CGColor; 121 | } 122 | 123 | - (void)selectUI 124 | { 125 | self.innerLayer.fillColor = SELECTCOLOR.CGColor; 126 | self.outterLayer.strokeColor = SELECTCOLOR.CGColor; 127 | } 128 | 129 | - (void)wrongUI 130 | { 131 | self.innerLayer.fillColor = WRONGCOLOR.CGColor; 132 | self.outterLayer.strokeColor = WRONGCOLOR.CGColor; 133 | } 134 | 135 | 136 | 137 | 138 | 139 | - (void)judegeDirectionActionx1:(CGFloat)x1 y1:(CGFloat)y1 x2:(CGFloat)x2 y2:(CGFloat)y2 isHidden:(BOOL)isHidden 140 | { 141 | if (isHidden) { 142 | self.triangleLayer.hidden = YES; 143 | return; 144 | } 145 | if (x1==x2 && y1==y2) { 146 | return; 147 | } 148 | if (x1==0 && y1==0) { 149 | return; 150 | } 151 | if (x2==0 && y2==0) { 152 | return; 153 | } 154 | if (self.triangleLayer.hidden==NO) { 155 | return; 156 | } 157 | 158 | 159 | 160 | 161 | self.triangleLayer.hidden = NO; 162 | CGFloat angle ; 163 | 164 | if (x1y2) { 165 | // 左上 166 | angle = M_PI_4; 167 | } 168 | 169 | 170 | else if (x1x2 && y1x2 && y1==y2) { 195 | // 右 196 | angle = - M_PI_2; 197 | } 198 | 199 | 200 | else if (x1>x2 && y1>y2) { 201 | // 右上 202 | angle = - M_PI_4 *3 ; 203 | } 204 | 205 | else { 206 | angle = .0f; 207 | } 208 | 209 | //NSLog(@"..................... angle = [%f]", angle); 210 | self.transform = CGAffineTransformMakeRotation(angle); 211 | 212 | 213 | } 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | @end 224 | -------------------------------------------------------------------------------- /AliPayDemo/AliSDK/AliPayViews.h: -------------------------------------------------------------------------------- 1 | // 2 | // AliPayViews.h 3 | // AliPayDemo 4 | // 5 | // Created by pg on 15/7/9. 6 | // Copyright (c) 2015年 pg. All rights reserved. 7 | // 8 | 9 | #import 10 | typedef enum { 11 | AlertPwdModel, //修改密码 (需要先输入老密码) 12 | SetPwdModel, //重置密码(无论存不存老密码都一并删除,在重新设置密码) 13 | ValidatePwdModel, //验证密码 (输入一遍,进行验证) 14 | DeletePwdModel, //删除密码 15 | NoneModel 16 | }GestureModel; 17 | 18 | 19 | typedef void (^PasswordBlock) (NSString *pswString); 20 | 21 | 22 | @interface AliPayViews : UIView 23 | @property(nonatomic , assign)GestureModel gestureModel; 24 | @property(nonatomic , strong)PasswordBlock block; 25 | 26 | 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /AliPayDemo/AliSDK/AliPayViews.m: -------------------------------------------------------------------------------- 1 | // 2 | // AliPayViews.m 3 | // AliPayDemo 4 | // 5 | // Created by pg on 15/7/9. 6 | // Copyright (c) 2015年 pg. All rights reserved. 7 | // 8 | 9 | #import "AliPayViews.h" 10 | #import "AliPayItem.h" 11 | #import "Header.h" 12 | #import "KeychainData.h" 13 | #import "AlipaySubItem.h" 14 | 15 | #define KscreenHeight [UIScreen mainScreen].bounds.size.height 16 | #define KscreenWidth [UIScreen mainScreen].bounds.size.width 17 | 18 | #define ITEMTAG 122 19 | 20 | @interface AliPayViews() 21 | @property(nonatomic , strong)NSMutableArray *btnArray; 22 | @property(nonatomic , assign)CGPoint movePoint; 23 | @property(nonatomic , strong)AlipaySubItem *subItemsss; 24 | @property(nonatomic , strong)UILabel *tfLabel; 25 | @property(nonatomic , assign)CGPoint lastPoint; 26 | @end 27 | 28 | 29 | 30 | @implementation AliPayViews 31 | 32 | - (NSMutableArray *)btnArray 33 | { 34 | if (_btnArray==nil) { 35 | _btnArray = [NSMutableArray array]; 36 | } 37 | return _btnArray; 38 | } 39 | 40 | - (UILabel *)tfLabel 41 | { 42 | if (_tfLabel==nil) { 43 | _tfLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, self.subItemsss.frame.origin.y+50, KscreenWidth , 40)]; 44 | _tfLabel.textAlignment = NSTextAlignmentCenter; 45 | _tfLabel.textColor = [UIColor whiteColor]; 46 | _tfLabel.text = SETPSWSTRING; 47 | [self addSubview:_tfLabel]; 48 | } 49 | return _tfLabel; 50 | } 51 | 52 | 53 | - (AlipaySubItem *)subItemsss 54 | { 55 | if (_subItemsss==nil) { 56 | _subItemsss = [[AlipaySubItem alloc] initWithFrame:CGRectMake((self.frame.size.width-SUBITEMTOTALWH)/2, SUBITEM_TOP, SUBITEMTOTALWH, SUBITEMTOTALWH)]; 57 | [self addSubview:_subItemsss]; 58 | } 59 | return _subItemsss; 60 | } 61 | 62 | 63 | 64 | - (instancetype)initWithFrame:(CGRect)frame 65 | { 66 | self = [super initWithFrame:frame]; 67 | if (self) { 68 | 69 | [self initViews]; 70 | 71 | } 72 | return self; 73 | } 74 | 75 | #pragma mark - init 76 | - (void)initViews 77 | { 78 | self.backgroundColor = BACKGROUNDCOLOR; 79 | 80 | /******* 上面的9个小点 ******/ 81 | self.subItemsss.backgroundColor = [UIColor clearColor]; 82 | 83 | 84 | /***** 提示文字 ******/ 85 | self.tfLabel.backgroundColor = [UIColor clearColor]; 86 | 87 | 88 | /****** 9个大点的布局 *****/ 89 | [self createPoint_nine]; 90 | 91 | 92 | /******* 小按钮上三角的point ******/ 93 | _lastPoint = CGPointMake(0, 0); 94 | } 95 | 96 | 97 | 98 | 99 | 100 | 101 | #pragma mark - Touch Event 102 | /** 103 | * begin 104 | */ 105 | - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 106 | { 107 | [super touchesBegan:touches withEvent:event]; 108 | 109 | CGPoint point = [self touchLocation:touches]; 110 | 111 | [self isContainItem:point]; 112 | 113 | } 114 | 115 | 116 | /** 117 | * touch Move 118 | */ 119 | - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 120 | { 121 | [super touchesMoved:touches withEvent:event]; 122 | 123 | CGPoint point = [self touchLocation:touches]; 124 | 125 | [self isContainItem:point]; 126 | 127 | [self touchMove_triangleAction]; 128 | 129 | [self setNeedsDisplay]; 130 | 131 | } 132 | 133 | 134 | /** 135 | * touch End 136 | */ 137 | - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 138 | { 139 | [super touchesEnded:touches withEvent:event]; 140 | 141 | [self touchEndAction]; 142 | 143 | [self setNeedsDisplay]; 144 | 145 | 146 | } 147 | 148 | 149 | 150 | #pragma mark - UILabel property 151 | - (void)shake:(UIView *)myView 152 | { 153 | int offset = 8 ; 154 | 155 | CALayer *lbl = [myView layer]; 156 | CGPoint posLbl = [lbl position]; 157 | CGPoint y = CGPointMake(posLbl.x-offset, posLbl.y); 158 | CGPoint x = CGPointMake(posLbl.x+offset, posLbl.y); 159 | CABasicAnimation * animation = [CABasicAnimation animationWithKeyPath:@"position"]; 160 | [animation setTimingFunction:[CAMediaTimingFunction 161 | functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; 162 | [animation setFromValue:[NSValue valueWithCGPoint:x]]; 163 | [animation setToValue:[NSValue valueWithCGPoint:y]]; 164 | [animation setAutoreverses:YES]; 165 | [animation setDuration:0.06]; 166 | [animation setRepeatCount:2]; 167 | [lbl addAnimation:animation forKey:nil]; 168 | 169 | } 170 | 171 | 172 | 173 | 174 | 175 | - (void)setGestureModel:(GestureModel)gestureModel 176 | { 177 | _gestureModel = gestureModel; 178 | self.tfLabel.textColor = [UIColor whiteColor]; 179 | 180 | switch (gestureModel) { 181 | 182 | case AlertPwdModel: 183 | //修改密码 184 | self.tfLabel.text = INPUT_OLD_PSWSTRING; //请输入原始密码 185 | break; 186 | 187 | case SetPwdModel: 188 | //重置密码 189 | self.tfLabel.text = SETPSWSTRING; //请滑动设置密码 190 | break; 191 | 192 | case ValidatePwdModel: 193 | //验证密码 194 | self.tfLabel.text = VALIDATE_PSWSTRING; //验证密码 195 | break; 196 | 197 | case DeletePwdModel: 198 | //删除密码 199 | [KeychainData forgotPsw]; 200 | break; 201 | 202 | default: 203 | break; 204 | } 205 | } 206 | 207 | 208 | 209 | 210 | 211 | #pragma mark - total method 212 | 213 | /** 214 | * 下面的9个划线的点 init 215 | */ 216 | - (void)createPoint_nine 217 | { 218 | 219 | for (int i=0; i<9; i++) 220 | { 221 | int row = i / 3; 222 | int column = i % 3; 223 | 224 | CGFloat spaceFloat = (KscreenWidth-3*ITEMWH)/4; //每个item的间距是等宽的 225 | CGFloat pointX = spaceFloat*(column+1)+ITEMWH*column; //起点X 226 | CGFloat pointY = ITEM_TOTAL_POSITION + ITEMWH*row + spaceFloat*row; //起点Y 227 | 228 | /** 229 | * 对每一个item的frame的布局 230 | */ 231 | AliPayItem *item = [[AliPayItem alloc] initWithFrame:CGRectMake( pointX , pointY , ITEMWH, ITEMWH)]; 232 | item.userInteractionEnabled = YES; 233 | item.backgroundColor = [UIColor clearColor]; 234 | item.isSelect = NO; 235 | item.tag = ITEMTAG + i ; 236 | [self addSubview:item]; 237 | 238 | //NSLog(@"item.frame = [%@]", NSStringFromCGPoint(item.center)); 239 | } 240 | } 241 | 242 | /** 243 | * touch begin move 244 | */ 245 | 246 | - (CGPoint)touchLocation:(NSSet *)touches 247 | { 248 | UITouch *touch = [touches anyObject]; 249 | CGPoint point = [touch locationInView:self]; 250 | _movePoint = point; 251 | 252 | return point; 253 | } 254 | 255 | - (void)isContainItem:(CGPoint)point 256 | { 257 | for (AliPayItem *item in self.subviews) 258 | { 259 | if (![item isKindOfClass:[AlipaySubItem class]] && [item isKindOfClass:[AliPayItem class]]) 260 | { 261 | BOOL isContain = CGRectContainsPoint(item.frame, point); 262 | if (isContain && item.isSelect==NO) 263 | { 264 | [self.btnArray addObject:item]; 265 | item.isSelect = YES; 266 | item.model = selectStyle; 267 | } 268 | } 269 | 270 | } 271 | 272 | } 273 | 274 | - (void)touchMove_triangleAction 275 | { 276 | NSString *resultStr = [self getResultPwd]; 277 | if (resultStr&&resultStr.length>0 ) 278 | { 279 | NSArray *resultArr = [resultStr componentsSeparatedByString:@"A"]; 280 | if ([resultArr isKindOfClass:[NSArray class]] && resultArr.count>2 ) 281 | { 282 | NSString *lastTag = resultArr[resultArr.count-1]; 283 | NSString *lastTwoTag = resultArr[resultArr.count-2]; 284 | 285 | CGPoint lastP ; 286 | CGPoint lastTwoP; 287 | AliPayItem *lastItem; 288 | 289 | for (AliPayItem *item in self.btnArray) 290 | { 291 | if (item.tag-ITEMTAG == lastTag.intValue) 292 | { 293 | lastP = item.center; 294 | } 295 | if (item.tag-ITEMTAG == lastTwoTag.intValue) 296 | { 297 | lastTwoP = item.center; 298 | lastItem = item; 299 | } 300 | 301 | CGFloat x1 = lastTwoP.x; 302 | CGFloat y1 = lastTwoP.y; 303 | CGFloat x2 = lastP.x; 304 | CGFloat y2 = lastP.y; 305 | 306 | [lastItem judegeDirectionActionx1:x1 y1:y1 x2:x2 y2:y2 isHidden:NO]; 307 | 308 | } 309 | 310 | 311 | 312 | } 313 | } 314 | } 315 | 316 | /** 317 | * touch end 318 | */ 319 | - (void)touchEndAction 320 | { 321 | for (AliPayItem *itemssss in self.btnArray) 322 | { 323 | [itemssss judegeDirectionActionx1:0 y1:0 x2:0 y2:0 isHidden:NO]; 324 | } 325 | 326 | 327 | // if (判断格式少于4个点) [处理密码数据] 328 | if ([self judgeFormat]) [self setPswMethod:[self getResultPwd]] ; 329 | 330 | 331 | // 数组清空 332 | [self.btnArray removeAllObjects]; 333 | 334 | 335 | // 选中样式 336 | for (AliPayItem *item in self.subviews) 337 | { 338 | if (![item isKindOfClass:[AlipaySubItem class]] && [item isKindOfClass:[AliPayItem class]]) 339 | { 340 | item.isSelect = NO; 341 | item.model = normalStyle; 342 | [item judegeDirectionActionx1:0 y1:0 x2:0 y2:0 isHidden:YES]; 343 | } 344 | 345 | } 346 | 347 | } 348 | 349 | 350 | 351 | /** 352 | * 少于4个点 353 | */ 354 | - (BOOL)judgeFormat 355 | { 356 | if (self.btnArray.count<=3) { 357 | //不合法 358 | self.tfLabel.textColor = LABELWRONGCOLOR; 359 | self.tfLabel.text = PSW_WRONG_NUMSTRING; 360 | [self shake:self.tfLabel]; 361 | return NO; 362 | } 363 | 364 | return YES; 365 | } 366 | 367 | /** 368 | * 对密码str进行处理 369 | */ 370 | - (NSString *)getResultPwd 371 | { 372 | NSMutableString *resultStr = [NSMutableString string]; 373 | 374 | for (AliPayItem *item in self.btnArray) 375 | { 376 | if (![item isKindOfClass:[AlipaySubItem class]] && [item isKindOfClass:[AliPayItem class]]) 377 | { 378 | [resultStr appendString:@"A"]; 379 | [resultStr appendString:[NSString stringWithFormat:@"%ld", (long)item.tag-ITEMTAG]]; 380 | } 381 | } 382 | 383 | return (NSString *)resultStr; 384 | } 385 | 386 | 387 | 388 | 389 | #pragma mark - 处理修改,设置,登录的业务逻辑 390 | - (void)setPswMethod:(NSString *)resultStr 391 | { 392 | //没有任何记录,第一次登录 393 | BOOL isSaveBool = [KeychainData isFirstInput:resultStr]; 394 | 395 | //默认为蓝色 396 | UIColor *color = SELECTCOLOR; 397 | 398 | if (isSaveBool) { 399 | 400 | //第一次输入之后,显示的文字 401 | self.tfLabel.text = RESETPSWSTRING; 402 | self.tfLabel.textColor = [UIColor whiteColor]; 403 | 404 | } else { 405 | //密码已经存在 406 | //1 , 修改 407 | //2 , 验证 408 | //3 , 登录 409 | 410 | //设置密码 411 | color = [self setPwdJudgeAction:color str:resultStr]; 412 | 413 | //修改密码 414 | color = [self alertPwdJudgeAction:color str:resultStr]; 415 | 416 | //验证密码 417 | color = [self validatePwdJudgeAction:color str:resultStr]; 418 | 419 | } 420 | 421 | /************** 小键盘颜色 ***************/ 422 | [self.subItemsss resultArr:(NSArray *)[resultStr componentsSeparatedByString:@"A"] fillColor:color]; 423 | 424 | } 425 | 426 | 427 | 428 | /** 429 | * 设置密码 430 | */ 431 | - (UIColor *)setPwdJudgeAction:(UIColor *)color str:(NSString *)resultStr 432 | { 433 | /** 434 | * 设置密码 435 | */ 436 | if (self.gestureModel == SetPwdModel) { 437 | 438 | // isRight == YES 2次的密码相同 439 | BOOL isRight = [KeychainData isSecondInputRight:resultStr]; 440 | if (isRight) { 441 | // 验证成功 442 | 443 | self.tfLabel.text = PSWSUCCESSSTRING; 444 | self.tfLabel.textColor = [UIColor whiteColor]; 445 | [self performSelector:@selector(blockAction:) withObject:resultStr afterDelay:.8]; 446 | 447 | } else { 448 | 449 | // 失败 450 | self.tfLabel.text = PSWFAILTSTRING; 451 | self.tfLabel.textColor = LABELWRONGCOLOR; 452 | [self shake:self.tfLabel]; 453 | color = LABELWRONGCOLOR; 454 | 455 | } 456 | } 457 | return color; 458 | } 459 | /** 460 | * 修改密码 461 | */ 462 | - (UIColor *)alertPwdJudgeAction:(UIColor *)color str:(NSString *)resultStr 463 | { 464 | /** 465 | * 修改 466 | */ 467 | if (self.gestureModel == AlertPwdModel) 468 | { 469 | BOOL isValidate = [KeychainData isSecondInputRight:resultStr]; 470 | if (isValidate) { 471 | 472 | //如果验证成功 473 | [KeychainData forgotPsw]; 474 | self.tfLabel.text = INPUT_NEW_PSWSTRING; 475 | self.tfLabel.textColor = [UIColor whiteColor]; 476 | _gestureModel = SetPwdModel; 477 | 478 | } else { 479 | //验证失败 480 | self.tfLabel.text = PSWFAILTSTRING; 481 | self.tfLabel.textColor = LABELWRONGCOLOR; 482 | [self shake:self.tfLabel]; 483 | color = LABELWRONGCOLOR; 484 | } 485 | } 486 | return color; 487 | } 488 | 489 | /** 490 | * 验证,登录 491 | */ 492 | - (UIColor *)validatePwdJudgeAction:(UIColor *)color str:(NSString *)resultStr 493 | { 494 | 495 | 496 | if (self.gestureModel == ValidatePwdModel) { 497 | BOOL isValidate = [KeychainData isSecondInputRight:resultStr]; 498 | if (isValidate) { 499 | //如果验证成功 500 | self.tfLabel.text = VALIDATE_PSWSTRING_SUCCESS; 501 | self.tfLabel.textColor = [UIColor whiteColor]; 502 | [self performSelector:@selector(blockAction:) withObject:resultStr afterDelay:.8]; 503 | 504 | } else { 505 | //失败 506 | self.tfLabel.text = PSWFAILTSTRING; 507 | self.tfLabel.textColor = LABELWRONGCOLOR; 508 | [self shake:self.tfLabel]; 509 | color = LABELWRONGCOLOR; 510 | 511 | } 512 | } 513 | 514 | return color; 515 | } 516 | 517 | /** 518 | * 成功的block回调 519 | */ 520 | - (void)blockAction:(NSString *)resultStr 521 | { 522 | if (self.block) 523 | { 524 | _gestureModel = NoneModel; 525 | self.block([resultStr stringByReplacingOccurrencesOfString:@"A" withString:@"__"]); 526 | } 527 | } 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | #pragma mark - drawRect 536 | - (void)drawRect:(CGRect)rect 537 | { 538 | UIBezierPath *path = [UIBezierPath bezierPath]; 539 | 540 | for (int i=0; i 10 | 11 | @interface AlipaySubItem : UIView 12 | 13 | 14 | - (void)resultArr:(NSArray *)array fillColor:(UIColor *)color; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /AliPayDemo/AliSDK/AlipaySubItem.m: -------------------------------------------------------------------------------- 1 | // 2 | // AlipaySubItem.m 3 | // AliPayDemo 4 | // 5 | // Created by pg on 15/7/14. 6 | // Copyright (c) 2015年 pg. All rights reserved. 7 | // 8 | 9 | #import "AlipaySubItem.h" 10 | #import "Header.h" 11 | #define ALIPAYSUBITEMTAG 33 12 | 13 | @interface AlipaySubItem() 14 | //@property(nonatomic , strong)CAShapeLayer *shape; 15 | @end 16 | 17 | 18 | @implementation AlipaySubItem 19 | 20 | 21 | 22 | 23 | - (instancetype)initWithFrame:(CGRect)frame 24 | { 25 | self = [super initWithFrame:frame]; 26 | if (self) { 27 | [self initViews]; 28 | } 29 | return self; 30 | } 31 | 32 | 33 | - (void)initViews 34 | { 35 | for (int i=0; i<9; i++) 36 | { 37 | int row = i / 3 ; 38 | int column = i % 3 ; 39 | CGFloat x_or_y = (SUBITEMTOTALWH-3*SUBITEMWH)/4 ; 40 | CGFloat posX = x_or_y*(column+1)+column*SUBITEMWH ; 41 | CGFloat posY = x_or_y*(row+1)+row*SUBITEMWH ; 42 | 43 | 44 | UIView *myView = [[UIView alloc] initWithFrame:CGRectMake( posX , posY , SUBITEMWH , SUBITEMWH)]; 45 | myView.tag = i + ALIPAYSUBITEMTAG; 46 | [self addSubview:myView]; 47 | 48 | 49 | [self drawCircle:myView color:[UIColor clearColor]]; 50 | } 51 | } 52 | 53 | 54 | 55 | 56 | - (void)drawCircle:(UIView *)myView color:(UIColor *)color 57 | { 58 | if (color == [UIColor clearColor]) 59 | { 60 | myView.backgroundColor = [UIColor whiteColor]; 61 | } 62 | else 63 | { 64 | myView.backgroundColor = color; 65 | } 66 | 67 | 68 | CAShapeLayer *shape = [CAShapeLayer layer]; 69 | shape.frame = CGRectMake( 1 , 1 , SUBITEMWH-2 , SUBITEMWH-2); 70 | shape.fillColor = color.CGColor; 71 | if (color == [UIColor clearColor]) 72 | { 73 | shape.strokeColor = [UIColor whiteColor].CGColor; 74 | } 75 | else 76 | { 77 | shape.strokeColor = color.CGColor; 78 | } 79 | shape.lineWidth = 1; 80 | myView.layer.mask = shape; 81 | 82 | 83 | UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:shape.bounds]; 84 | shape.path = path.CGPath; 85 | } 86 | 87 | 88 | 89 | 90 | 91 | 92 | - (void)resultArr:(NSArray *)array fillColor:(UIColor *)color 93 | { 94 | [self.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { 95 | 96 | if ([array containsObject:[NSString stringWithFormat:@"%lu", (unsigned long)idx]]) 97 | { 98 | // 如果array里包含idx,填充为白色 99 | UIView *myView = (UIView *)[self viewWithTag:(idx+ALIPAYSUBITEMTAG)]; 100 | [self drawCircle:myView color:color]; 101 | 102 | [self performSelector:@selector(drawCleanCircle:) withObject:myView afterDelay:1 ]; 103 | 104 | } 105 | 106 | }]; 107 | } 108 | 109 | 110 | 111 | 112 | - (void)drawCleanCircle:(UIView *)myView 113 | { 114 | [self drawCircle:myView color:[UIColor clearColor]]; 115 | } 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | @end 129 | -------------------------------------------------------------------------------- /AliPayDemo/AliSDK/Header.h: -------------------------------------------------------------------------------- 1 | // 2 | // Header.h 3 | // AliPayDemo 4 | // 5 | // Created by pg on 15/7/10. 6 | // Copyright (c) 2015年 pg. All rights reserved. 7 | // 8 | 9 | #ifndef AliPayDemo_Header_h 10 | #define AliPayDemo_Header_h 11 | 12 | 13 | #endif 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | /******************* ITEM *********************/ 33 | 34 | #define ITEMRADIUS_OUTTER 70 //item的外圆直径 35 | #define ITEMRADIUS_INNER 20 //item的内圆直径 36 | #define ITEMRADIUS_LINEWIDTH 1 //item的线宽 37 | #define ITEMWH 70 //item的宽高 38 | #define ITEM_TOTAL_POSITION 250 // 整个item的顶点位置 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | /*********************** subItem *************************/ 49 | 50 | #define SUBITEMTOTALWH 50 // 整个subitem的大小 51 | #define SUBITEMWH 12 //单个subitem的大小 52 | #define SUBITEM_TOP 80 //整个的subitem的顶点位置(y点) 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | /*********************** 颜色 *************************/ 62 | 63 | //背景色 深蓝色 64 | #define BACKGROUNDCOLOR [UIColor colorWithRed:0.05 green:0.2 blue:0.35 alpha:1] 65 | 66 | //选中颜色 浅蓝色 67 | #define SELECTCOLOR [UIColor colorWithRed:0.13 green:0.7 blue:0.96 alpha:1] 68 | 69 | 70 | //选错的颜色 红色 71 | #define WRONGCOLOR [UIColor colorWithRed:1 green:0 blue:0 alpha:1] 72 | 73 | //文字错误提示颜色 浅红色 74 | #define LABELWRONGCOLOR [UIColor colorWithRed:0.94 green:0.31 blue:0.36 alpha:1] 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | /*********************** 文字提示语 *************************/ 84 | #define SETPSWSTRING @"请滑动设置密码" 85 | #define RESETPSWSTRING @"请再次滑动确认密码" 86 | #define PSWSUCCESSSTRING @"设置密码成功" 87 | #define PSWFAILTSTRING @"密码错误" 88 | #define PSW_WRONG_NUMSTRING @"请至少设置4个点" 89 | #define INPUT_OLD_PSWSTRING @"请输入原始密码" 90 | #define INPUT_NEW_PSWSTRING @"请输入新密码" 91 | #define VALIDATE_PSWSTRING @"验证密码" 92 | #define VALIDATE_PSWSTRING_SUCCESS @"登录成功" 93 | 94 | 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /AliPayDemo/AliSDK/KeychainData.h: -------------------------------------------------------------------------------- 1 | // 2 | // KeychainData.h 3 | // AliPayDemo 4 | // 5 | // Created by pg on 15/7/15. 6 | // Copyright (c) 2015年 pg. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface KeychainData : NSObject 12 | 13 | /****** 是否是第一次输入 ******/ 14 | + (BOOL)isFirstInput:(NSString *)str; 15 | 16 | /****** 判断第二次输入 ******/ 17 | + (BOOL)isSecondInputRight:(NSString *)str; 18 | 19 | /****** 忘记密码 ******/ 20 | + (void)forgotPsw; 21 | 22 | /****** 设置密码 ******/ 23 | + (void)setPSW:(NSString *)str; 24 | 25 | /***** 是否有保存记录 ******/ 26 | + (BOOL)isSave; 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | /**** KeychainData.m *****/ 40 | /***************** 根据keychain官网的,封装,增,取,删。都只需一句话 *********************/ 41 | + (void)setObject:(id)object forKey:(id)key; 42 | + (id)objectForKey:(id)key; 43 | + (void)removeObjectForKey:(id)key; 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /AliPayDemo/AliSDK/KeychainData.m: -------------------------------------------------------------------------------- 1 | // 2 | // KeychainData.m 3 | // AliPayDemo 4 | // 5 | // Created by pg on 15/7/15. 6 | // Copyright (c) 2015年 pg. All rights reserved. 7 | // 8 | 9 | #import "KeychainData.h" 10 | #import "KeychainItemWrapper.h" 11 | 12 | 13 | 14 | #define KEYCHAIN_KEY @"password_slider" 15 | 16 | @implementation KeychainData 17 | 18 | 19 | + (void)setObject:(id)object forKey:(id)key 20 | { 21 | KeychainItemWrapper *keyChain = [[KeychainItemWrapper alloc] initWithIdentifier:[NSString stringWithFormat:@"a%@&&a", key] accessGroup:nil]; 22 | [keyChain setObject:object forKey:(__bridge id)kSecAttrAccount];// 上面两行用来标识一个Item 23 | 24 | /** 25 | 26 | forKey:(id)kSecAttrAccount]; 27 | forKey:(id)kSecValueData]; 28 | 29 | 30 | */ 31 | 32 | } 33 | 34 | + (id)objectForKey:(id)key 35 | { 36 | KeychainItemWrapper *keyChain = [[KeychainItemWrapper alloc] initWithIdentifier:[NSString stringWithFormat:@"a%@&&a", key] accessGroup:nil]; 37 | id a = [keyChain objectForKey:(__bridge id)kSecAttrAccount]; 38 | return a; 39 | } 40 | 41 | + (void)removeObjectForKey:(id)key 42 | { 43 | KeychainItemWrapper *keyChain = [[KeychainItemWrapper alloc] initWithIdentifier:[NSString stringWithFormat:@"a%@&&a", key] accessGroup:nil]; 44 | [keyChain resetKeychainItem]; 45 | } 46 | 47 | 48 | #pragma mark -------------------------- 49 | 50 | + (BOOL)isSave 51 | { 52 | NSString *str = [self objectForKey:KEYCHAIN_KEY]; 53 | if (str && str.length>0 && [str isKindOfClass:[NSString class]]) { 54 | return YES; 55 | } 56 | 57 | return NO; 58 | } 59 | 60 | 61 | + (BOOL)isFirstInput:(NSString *)str 62 | { 63 | NSString *oldStr = [self objectForKey:KEYCHAIN_KEY]; 64 | if (oldStr && oldStr.length>0 && [oldStr isKindOfClass:[NSString class]]) 65 | { 66 | return NO; 67 | } 68 | 69 | [self setObject:str forKey:KEYCHAIN_KEY]; 70 | 71 | return YES; 72 | } 73 | 74 | 75 | 76 | + (BOOL)isSecondInputRight:(NSString *)str 77 | { 78 | NSString *oldStr = [self objectForKey:KEYCHAIN_KEY]; 79 | 80 | if ([oldStr isKindOfClass:[NSNull class]]) { 81 | return NO; 82 | } 83 | else if (!oldStr || oldStr.length<1 || ![oldStr isKindOfClass:[NSString class]]) { 84 | return NO; 85 | } 86 | else if (oldStr.length==str.length && [oldStr isEqualToString:str]) { 87 | return YES; 88 | } 89 | 90 | return NO; 91 | } 92 | 93 | 94 | + (void)forgotPsw 95 | { 96 | [self removeObjectForKey:KEYCHAIN_KEY]; 97 | } 98 | 99 | 100 | + (void)setPSW:(NSString *)str 101 | { 102 | [self setObject:str forKey:KEYCHAIN_KEY]; 103 | } 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | @end 114 | -------------------------------------------------------------------------------- /AliPayDemo/AliSDK/KeychainItemWrapper.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: KeychainItemWrapper.h 3 | Abstract: 4 | Objective-C wrapper for accessing a single keychain item. 5 | 6 | Version: 1.2 7 | 8 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 9 | Inc. ("Apple") in consideration of your agreement to the following 10 | terms, and your use, installation, modification or redistribution of 11 | this Apple software constitutes acceptance of these terms. If you do 12 | not agree with these terms, please do not use, install, modify or 13 | redistribute this Apple software. 14 | 15 | In consideration of your agreement to abide by the following terms, and 16 | subject to these terms, Apple grants you a personal, non-exclusive 17 | license, under Apple's copyrights in this original Apple software (the 18 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 19 | Software, with or without modifications, in source and/or binary forms; 20 | provided that if you redistribute the Apple Software in its entirety and 21 | without modifications, you must retain this notice and the following 22 | text and disclaimers in all such redistributions of the Apple Software. 23 | Neither the name, trademarks, service marks or logos of Apple Inc. may 24 | be used to endorse or promote products derived from the Apple Software 25 | without specific prior written permission from Apple. Except as 26 | expressly stated in this notice, no other rights or licenses, express or 27 | implied, are granted by Apple herein, including but not limited to any 28 | patent rights that may be infringed by your derivative works or by other 29 | works in which the Apple Software may be incorporated. 30 | 31 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 32 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 33 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 34 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 35 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 36 | 37 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 38 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 39 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 40 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 41 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 42 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 43 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 44 | POSSIBILITY OF SUCH DAMAGE. 45 | 46 | Copyright (C) 2010 Apple Inc. All Rights Reserved. 47 | 48 | */ 49 | 50 | #import 51 | 52 | /* 53 | The KeychainItemWrapper class is an abstraction layer for the iPhone Keychain communication. It is merely a 54 | simple wrapper to provide a distinct barrier between all the idiosyncracies involved with the Keychain 55 | CF/NS container objects. 56 | */ 57 | @interface KeychainItemWrapper : NSObject 58 | { 59 | NSMutableDictionary *keychainItemData; // The actual keychain item data backing store. 60 | NSMutableDictionary *genericPasswordQuery; // A placeholder for the generic keychain item query used to locate the item. 61 | } 62 | 63 | @property (nonatomic, retain) NSMutableDictionary *keychainItemData; 64 | @property (nonatomic, retain) NSMutableDictionary *genericPasswordQuery; 65 | 66 | // Designated initializer. 67 | - (id)initWithIdentifier: (NSString *)identifier accessGroup:(NSString *) accessGroup; 68 | - (void)setObject:(id)inObject forKey:(id)key; 69 | - (id)objectForKey:(id)key; 70 | 71 | // Initializes and resets the default generic keychain item data. 72 | - (void)resetKeychainItem; 73 | 74 | @end -------------------------------------------------------------------------------- /AliPayDemo/AliSDK/KeychainItemWrapper.m: -------------------------------------------------------------------------------- 1 | /* 2 | File: KeychainItemWrapper.m 3 | Abstract: 4 | Objective-C wrapper for accessing a single keychain item. 5 | 6 | Version: 1.2 7 | 8 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 9 | Inc. ("Apple") in consideration of your agreement to the following 10 | terms, and your use, installation, modification or redistribution of 11 | this Apple software constitutes acceptance of these terms. If you do 12 | not agree with these terms, please do not use, install, modify or 13 | redistribute this Apple software. 14 | 15 | In consideration of your agreement to abide by the following terms, and 16 | subject to these terms, Apple grants you a personal, non-exclusive 17 | license, under Apple's copyrights in this original Apple software (the 18 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 19 | Software, with or without modifications, in source and/or binary forms; 20 | provided that if you redistribute the Apple Software in its entirety and 21 | without modifications, you must retain this notice and the following 22 | text and disclaimers in all such redistributions of the Apple Software. 23 | Neither the name, trademarks, service marks or logos of Apple Inc. may 24 | be used to endorse or promote products derived from the Apple Software 25 | without specific prior written permission from Apple. Except as 26 | expressly stated in this notice, no other rights or licenses, express or 27 | implied, are granted by Apple herein, including but not limited to any 28 | patent rights that may be infringed by your derivative works or by other 29 | works in which the Apple Software may be incorporated. 30 | 31 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 32 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 33 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 34 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 35 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 36 | 37 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 38 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 39 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 40 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 41 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 42 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 43 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 44 | POSSIBILITY OF SUCH DAMAGE. 45 | 46 | Copyright (C) 2010 Apple Inc. All Rights Reserved. 47 | 48 | */ 49 | 50 | #import "KeychainItemWrapper.h" 51 | #import 52 | 53 | /* 54 | 55 | These are the default constants and their respective types, 56 | available for the kSecClassGenericPassword Keychain Item class: 57 | 58 | kSecAttrAccessGroup - CFStringRef 59 | kSecAttrCreationDate - CFDateRef 60 | kSecAttrModificationDate - CFDateRef 61 | kSecAttrDescription - CFStringRef 62 | kSecAttrComment - CFStringRef 63 | kSecAttrCreator - CFNumberRef 64 | kSecAttrType - CFNumberRef 65 | kSecAttrLabel - CFStringRef 66 | kSecAttrIsInvisible - CFBooleanRef 67 | kSecAttrIsNegative - CFBooleanRef 68 | kSecAttrAccount - CFStringRef 69 | kSecAttrService - CFStringRef 70 | kSecAttrGeneric - CFDataRef 71 | 72 | See the header file Security/SecItem.h for more details. 73 | 74 | */ 75 | 76 | @interface KeychainItemWrapper (PrivateMethods) 77 | /* 78 | The decision behind the following two methods (secItemFormatToDictionary and dictionaryToSecItemFormat) was 79 | to encapsulate the transition between what the detail view controller was expecting (NSString *) and what the 80 | Keychain API expects as a validly constructed container class. 81 | */ 82 | - (NSMutableDictionary *)secItemFormatToDictionary:(NSDictionary *)dictionaryToConvert; 83 | - (NSMutableDictionary *)dictionaryToSecItemFormat:(NSDictionary *)dictionaryToConvert; 84 | 85 | // Updates the item in the keychain, or adds it if it doesn't exist. 86 | - (void)writeToKeychain; 87 | 88 | @end 89 | 90 | @implementation KeychainItemWrapper 91 | 92 | @synthesize keychainItemData, genericPasswordQuery; 93 | 94 | - (id)initWithIdentifier: (NSString *)identifier accessGroup:(NSString *) accessGroup; 95 | { 96 | if (self = [super init]) 97 | { 98 | // Begin Keychain search setup. The genericPasswordQuery leverages the special user 99 | // defined attribute kSecAttrGeneric to distinguish itself between other generic Keychain 100 | // items which may be included by the same application. 101 | genericPasswordQuery = [[NSMutableDictionary alloc] init]; 102 | 103 | [genericPasswordQuery setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass]; 104 | [genericPasswordQuery setObject:identifier forKey:(id)kSecAttrGeneric]; 105 | 106 | // The keychain access group attribute determines if this item can be shared 107 | // amongst multiple apps whose code signing entitlements contain the same keychain access group. 108 | if (accessGroup != nil) 109 | { 110 | #if TARGET_IPHONE_SIMULATOR 111 | // Ignore the access group if running on the iPhone simulator. 112 | // 113 | // Apps that are built for the simulator aren't signed, so there's no keychain access group 114 | // for the simulator to check. This means that all apps can see all keychain items when run 115 | // on the simulator. 116 | // 117 | // If a SecItem contains an access group attribute, SecItemAdd and SecItemUpdate on the 118 | // simulator will return -25243 (errSecNoAccessForItem). 119 | #else 120 | [genericPasswordQuery setObject:accessGroup forKey:(id)kSecAttrAccessGroup]; 121 | #endif 122 | } 123 | 124 | // Use the proper search constants, return only the attributes of the first match. 125 | [genericPasswordQuery setObject:(id)kSecMatchLimitOne forKey:(id)kSecMatchLimit]; 126 | [genericPasswordQuery setObject:(id)kCFBooleanTrue forKey:(id)kSecReturnAttributes]; 127 | 128 | NSDictionary *tempQuery = [NSDictionary dictionaryWithDictionary:genericPasswordQuery]; 129 | 130 | NSMutableDictionary *outDictionary = nil; 131 | 132 | if (! SecItemCopyMatching((CFDictionaryRef)tempQuery, (CFTypeRef *)&outDictionary) == noErr) 133 | { 134 | // Stick these default values into keychain item if nothing found. 135 | [self resetKeychainItem]; 136 | 137 | // Add the generic attribute and the keychain access group. 138 | [keychainItemData setObject:identifier forKey:(id)kSecAttrGeneric]; 139 | if (accessGroup != nil) 140 | { 141 | #if TARGET_IPHONE_SIMULATOR 142 | // Ignore the access group if running on the iPhone simulator. 143 | // 144 | // Apps that are built for the simulator aren't signed, so there's no keychain access group 145 | // for the simulator to check. This means that all apps can see all keychain items when run 146 | // on the simulator. 147 | // 148 | // If a SecItem contains an access group attribute, SecItemAdd and SecItemUpdate on the 149 | // simulator will return -25243 (errSecNoAccessForItem). 150 | #else 151 | [keychainItemData setObject:accessGroup forKey:(id)kSecAttrAccessGroup]; 152 | #endif 153 | } 154 | } 155 | else 156 | { 157 | // load the saved data from Keychain. 158 | self.keychainItemData = [self secItemFormatToDictionary:outDictionary]; 159 | } 160 | 161 | [outDictionary release]; 162 | } 163 | 164 | return self; 165 | } 166 | 167 | - (void)dealloc 168 | { 169 | [keychainItemData release]; 170 | [genericPasswordQuery release]; 171 | 172 | [super dealloc]; 173 | } 174 | 175 | - (void)setObject:(id)inObject forKey:(id)key 176 | { 177 | if (inObject == nil) return; 178 | id currentObject = [keychainItemData objectForKey:key]; 179 | if (![currentObject isEqual:inObject]) 180 | { 181 | [keychainItemData setObject:inObject forKey:key]; 182 | [self writeToKeychain]; 183 | } 184 | } 185 | 186 | - (id)objectForKey:(id)key 187 | { 188 | return [keychainItemData objectForKey:key]; 189 | } 190 | 191 | - (void)resetKeychainItem 192 | { 193 | OSStatus junk = noErr; 194 | if (!keychainItemData) 195 | { 196 | self.keychainItemData = [[NSMutableDictionary alloc] init]; 197 | } 198 | else if (keychainItemData) 199 | { 200 | NSMutableDictionary *tempDictionary = [self dictionaryToSecItemFormat:keychainItemData]; 201 | junk = SecItemDelete((CFDictionaryRef)tempDictionary); 202 | NSAssert( junk == noErr || junk == errSecItemNotFound, @"Problem deleting current dictionary." ); 203 | } 204 | 205 | // Default attributes for keychain item. 206 | [keychainItemData setObject:@"" forKey:(id)kSecAttrAccount]; 207 | [keychainItemData setObject:@"" forKey:(id)kSecAttrLabel]; 208 | [keychainItemData setObject:@"" forKey:(id)kSecAttrDescription]; 209 | 210 | // Default data for keychain item. 211 | [keychainItemData setObject:@"" forKey:(id)kSecValueData]; 212 | } 213 | 214 | - (NSMutableDictionary *)dictionaryToSecItemFormat:(NSDictionary *)dictionaryToConvert 215 | { 216 | // The assumption is that this method will be called with a properly populated dictionary 217 | // containing all the right key/value pairs for a SecItem. 218 | 219 | // Create a dictionary to return populated with the attributes and data. 220 | NSMutableDictionary *returnDictionary = [NSMutableDictionary dictionaryWithDictionary:dictionaryToConvert]; 221 | 222 | // Add the Generic Password keychain item class attribute. 223 | [returnDictionary setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass]; 224 | 225 | // Convert the NSString to NSData to meet the requirements for the value type kSecValueData. 226 | // This is where to store sensitive data that should be encrypted. 227 | NSString *passwordString = [dictionaryToConvert objectForKey:(id)kSecValueData]; 228 | [returnDictionary setObject:[passwordString dataUsingEncoding:NSUTF8StringEncoding] forKey:(id)kSecValueData]; 229 | 230 | return returnDictionary; 231 | } 232 | 233 | - (NSMutableDictionary *)secItemFormatToDictionary:(NSDictionary *)dictionaryToConvert 234 | { 235 | // The assumption is that this method will be called with a properly populated dictionary 236 | // containing all the right key/value pairs for the UI element. 237 | 238 | // Create a dictionary to return populated with the attributes and data. 239 | NSMutableDictionary *returnDictionary = [NSMutableDictionary dictionaryWithDictionary:dictionaryToConvert]; 240 | 241 | // Add the proper search key and class attribute. 242 | [returnDictionary setObject:(id)kCFBooleanTrue forKey:(id)kSecReturnData]; 243 | [returnDictionary setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass]; 244 | 245 | // Acquire the password data from the attributes. 246 | NSData *passwordData = NULL; 247 | if (SecItemCopyMatching((CFDictionaryRef)returnDictionary, (CFTypeRef *)&passwordData) == noErr) 248 | { 249 | // Remove the search, class, and identifier key/value, we don't need them anymore. 250 | [returnDictionary removeObjectForKey:(id)kSecReturnData]; 251 | 252 | // Add the password to the dictionary, converting from NSData to NSString. 253 | NSString *password = [[[NSString alloc] initWithBytes:[passwordData bytes] length:[passwordData length] 254 | encoding:NSUTF8StringEncoding] autorelease]; 255 | [returnDictionary setObject:password forKey:(id)kSecValueData]; 256 | } 257 | else 258 | { 259 | // Don't do anything if nothing is found. 260 | NSAssert(NO, @"Serious error, no matching item found in the keychain.\n"); 261 | } 262 | 263 | [passwordData release]; 264 | 265 | return returnDictionary; 266 | } 267 | 268 | - (void)writeToKeychain 269 | { 270 | NSDictionary *attributes = NULL; 271 | NSMutableDictionary *updateItem = NULL; 272 | OSStatus result; 273 | 274 | if (SecItemCopyMatching((CFDictionaryRef)genericPasswordQuery, (CFTypeRef *)&attributes) == noErr) 275 | { 276 | // First we need the attributes from the Keychain. 277 | updateItem = [NSMutableDictionary dictionaryWithDictionary:attributes]; 278 | // Second we need to add the appropriate search key/values. 279 | [updateItem setObject:[genericPasswordQuery objectForKey:(id)kSecClass] forKey:(id)kSecClass]; 280 | 281 | // Lastly, we need to set up the updated attribute list being careful to remove the class. 282 | NSMutableDictionary *tempCheck = [self dictionaryToSecItemFormat:keychainItemData]; 283 | [tempCheck removeObjectForKey:(id)kSecClass]; 284 | 285 | #if TARGET_IPHONE_SIMULATOR 286 | // Remove the access group if running on the iPhone simulator. 287 | // 288 | // Apps that are built for the simulator aren't signed, so there's no keychain access group 289 | // for the simulator to check. This means that all apps can see all keychain items when run 290 | // on the simulator. 291 | // 292 | // If a SecItem contains an access group attribute, SecItemAdd and SecItemUpdate on the 293 | // simulator will return -25243 (errSecNoAccessForItem). 294 | // 295 | // The access group attribute will be included in items returned by SecItemCopyMatching, 296 | // which is why we need to remove it before updating the item. 297 | [tempCheck removeObjectForKey:(id)kSecAttrAccessGroup]; 298 | #endif 299 | 300 | // An implicit assumption is that you can only update a single item at a time. 301 | 302 | result = SecItemUpdate((CFDictionaryRef)updateItem, (CFDictionaryRef)tempCheck); 303 | NSAssert( result == noErr, @"Couldn't update the Keychain Item." ); 304 | } 305 | else 306 | { 307 | // No previous item found; add the new one. 308 | result = SecItemAdd((CFDictionaryRef)[self dictionaryToSecItemFormat:keychainItemData], NULL); 309 | NSAssert( result == noErr, @"Couldn't add the Keychain Item." ); 310 | } 311 | } 312 | 313 | @end 314 | -------------------------------------------------------------------------------- /AliPayDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // AliPayDemo 4 | // 5 | // Created by pg on 15/7/8. 6 | // Copyright (c) 2015年 pg. 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 | -------------------------------------------------------------------------------- /AliPayDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // AliPayDemo 4 | // 5 | // Created by pg on 15/7/8. 6 | // Copyright (c) 2015年 pg. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // 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. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /AliPayDemo/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /AliPayDemo/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 | -------------------------------------------------------------------------------- /AliPayDemo/Images.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 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /AliPayDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | BHYB.$(PRODUCT_NAME:rfc1034identifier) 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 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /AliPayDemo/MBProgressHUD.h: -------------------------------------------------------------------------------- 1 | // 2 | // MBProgressHUD.h 3 | // Version 0.9.1 4 | // Created by Matej Bukovinski on 2.4.09 5 | // This code is distributed under the terms and conditions of the MIT license. 6 | 7 | // Copyright (c) 2009-2015 Matej Bukovinski 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | 27 | #import 28 | #import 29 | #import 30 | 31 | @protocol MBProgressHUDDelegate; 32 | 33 | 34 | typedef NS_ENUM(NSInteger, MBProgressHUDMode) { 35 | /** Progress is shown using an UIActivityIndicatorView. This is the default. */ 36 | MBProgressHUDModeIndeterminate, 37 | /** Progress is shown using a round, pie-chart like, progress view. */ 38 | MBProgressHUDModeDeterminate, 39 | /** Progress is shown using a horizontal progress bar */ 40 | MBProgressHUDModeDeterminateHorizontalBar, 41 | /** Progress is shown using a ring-shaped progress view. */ 42 | MBProgressHUDModeAnnularDeterminate, 43 | /** Shows a custom view */ 44 | MBProgressHUDModeCustomView, 45 | /** Shows only labels */ 46 | MBProgressHUDModeText 47 | }; 48 | 49 | typedef NS_ENUM(NSInteger, MBProgressHUDAnimation) { 50 | /** Opacity animation */ 51 | MBProgressHUDAnimationFade, 52 | /** Opacity + scale animation */ 53 | MBProgressHUDAnimationZoom, 54 | MBProgressHUDAnimationZoomOut = MBProgressHUDAnimationZoom, 55 | MBProgressHUDAnimationZoomIn 56 | }; 57 | 58 | 59 | #ifndef MB_INSTANCETYPE 60 | #if __has_feature(objc_instancetype) 61 | #define MB_INSTANCETYPE instancetype 62 | #else 63 | #define MB_INSTANCETYPE id 64 | #endif 65 | #endif 66 | 67 | #ifndef MB_STRONG 68 | #if __has_feature(objc_arc) 69 | #define MB_STRONG strong 70 | #else 71 | #define MB_STRONG retain 72 | #endif 73 | #endif 74 | 75 | #ifndef MB_WEAK 76 | #if __has_feature(objc_arc_weak) 77 | #define MB_WEAK weak 78 | #elif __has_feature(objc_arc) 79 | #define MB_WEAK unsafe_unretained 80 | #else 81 | #define MB_WEAK assign 82 | #endif 83 | #endif 84 | 85 | #if NS_BLOCKS_AVAILABLE 86 | typedef void (^MBProgressHUDCompletionBlock)(); 87 | #endif 88 | 89 | 90 | /** 91 | * Displays a simple HUD window containing a progress indicator and two optional labels for short messages. 92 | * 93 | * This is a simple drop-in class for displaying a progress HUD view similar to Apple's private UIProgressHUD class. 94 | * The MBProgressHUD window spans over the entire space given to it by the initWithFrame constructor and catches all 95 | * user input on this region, thereby preventing the user operations on components below the view. The HUD itself is 96 | * drawn centered as a rounded semi-transparent view which resizes depending on the user specified content. 97 | * 98 | * This view supports four modes of operation: 99 | * - MBProgressHUDModeIndeterminate - shows a UIActivityIndicatorView 100 | * - MBProgressHUDModeDeterminate - shows a custom round progress indicator 101 | * - MBProgressHUDModeAnnularDeterminate - shows a custom annular progress indicator 102 | * - MBProgressHUDModeCustomView - shows an arbitrary, user specified view (@see customView) 103 | * 104 | * All three modes can have optional labels assigned: 105 | * - If the labelText property is set and non-empty then a label containing the provided content is placed below the 106 | * indicator view. 107 | * - If also the detailsLabelText property is set then another label is placed below the first label. 108 | */ 109 | @interface MBProgressHUD : UIView 110 | 111 | /** 112 | * Creates a new HUD, adds it to provided view and shows it. The counterpart to this method is hideHUDForView:animated:. 113 | * 114 | * @param view The view that the HUD will be added to 115 | * @param animated If set to YES the HUD will appear using the current animationType. If set to NO the HUD will not use 116 | * animations while appearing. 117 | * @return A reference to the created HUD. 118 | * 119 | * @see hideHUDForView:animated: 120 | * @see animationType 121 | */ 122 | + (MB_INSTANCETYPE)showHUDAddedTo:(UIView *)view animated:(BOOL)animated; 123 | 124 | /** 125 | * Finds the top-most HUD subview and hides it. The counterpart to this method is showHUDAddedTo:animated:. 126 | * 127 | * @param view The view that is going to be searched for a HUD subview. 128 | * @param animated If set to YES the HUD will disappear using the current animationType. If set to NO the HUD will not use 129 | * animations while disappearing. 130 | * @return YES if a HUD was found and removed, NO otherwise. 131 | * 132 | * @see showHUDAddedTo:animated: 133 | * @see animationType 134 | */ 135 | + (BOOL)hideHUDForView:(UIView *)view animated:(BOOL)animated; 136 | 137 | /** 138 | * Finds all the HUD subviews and hides them. 139 | * 140 | * @param view The view that is going to be searched for HUD subviews. 141 | * @param animated If set to YES the HUDs will disappear using the current animationType. If set to NO the HUDs will not use 142 | * animations while disappearing. 143 | * @return the number of HUDs found and removed. 144 | * 145 | * @see hideHUDForView:animated: 146 | * @see animationType 147 | */ 148 | + (NSUInteger)hideAllHUDsForView:(UIView *)view animated:(BOOL)animated; 149 | 150 | /** 151 | * Finds the top-most HUD subview and returns it. 152 | * 153 | * @param view The view that is going to be searched. 154 | * @return A reference to the last HUD subview discovered. 155 | */ 156 | + (MB_INSTANCETYPE)HUDForView:(UIView *)view; 157 | 158 | /** 159 | * Finds all HUD subviews and returns them. 160 | * 161 | * @param view The view that is going to be searched. 162 | * @return All found HUD views (array of MBProgressHUD objects). 163 | */ 164 | + (NSArray *)allHUDsForView:(UIView *)view; 165 | 166 | /** 167 | * A convenience constructor that initializes the HUD with the window's bounds. Calls the designated constructor with 168 | * window.bounds as the parameter. 169 | * 170 | * @param window The window instance that will provide the bounds for the HUD. Should be the same instance as 171 | * the HUD's superview (i.e., the window that the HUD will be added to). 172 | */ 173 | - (id)initWithWindow:(UIWindow *)window; 174 | 175 | /** 176 | * A convenience constructor that initializes the HUD with the view's bounds. Calls the designated constructor with 177 | * view.bounds as the parameter 178 | * 179 | * @param view The view instance that will provide the bounds for the HUD. Should be the same instance as 180 | * the HUD's superview (i.e., the view that the HUD will be added to). 181 | */ 182 | - (id)initWithView:(UIView *)view; 183 | 184 | /** 185 | * Display the HUD. You need to make sure that the main thread completes its run loop soon after this method call so 186 | * the user interface can be updated. Call this method when your task is already set-up to be executed in a new thread 187 | * (e.g., when using something like NSOperation or calling an asynchronous call like NSURLRequest). 188 | * 189 | * @param animated If set to YES the HUD will appear using the current animationType. If set to NO the HUD will not use 190 | * animations while appearing. 191 | * 192 | * @see animationType 193 | */ 194 | - (void)show:(BOOL)animated; 195 | 196 | /** 197 | * Hide the HUD. This still calls the hudWasHidden: delegate. This is the counterpart of the show: method. Use it to 198 | * hide the HUD when your task completes. 199 | * 200 | * @param animated If set to YES the HUD will disappear using the current animationType. If set to NO the HUD will not use 201 | * animations while disappearing. 202 | * 203 | * @see animationType 204 | */ 205 | - (void)hide:(BOOL)animated; 206 | 207 | /** 208 | * Hide the HUD after a delay. This still calls the hudWasHidden: delegate. This is the counterpart of the show: method. Use it to 209 | * hide the HUD when your task completes. 210 | * 211 | * @param animated If set to YES the HUD will disappear using the current animationType. If set to NO the HUD will not use 212 | * animations while disappearing. 213 | * @param delay Delay in seconds until the HUD is hidden. 214 | * 215 | * @see animationType 216 | */ 217 | - (void)hide:(BOOL)animated afterDelay:(NSTimeInterval)delay; 218 | 219 | /** 220 | * Shows the HUD while a background task is executing in a new thread, then hides the HUD. 221 | * 222 | * This method also takes care of autorelease pools so your method does not have to be concerned with setting up a 223 | * pool. 224 | * 225 | * @param method The method to be executed while the HUD is shown. This method will be executed in a new thread. 226 | * @param target The object that the target method belongs to. 227 | * @param object An optional object to be passed to the method. 228 | * @param animated If set to YES the HUD will (dis)appear using the current animationType. If set to NO the HUD will not use 229 | * animations while (dis)appearing. 230 | */ 231 | - (void)showWhileExecuting:(SEL)method onTarget:(id)target withObject:(id)object animated:(BOOL)animated; 232 | 233 | #if NS_BLOCKS_AVAILABLE 234 | 235 | /** 236 | * Shows the HUD while a block is executing on a background queue, then hides the HUD. 237 | * 238 | * @see showAnimated:whileExecutingBlock:onQueue:completionBlock: 239 | */ 240 | - (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block; 241 | 242 | /** 243 | * Shows the HUD while a block is executing on a background queue, then hides the HUD. 244 | * 245 | * @see showAnimated:whileExecutingBlock:onQueue:completionBlock: 246 | */ 247 | - (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block completionBlock:(MBProgressHUDCompletionBlock)completion; 248 | 249 | /** 250 | * Shows the HUD while a block is executing on the specified dispatch queue, then hides the HUD. 251 | * 252 | * @see showAnimated:whileExecutingBlock:onQueue:completionBlock: 253 | */ 254 | - (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block onQueue:(dispatch_queue_t)queue; 255 | 256 | /** 257 | * Shows the HUD while a block is executing on the specified dispatch queue, executes completion block on the main queue, and then hides the HUD. 258 | * 259 | * @param animated If set to YES the HUD will (dis)appear using the current animationType. If set to NO the HUD will 260 | * not use animations while (dis)appearing. 261 | * @param block The block to be executed while the HUD is shown. 262 | * @param queue The dispatch queue on which the block should be executed. 263 | * @param completion The block to be executed on completion. 264 | * 265 | * @see completionBlock 266 | */ 267 | - (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block onQueue:(dispatch_queue_t)queue 268 | completionBlock:(MBProgressHUDCompletionBlock)completion; 269 | 270 | /** 271 | * A block that gets called after the HUD was completely hidden. 272 | */ 273 | @property (copy) MBProgressHUDCompletionBlock completionBlock; 274 | 275 | #endif 276 | 277 | /** 278 | * MBProgressHUD operation mode. The default is MBProgressHUDModeIndeterminate. 279 | * 280 | * @see MBProgressHUDMode 281 | */ 282 | @property (assign) MBProgressHUDMode mode; 283 | 284 | /** 285 | * The animation type that should be used when the HUD is shown and hidden. 286 | * 287 | * @see MBProgressHUDAnimation 288 | */ 289 | @property (assign) MBProgressHUDAnimation animationType; 290 | 291 | /** 292 | * The UIView (e.g., a UIImageView) to be shown when the HUD is in MBProgressHUDModeCustomView. 293 | * For best results use a 37 by 37 pixel view (so the bounds match the built in indicator bounds). 294 | */ 295 | @property (MB_STRONG) UIView *customView; 296 | 297 | /** 298 | * The HUD delegate object. 299 | * 300 | * @see MBProgressHUDDelegate 301 | */ 302 | @property (MB_WEAK) id delegate; 303 | 304 | /** 305 | * An optional short message to be displayed below the activity indicator. The HUD is automatically resized to fit 306 | * the entire text. If the text is too long it will get clipped by displaying "..." at the end. If left unchanged or 307 | * set to @"", then no message is displayed. 308 | */ 309 | @property (copy) NSString *labelText; 310 | 311 | /** 312 | * An optional details message displayed below the labelText message. This message is displayed only if the labelText 313 | * property is also set and is different from an empty string (@""). The details text can span multiple lines. 314 | */ 315 | @property (copy) NSString *detailsLabelText; 316 | 317 | /** 318 | * The opacity of the HUD window. Defaults to 0.8 (80% opacity). 319 | */ 320 | @property (assign) float opacity; 321 | 322 | /** 323 | * The color of the HUD window. Defaults to black. If this property is set, color is set using 324 | * this UIColor and the opacity property is not used. using retain because performing copy on 325 | * UIColor base colors (like [UIColor greenColor]) cause problems with the copyZone. 326 | */ 327 | @property (MB_STRONG) UIColor *color; 328 | 329 | /** 330 | * The x-axis offset of the HUD relative to the centre of the superview. 331 | */ 332 | @property (assign) float xOffset; 333 | 334 | /** 335 | * The y-axis offset of the HUD relative to the centre of the superview. 336 | */ 337 | @property (assign) float yOffset; 338 | 339 | /** 340 | * The amount of space between the HUD edge and the HUD elements (labels, indicators or custom views). 341 | * Defaults to 20.0 342 | */ 343 | @property (assign) float margin; 344 | 345 | /** 346 | * The corner radius for the HUD 347 | * Defaults to 10.0 348 | */ 349 | @property (assign) float cornerRadius; 350 | 351 | /** 352 | * Cover the HUD background view with a radial gradient. 353 | */ 354 | @property (assign) BOOL dimBackground; 355 | 356 | /* 357 | * Grace period is the time (in seconds) that the invoked method may be run without 358 | * showing the HUD. If the task finishes before the grace time runs out, the HUD will 359 | * not be shown at all. 360 | * This may be used to prevent HUD display for very short tasks. 361 | * Defaults to 0 (no grace time). 362 | * Grace time functionality is only supported when the task status is known! 363 | * @see taskInProgress 364 | */ 365 | @property (assign) float graceTime; 366 | 367 | /** 368 | * The minimum time (in seconds) that the HUD is shown. 369 | * This avoids the problem of the HUD being shown and than instantly hidden. 370 | * Defaults to 0 (no minimum show time). 371 | */ 372 | @property (assign) float minShowTime; 373 | 374 | /** 375 | * Indicates that the executed operation is in progress. Needed for correct graceTime operation. 376 | * If you don't set a graceTime (different than 0.0) this does nothing. 377 | * This property is automatically set when using showWhileExecuting:onTarget:withObject:animated:. 378 | * When threading is done outside of the HUD (i.e., when the show: and hide: methods are used directly), 379 | * you need to set this property when your task starts and completes in order to have normal graceTime 380 | * functionality. 381 | */ 382 | @property (assign) BOOL taskInProgress; 383 | 384 | /** 385 | * Removes the HUD from its parent view when hidden. 386 | * Defaults to NO. 387 | */ 388 | @property (assign) BOOL removeFromSuperViewOnHide; 389 | 390 | /** 391 | * Font to be used for the main label. Set this property if the default is not adequate. 392 | */ 393 | @property (MB_STRONG) UIFont* labelFont; 394 | 395 | /** 396 | * Color to be used for the main label. Set this property if the default is not adequate. 397 | */ 398 | @property (MB_STRONG) UIColor* labelColor; 399 | 400 | /** 401 | * Font to be used for the details label. Set this property if the default is not adequate. 402 | */ 403 | @property (MB_STRONG) UIFont* detailsLabelFont; 404 | 405 | /** 406 | * Color to be used for the details label. Set this property if the default is not adequate. 407 | */ 408 | @property (MB_STRONG) UIColor* detailsLabelColor; 409 | 410 | /** 411 | * The color of the activity indicator. Defaults to [UIColor whiteColor] 412 | * Does nothing on pre iOS 5. 413 | */ 414 | @property (MB_STRONG) UIColor *activityIndicatorColor; 415 | 416 | /** 417 | * The progress of the progress indicator, from 0.0 to 1.0. Defaults to 0.0. 418 | */ 419 | @property (assign) float progress; 420 | 421 | /** 422 | * The minimum size of the HUD bezel. Defaults to CGSizeZero (no minimum size). 423 | */ 424 | @property (assign) CGSize minSize; 425 | 426 | 427 | /** 428 | * The actual size of the HUD bezel. 429 | * You can use this to limit touch handling on the bezel aria only. 430 | * @see https://github.com/jdg/MBProgressHUD/pull/200 431 | */ 432 | @property (atomic, assign, readonly) CGSize size; 433 | 434 | 435 | /** 436 | * Force the HUD dimensions to be equal if possible. 437 | */ 438 | @property (assign, getter = isSquare) BOOL square; 439 | 440 | @end 441 | 442 | 443 | @protocol MBProgressHUDDelegate 444 | 445 | @optional 446 | 447 | /** 448 | * Called after the HUD was fully hidden from the screen. 449 | */ 450 | - (void)hudWasHidden:(MBProgressHUD *)hud; 451 | 452 | @end 453 | 454 | 455 | /** 456 | * A progress view for showing definite progress by filling up a circle (pie chart). 457 | */ 458 | @interface MBRoundProgressView : UIView 459 | 460 | /** 461 | * Progress (0.0 to 1.0) 462 | */ 463 | @property (nonatomic, assign) float progress; 464 | 465 | /** 466 | * Indicator progress color. 467 | * Defaults to white [UIColor whiteColor] 468 | */ 469 | @property (nonatomic, MB_STRONG) UIColor *progressTintColor; 470 | 471 | /** 472 | * Indicator background (non-progress) color. 473 | * Defaults to translucent white (alpha 0.1) 474 | */ 475 | @property (nonatomic, MB_STRONG) UIColor *backgroundTintColor; 476 | 477 | /* 478 | * Display mode - NO = round or YES = annular. Defaults to round. 479 | */ 480 | @property (nonatomic, assign, getter = isAnnular) BOOL annular; 481 | 482 | @end 483 | 484 | 485 | /** 486 | * A flat bar progress view. 487 | */ 488 | @interface MBBarProgressView : UIView 489 | 490 | /** 491 | * Progress (0.0 to 1.0) 492 | */ 493 | @property (nonatomic, assign) float progress; 494 | 495 | /** 496 | * Bar border line color. 497 | * Defaults to white [UIColor whiteColor]. 498 | */ 499 | @property (nonatomic, MB_STRONG) UIColor *lineColor; 500 | 501 | /** 502 | * Bar background color. 503 | * Defaults to clear [UIColor clearColor]; 504 | */ 505 | @property (nonatomic, MB_STRONG) UIColor *progressRemainingColor; 506 | 507 | /** 508 | * Bar progress color. 509 | * Defaults to white [UIColor whiteColor]. 510 | */ 511 | @property (nonatomic, MB_STRONG) UIColor *progressColor; 512 | 513 | @end 514 | -------------------------------------------------------------------------------- /AliPayDemo/MBProgressHUD.m: -------------------------------------------------------------------------------- 1 | // 2 | // MBProgressHUD.m 3 | // Version 0.9.1 4 | // Created by Matej Bukovinski on 2.4.09. 5 | // 6 | 7 | #import "MBProgressHUD.h" 8 | #import 9 | 10 | 11 | #if __has_feature(objc_arc) 12 | #define MB_AUTORELEASE(exp) exp 13 | #define MB_RELEASE(exp) exp 14 | #define MB_RETAIN(exp) exp 15 | #else 16 | #define MB_AUTORELEASE(exp) [exp autorelease] 17 | #define MB_RELEASE(exp) [exp release] 18 | #define MB_RETAIN(exp) [exp retain] 19 | #endif 20 | 21 | #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000 22 | #define MBLabelAlignmentCenter NSTextAlignmentCenter 23 | #else 24 | #define MBLabelAlignmentCenter UITextAlignmentCenter 25 | #endif 26 | 27 | #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000 28 | #define MB_TEXTSIZE(text, font) [text length] > 0 ? [text \ 29 | sizeWithAttributes:@{NSFontAttributeName:font}] : CGSizeZero; 30 | #else 31 | #define MB_TEXTSIZE(text, font) [text length] > 0 ? [text sizeWithFont:font] : CGSizeZero; 32 | #endif 33 | 34 | #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000 35 | #define MB_MULTILINE_TEXTSIZE(text, font, maxSize, mode) [text length] > 0 ? [text \ 36 | boundingRectWithSize:maxSize options:(NSStringDrawingUsesLineFragmentOrigin) \ 37 | attributes:@{NSFontAttributeName:font} context:nil].size : CGSizeZero; 38 | #else 39 | #define MB_MULTILINE_TEXTSIZE(text, font, maxSize, mode) [text length] > 0 ? [text \ 40 | sizeWithFont:font constrainedToSize:maxSize lineBreakMode:mode] : CGSizeZero; 41 | #endif 42 | 43 | #ifndef kCFCoreFoundationVersionNumber_iOS_7_0 44 | #define kCFCoreFoundationVersionNumber_iOS_7_0 847.20 45 | #endif 46 | 47 | #ifndef kCFCoreFoundationVersionNumber_iOS_8_0 48 | #define kCFCoreFoundationVersionNumber_iOS_8_0 1129.15 49 | #endif 50 | 51 | 52 | static const CGFloat kPadding = 4.f; 53 | static const CGFloat kLabelFontSize = 16.f; 54 | static const CGFloat kDetailsLabelFontSize = 12.f; 55 | 56 | 57 | @interface MBProgressHUD () { 58 | BOOL useAnimation; 59 | SEL methodForExecution; 60 | id targetForExecution; 61 | id objectForExecution; 62 | UILabel *label; 63 | UILabel *detailsLabel; 64 | BOOL isFinished; 65 | CGAffineTransform rotationTransform; 66 | } 67 | 68 | @property (atomic, MB_STRONG) UIView *indicator; 69 | @property (atomic, MB_STRONG) NSTimer *graceTimer; 70 | @property (atomic, MB_STRONG) NSTimer *minShowTimer; 71 | @property (atomic, MB_STRONG) NSDate *showStarted; 72 | 73 | @end 74 | 75 | 76 | @implementation MBProgressHUD 77 | 78 | #pragma mark - Properties 79 | 80 | @synthesize animationType; 81 | @synthesize delegate; 82 | @synthesize opacity; 83 | @synthesize color; 84 | @synthesize labelFont; 85 | @synthesize labelColor; 86 | @synthesize detailsLabelFont; 87 | @synthesize detailsLabelColor; 88 | @synthesize indicator; 89 | @synthesize xOffset; 90 | @synthesize yOffset; 91 | @synthesize minSize; 92 | @synthesize square; 93 | @synthesize margin; 94 | @synthesize dimBackground; 95 | @synthesize graceTime; 96 | @synthesize minShowTime; 97 | @synthesize graceTimer; 98 | @synthesize minShowTimer; 99 | @synthesize taskInProgress; 100 | @synthesize removeFromSuperViewOnHide; 101 | @synthesize customView; 102 | @synthesize showStarted; 103 | @synthesize mode; 104 | @synthesize labelText; 105 | @synthesize detailsLabelText; 106 | @synthesize progress; 107 | @synthesize size; 108 | @synthesize activityIndicatorColor; 109 | #if NS_BLOCKS_AVAILABLE 110 | @synthesize completionBlock; 111 | #endif 112 | 113 | #pragma mark - Class methods 114 | 115 | + (MB_INSTANCETYPE)showHUDAddedTo:(UIView *)view animated:(BOOL)animated { 116 | MBProgressHUD *hud = [[self alloc] initWithView:view]; 117 | hud.removeFromSuperViewOnHide = YES; 118 | [view addSubview:hud]; 119 | [hud show:animated]; 120 | return MB_AUTORELEASE(hud); 121 | } 122 | 123 | + (BOOL)hideHUDForView:(UIView *)view animated:(BOOL)animated { 124 | MBProgressHUD *hud = [self HUDForView:view]; 125 | if (hud != nil) { 126 | hud.removeFromSuperViewOnHide = YES; 127 | [hud hide:animated]; 128 | return YES; 129 | } 130 | return NO; 131 | } 132 | 133 | + (NSUInteger)hideAllHUDsForView:(UIView *)view animated:(BOOL)animated { 134 | NSArray *huds = [MBProgressHUD allHUDsForView:view]; 135 | for (MBProgressHUD *hud in huds) { 136 | hud.removeFromSuperViewOnHide = YES; 137 | [hud hide:animated]; 138 | } 139 | return [huds count]; 140 | } 141 | 142 | + (MB_INSTANCETYPE)HUDForView:(UIView *)view { 143 | NSEnumerator *subviewsEnum = [view.subviews reverseObjectEnumerator]; 144 | for (UIView *subview in subviewsEnum) { 145 | if ([subview isKindOfClass:self]) { 146 | return (MBProgressHUD *)subview; 147 | } 148 | } 149 | return nil; 150 | } 151 | 152 | + (NSArray *)allHUDsForView:(UIView *)view { 153 | NSMutableArray *huds = [NSMutableArray array]; 154 | NSArray *subviews = view.subviews; 155 | for (UIView *aView in subviews) { 156 | if ([aView isKindOfClass:self]) { 157 | [huds addObject:aView]; 158 | } 159 | } 160 | return [NSArray arrayWithArray:huds]; 161 | } 162 | 163 | #pragma mark - Lifecycle 164 | 165 | - (id)initWithFrame:(CGRect)frame { 166 | self = [super initWithFrame:frame]; 167 | if (self) { 168 | // Set default values for properties 169 | self.animationType = MBProgressHUDAnimationFade; 170 | self.mode = MBProgressHUDModeIndeterminate; 171 | self.labelText = nil; 172 | self.detailsLabelText = nil; 173 | self.opacity = 0.8f; 174 | self.color = nil; 175 | self.labelFont = [UIFont boldSystemFontOfSize:kLabelFontSize]; 176 | self.labelColor = [UIColor whiteColor]; 177 | self.detailsLabelFont = [UIFont boldSystemFontOfSize:kDetailsLabelFontSize]; 178 | self.detailsLabelColor = [UIColor whiteColor]; 179 | self.activityIndicatorColor = [UIColor whiteColor]; 180 | self.xOffset = 0.0f; 181 | self.yOffset = 0.0f; 182 | self.dimBackground = NO; 183 | self.margin = 20.0f; 184 | self.cornerRadius = 10.0f; 185 | self.graceTime = 0.0f; 186 | self.minShowTime = 0.0f; 187 | self.removeFromSuperViewOnHide = NO; 188 | self.minSize = CGSizeZero; 189 | self.square = NO; 190 | self.contentMode = UIViewContentModeCenter; 191 | self.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin 192 | | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; 193 | 194 | // Transparent background 195 | self.opaque = NO; 196 | self.backgroundColor = [UIColor clearColor]; 197 | // Make it invisible for now 198 | self.alpha = 0.0f; 199 | 200 | taskInProgress = NO; 201 | rotationTransform = CGAffineTransformIdentity; 202 | 203 | [self setupLabels]; 204 | [self updateIndicators]; 205 | [self registerForKVO]; 206 | [self registerForNotifications]; 207 | } 208 | return self; 209 | } 210 | 211 | - (id)initWithView:(UIView *)view { 212 | NSAssert(view, @"View must not be nil."); 213 | return [self initWithFrame:view.bounds]; 214 | } 215 | 216 | - (id)initWithWindow:(UIWindow *)window { 217 | return [self initWithView:window]; 218 | } 219 | 220 | - (void)dealloc { 221 | [self unregisterFromNotifications]; 222 | [self unregisterFromKVO]; 223 | #if !__has_feature(objc_arc) 224 | [color release]; 225 | [indicator release]; 226 | [label release]; 227 | [detailsLabel release]; 228 | [labelText release]; 229 | [detailsLabelText release]; 230 | [graceTimer release]; 231 | [minShowTimer release]; 232 | [showStarted release]; 233 | [customView release]; 234 | [labelFont release]; 235 | [labelColor release]; 236 | [detailsLabelFont release]; 237 | [detailsLabelColor release]; 238 | #if NS_BLOCKS_AVAILABLE 239 | [completionBlock release]; 240 | #endif 241 | [super dealloc]; 242 | #endif 243 | } 244 | 245 | #pragma mark - Show & hide 246 | 247 | - (void)show:(BOOL)animated { 248 | useAnimation = animated; 249 | // If the grace time is set postpone the HUD display 250 | if (self.graceTime > 0.0) { 251 | self.graceTimer = [NSTimer scheduledTimerWithTimeInterval:self.graceTime target:self 252 | selector:@selector(handleGraceTimer:) userInfo:nil repeats:NO]; 253 | } 254 | // ... otherwise show the HUD imediately 255 | else { 256 | [self showUsingAnimation:useAnimation]; 257 | } 258 | } 259 | 260 | - (void)hide:(BOOL)animated { 261 | useAnimation = animated; 262 | // If the minShow time is set, calculate how long the hud was shown, 263 | // and pospone the hiding operation if necessary 264 | if (self.minShowTime > 0.0 && showStarted) { 265 | NSTimeInterval interv = [[NSDate date] timeIntervalSinceDate:showStarted]; 266 | if (interv < self.minShowTime) { 267 | self.minShowTimer = [NSTimer scheduledTimerWithTimeInterval:(self.minShowTime - interv) target:self 268 | selector:@selector(handleMinShowTimer:) userInfo:nil repeats:NO]; 269 | return; 270 | } 271 | } 272 | // ... otherwise hide the HUD immediately 273 | [self hideUsingAnimation:useAnimation]; 274 | } 275 | 276 | - (void)hide:(BOOL)animated afterDelay:(NSTimeInterval)delay { 277 | [self performSelector:@selector(hideDelayed:) withObject:[NSNumber numberWithBool:animated] afterDelay:delay]; 278 | } 279 | 280 | - (void)hideDelayed:(NSNumber *)animated { 281 | [self hide:[animated boolValue]]; 282 | } 283 | 284 | #pragma mark - Timer callbacks 285 | 286 | - (void)handleGraceTimer:(NSTimer *)theTimer { 287 | // Show the HUD only if the task is still running 288 | if (taskInProgress) { 289 | [self showUsingAnimation:useAnimation]; 290 | } 291 | } 292 | 293 | - (void)handleMinShowTimer:(NSTimer *)theTimer { 294 | [self hideUsingAnimation:useAnimation]; 295 | } 296 | 297 | #pragma mark - View Hierrarchy 298 | 299 | - (void)didMoveToSuperview { 300 | [self updateForCurrentOrientationAnimated:NO]; 301 | } 302 | 303 | #pragma mark - Internal show & hide operations 304 | 305 | - (void)showUsingAnimation:(BOOL)animated { 306 | // Cancel any scheduled hideDelayed: calls 307 | [NSObject cancelPreviousPerformRequestsWithTarget:self]; 308 | [self setNeedsDisplay]; 309 | 310 | if (animated && animationType == MBProgressHUDAnimationZoomIn) { 311 | self.transform = CGAffineTransformConcat(rotationTransform, CGAffineTransformMakeScale(0.5f, 0.5f)); 312 | } else if (animated && animationType == MBProgressHUDAnimationZoomOut) { 313 | self.transform = CGAffineTransformConcat(rotationTransform, CGAffineTransformMakeScale(1.5f, 1.5f)); 314 | } 315 | self.showStarted = [NSDate date]; 316 | // Fade in 317 | if (animated) { 318 | [UIView beginAnimations:nil context:NULL]; 319 | [UIView setAnimationDuration:0.30]; 320 | self.alpha = 1.0f; 321 | if (animationType == MBProgressHUDAnimationZoomIn || animationType == MBProgressHUDAnimationZoomOut) { 322 | self.transform = rotationTransform; 323 | } 324 | [UIView commitAnimations]; 325 | } 326 | else { 327 | self.alpha = 1.0f; 328 | } 329 | } 330 | 331 | - (void)hideUsingAnimation:(BOOL)animated { 332 | // Fade out 333 | if (animated && showStarted) { 334 | [UIView beginAnimations:nil context:NULL]; 335 | [UIView setAnimationDuration:0.30]; 336 | [UIView setAnimationDelegate:self]; 337 | [UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)]; 338 | // 0.02 prevents the hud from passing through touches during the animation the hud will get completely hidden 339 | // in the done method 340 | if (animationType == MBProgressHUDAnimationZoomIn) { 341 | self.transform = CGAffineTransformConcat(rotationTransform, CGAffineTransformMakeScale(1.5f, 1.5f)); 342 | } else if (animationType == MBProgressHUDAnimationZoomOut) { 343 | self.transform = CGAffineTransformConcat(rotationTransform, CGAffineTransformMakeScale(0.5f, 0.5f)); 344 | } 345 | 346 | self.alpha = 0.02f; 347 | [UIView commitAnimations]; 348 | } 349 | else { 350 | self.alpha = 0.0f; 351 | [self done]; 352 | } 353 | self.showStarted = nil; 354 | } 355 | 356 | - (void)animationFinished:(NSString *)animationID finished:(BOOL)finished context:(void*)context { 357 | [self done]; 358 | } 359 | 360 | - (void)done { 361 | [NSObject cancelPreviousPerformRequestsWithTarget:self]; 362 | isFinished = YES; 363 | self.alpha = 0.0f; 364 | if (removeFromSuperViewOnHide) { 365 | [self removeFromSuperview]; 366 | } 367 | #if NS_BLOCKS_AVAILABLE 368 | if (self.completionBlock) { 369 | self.completionBlock(); 370 | self.completionBlock = NULL; 371 | } 372 | #endif 373 | if ([delegate respondsToSelector:@selector(hudWasHidden:)]) { 374 | [delegate performSelector:@selector(hudWasHidden:) withObject:self]; 375 | } 376 | } 377 | 378 | #pragma mark - Threading 379 | 380 | - (void)showWhileExecuting:(SEL)method onTarget:(id)target withObject:(id)object animated:(BOOL)animated { 381 | methodForExecution = method; 382 | targetForExecution = MB_RETAIN(target); 383 | objectForExecution = MB_RETAIN(object); 384 | // Launch execution in new thread 385 | self.taskInProgress = YES; 386 | [NSThread detachNewThreadSelector:@selector(launchExecution) toTarget:self withObject:nil]; 387 | // Show HUD view 388 | [self show:animated]; 389 | } 390 | 391 | #if NS_BLOCKS_AVAILABLE 392 | 393 | - (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block { 394 | dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); 395 | [self showAnimated:animated whileExecutingBlock:block onQueue:queue completionBlock:NULL]; 396 | } 397 | 398 | - (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block completionBlock:(void (^)())completion { 399 | dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); 400 | [self showAnimated:animated whileExecutingBlock:block onQueue:queue completionBlock:completion]; 401 | } 402 | 403 | - (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block onQueue:(dispatch_queue_t)queue { 404 | [self showAnimated:animated whileExecutingBlock:block onQueue:queue completionBlock:NULL]; 405 | } 406 | 407 | - (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block onQueue:(dispatch_queue_t)queue 408 | completionBlock:(MBProgressHUDCompletionBlock)completion { 409 | self.taskInProgress = YES; 410 | self.completionBlock = completion; 411 | dispatch_async(queue, ^(void) { 412 | block(); 413 | dispatch_async(dispatch_get_main_queue(), ^(void) { 414 | [self cleanUp]; 415 | }); 416 | }); 417 | [self show:animated]; 418 | } 419 | 420 | #endif 421 | 422 | - (void)launchExecution { 423 | @autoreleasepool { 424 | #pragma clang diagnostic push 425 | #pragma clang diagnostic ignored "-Warc-performSelector-leaks" 426 | // Start executing the requested task 427 | [targetForExecution performSelector:methodForExecution withObject:objectForExecution]; 428 | #pragma clang diagnostic pop 429 | // Task completed, update view in main thread (note: view operations should 430 | // be done only in the main thread) 431 | [self performSelectorOnMainThread:@selector(cleanUp) withObject:nil waitUntilDone:NO]; 432 | } 433 | } 434 | 435 | - (void)cleanUp { 436 | taskInProgress = NO; 437 | #if !__has_feature(objc_arc) 438 | [targetForExecution release]; 439 | [objectForExecution release]; 440 | #else 441 | targetForExecution = nil; 442 | objectForExecution = nil; 443 | #endif 444 | [self hide:useAnimation]; 445 | } 446 | 447 | #pragma mark - UI 448 | 449 | - (void)setupLabels { 450 | label = [[UILabel alloc] initWithFrame:self.bounds]; 451 | label.adjustsFontSizeToFitWidth = NO; 452 | label.textAlignment = MBLabelAlignmentCenter; 453 | label.opaque = NO; 454 | label.backgroundColor = [UIColor clearColor]; 455 | label.textColor = self.labelColor; 456 | label.font = self.labelFont; 457 | label.text = self.labelText; 458 | [self addSubview:label]; 459 | 460 | detailsLabel = [[UILabel alloc] initWithFrame:self.bounds]; 461 | detailsLabel.font = self.detailsLabelFont; 462 | detailsLabel.adjustsFontSizeToFitWidth = NO; 463 | detailsLabel.textAlignment = MBLabelAlignmentCenter; 464 | detailsLabel.opaque = NO; 465 | detailsLabel.backgroundColor = [UIColor clearColor]; 466 | detailsLabel.textColor = self.detailsLabelColor; 467 | detailsLabel.numberOfLines = 0; 468 | detailsLabel.font = self.detailsLabelFont; 469 | detailsLabel.text = self.detailsLabelText; 470 | [self addSubview:detailsLabel]; 471 | } 472 | 473 | - (void)updateIndicators { 474 | 475 | BOOL isActivityIndicator = [indicator isKindOfClass:[UIActivityIndicatorView class]]; 476 | BOOL isRoundIndicator = [indicator isKindOfClass:[MBRoundProgressView class]]; 477 | 478 | if (mode == MBProgressHUDModeIndeterminate) { 479 | if (!isActivityIndicator) { 480 | // Update to indeterminate indicator 481 | [indicator removeFromSuperview]; 482 | self.indicator = MB_AUTORELEASE([[UIActivityIndicatorView alloc] 483 | initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]); 484 | [(UIActivityIndicatorView *)indicator startAnimating]; 485 | [self addSubview:indicator]; 486 | } 487 | #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 50000 488 | [(UIActivityIndicatorView *)indicator setColor:self.activityIndicatorColor]; 489 | #endif 490 | } 491 | else if (mode == MBProgressHUDModeDeterminateHorizontalBar) { 492 | // Update to bar determinate indicator 493 | [indicator removeFromSuperview]; 494 | self.indicator = MB_AUTORELEASE([[MBBarProgressView alloc] init]); 495 | [self addSubview:indicator]; 496 | } 497 | else if (mode == MBProgressHUDModeDeterminate || mode == MBProgressHUDModeAnnularDeterminate) { 498 | if (!isRoundIndicator) { 499 | // Update to determinante indicator 500 | [indicator removeFromSuperview]; 501 | self.indicator = MB_AUTORELEASE([[MBRoundProgressView alloc] init]); 502 | [self addSubview:indicator]; 503 | } 504 | if (mode == MBProgressHUDModeAnnularDeterminate) { 505 | [(MBRoundProgressView *)indicator setAnnular:YES]; 506 | } 507 | } 508 | else if (mode == MBProgressHUDModeCustomView && customView != indicator) { 509 | // Update custom view indicator 510 | [indicator removeFromSuperview]; 511 | self.indicator = customView; 512 | [self addSubview:indicator]; 513 | } else if (mode == MBProgressHUDModeText) { 514 | [indicator removeFromSuperview]; 515 | self.indicator = nil; 516 | } 517 | } 518 | 519 | #pragma mark - Layout 520 | 521 | - (void)layoutSubviews { 522 | [super layoutSubviews]; 523 | 524 | // Entirely cover the parent view 525 | UIView *parent = self.superview; 526 | if (parent) { 527 | self.frame = parent.bounds; 528 | } 529 | CGRect bounds = self.bounds; 530 | 531 | // Determine the total widt and height needed 532 | CGFloat maxWidth = bounds.size.width - 4 * margin; 533 | CGSize totalSize = CGSizeZero; 534 | 535 | CGRect indicatorF = indicator.bounds; 536 | indicatorF.size.width = MIN(indicatorF.size.width, maxWidth); 537 | totalSize.width = MAX(totalSize.width, indicatorF.size.width); 538 | totalSize.height += indicatorF.size.height; 539 | 540 | CGSize labelSize = MB_TEXTSIZE(label.text, label.font); 541 | labelSize.width = MIN(labelSize.width, maxWidth); 542 | totalSize.width = MAX(totalSize.width, labelSize.width); 543 | totalSize.height += labelSize.height; 544 | if (labelSize.height > 0.f && indicatorF.size.height > 0.f) { 545 | totalSize.height += kPadding; 546 | } 547 | 548 | CGFloat remainingHeight = bounds.size.height - totalSize.height - kPadding - 4 * margin; 549 | CGSize maxSize = CGSizeMake(maxWidth, remainingHeight); 550 | CGSize detailsLabelSize = MB_MULTILINE_TEXTSIZE(detailsLabel.text, detailsLabel.font, maxSize, detailsLabel.lineBreakMode); 551 | totalSize.width = MAX(totalSize.width, detailsLabelSize.width); 552 | totalSize.height += detailsLabelSize.height; 553 | if (detailsLabelSize.height > 0.f && (indicatorF.size.height > 0.f || labelSize.height > 0.f)) { 554 | totalSize.height += kPadding; 555 | } 556 | 557 | totalSize.width += 2 * margin; 558 | totalSize.height += 2 * margin; 559 | 560 | // Position elements 561 | CGFloat yPos = round(((bounds.size.height - totalSize.height) / 2)) + margin + yOffset; 562 | CGFloat xPos = xOffset; 563 | indicatorF.origin.y = yPos; 564 | indicatorF.origin.x = round((bounds.size.width - indicatorF.size.width) / 2) + xPos; 565 | indicator.frame = indicatorF; 566 | yPos += indicatorF.size.height; 567 | 568 | if (labelSize.height > 0.f && indicatorF.size.height > 0.f) { 569 | yPos += kPadding; 570 | } 571 | CGRect labelF; 572 | labelF.origin.y = yPos; 573 | labelF.origin.x = round((bounds.size.width - labelSize.width) / 2) + xPos; 574 | labelF.size = labelSize; 575 | label.frame = labelF; 576 | yPos += labelF.size.height; 577 | 578 | if (detailsLabelSize.height > 0.f && (indicatorF.size.height > 0.f || labelSize.height > 0.f)) { 579 | yPos += kPadding; 580 | } 581 | CGRect detailsLabelF; 582 | detailsLabelF.origin.y = yPos; 583 | detailsLabelF.origin.x = round((bounds.size.width - detailsLabelSize.width) / 2) + xPos; 584 | detailsLabelF.size = detailsLabelSize; 585 | detailsLabel.frame = detailsLabelF; 586 | 587 | // Enforce minsize and quare rules 588 | if (square) { 589 | CGFloat max = MAX(totalSize.width, totalSize.height); 590 | if (max <= bounds.size.width - 2 * margin) { 591 | totalSize.width = max; 592 | } 593 | if (max <= bounds.size.height - 2 * margin) { 594 | totalSize.height = max; 595 | } 596 | } 597 | if (totalSize.width < minSize.width) { 598 | totalSize.width = minSize.width; 599 | } 600 | if (totalSize.height < minSize.height) { 601 | totalSize.height = minSize.height; 602 | } 603 | 604 | size = totalSize; 605 | } 606 | 607 | #pragma mark BG Drawing 608 | 609 | - (void)drawRect:(CGRect)rect { 610 | 611 | CGContextRef context = UIGraphicsGetCurrentContext(); 612 | UIGraphicsPushContext(context); 613 | 614 | if (self.dimBackground) { 615 | //Gradient colours 616 | size_t gradLocationsNum = 2; 617 | CGFloat gradLocations[2] = {0.0f, 1.0f}; 618 | CGFloat gradColors[8] = {0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.75f}; 619 | CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 620 | CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, gradColors, gradLocations, gradLocationsNum); 621 | CGColorSpaceRelease(colorSpace); 622 | //Gradient center 623 | CGPoint gradCenter= CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2); 624 | //Gradient radius 625 | float gradRadius = MIN(self.bounds.size.width , self.bounds.size.height) ; 626 | //Gradient draw 627 | CGContextDrawRadialGradient (context, gradient, gradCenter, 628 | 0, gradCenter, gradRadius, 629 | kCGGradientDrawsAfterEndLocation); 630 | CGGradientRelease(gradient); 631 | } 632 | 633 | // Set background rect color 634 | if (self.color) { 635 | CGContextSetFillColorWithColor(context, self.color.CGColor); 636 | } else { 637 | CGContextSetGrayFillColor(context, 0.0f, self.opacity); 638 | } 639 | 640 | 641 | // Center HUD 642 | CGRect allRect = self.bounds; 643 | // Draw rounded HUD backgroud rect 644 | CGRect boxRect = CGRectMake(round((allRect.size.width - size.width) / 2) + self.xOffset, 645 | round((allRect.size.height - size.height) / 2) + self.yOffset, size.width, size.height); 646 | float radius = self.cornerRadius; 647 | CGContextBeginPath(context); 648 | CGContextMoveToPoint(context, CGRectGetMinX(boxRect) + radius, CGRectGetMinY(boxRect)); 649 | CGContextAddArc(context, CGRectGetMaxX(boxRect) - radius, CGRectGetMinY(boxRect) + radius, radius, 3 * (float)M_PI / 2, 0, 0); 650 | CGContextAddArc(context, CGRectGetMaxX(boxRect) - radius, CGRectGetMaxY(boxRect) - radius, radius, 0, (float)M_PI / 2, 0); 651 | CGContextAddArc(context, CGRectGetMinX(boxRect) + radius, CGRectGetMaxY(boxRect) - radius, radius, (float)M_PI / 2, (float)M_PI, 0); 652 | CGContextAddArc(context, CGRectGetMinX(boxRect) + radius, CGRectGetMinY(boxRect) + radius, radius, (float)M_PI, 3 * (float)M_PI / 2, 0); 653 | CGContextClosePath(context); 654 | CGContextFillPath(context); 655 | 656 | UIGraphicsPopContext(); 657 | } 658 | 659 | #pragma mark - KVO 660 | 661 | - (void)registerForKVO { 662 | for (NSString *keyPath in [self observableKeypaths]) { 663 | [self addObserver:self forKeyPath:keyPath options:NSKeyValueObservingOptionNew context:NULL]; 664 | } 665 | } 666 | 667 | - (void)unregisterFromKVO { 668 | for (NSString *keyPath in [self observableKeypaths]) { 669 | [self removeObserver:self forKeyPath:keyPath]; 670 | } 671 | } 672 | 673 | - (NSArray *)observableKeypaths { 674 | return [NSArray arrayWithObjects:@"mode", @"customView", @"labelText", @"labelFont", @"labelColor", 675 | @"detailsLabelText", @"detailsLabelFont", @"detailsLabelColor", @"progress", @"activityIndicatorColor", nil]; 676 | } 677 | 678 | - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { 679 | if (![NSThread isMainThread]) { 680 | [self performSelectorOnMainThread:@selector(updateUIForKeypath:) withObject:keyPath waitUntilDone:NO]; 681 | } else { 682 | [self updateUIForKeypath:keyPath]; 683 | } 684 | } 685 | 686 | - (void)updateUIForKeypath:(NSString *)keyPath { 687 | if ([keyPath isEqualToString:@"mode"] || [keyPath isEqualToString:@"customView"] || 688 | [keyPath isEqualToString:@"activityIndicatorColor"]) { 689 | [self updateIndicators]; 690 | } else if ([keyPath isEqualToString:@"labelText"]) { 691 | label.text = self.labelText; 692 | } else if ([keyPath isEqualToString:@"labelFont"]) { 693 | label.font = self.labelFont; 694 | } else if ([keyPath isEqualToString:@"labelColor"]) { 695 | label.textColor = self.labelColor; 696 | } else if ([keyPath isEqualToString:@"detailsLabelText"]) { 697 | detailsLabel.text = self.detailsLabelText; 698 | } else if ([keyPath isEqualToString:@"detailsLabelFont"]) { 699 | detailsLabel.font = self.detailsLabelFont; 700 | } else if ([keyPath isEqualToString:@"detailsLabelColor"]) { 701 | detailsLabel.textColor = self.detailsLabelColor; 702 | } else if ([keyPath isEqualToString:@"progress"]) { 703 | if ([indicator respondsToSelector:@selector(setProgress:)]) { 704 | [(id)indicator setValue:@(progress) forKey:@"progress"]; 705 | } 706 | return; 707 | } 708 | [self setNeedsLayout]; 709 | [self setNeedsDisplay]; 710 | } 711 | 712 | #pragma mark - Notifications 713 | 714 | - (void)registerForNotifications { 715 | NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; 716 | 717 | [nc addObserver:self selector:@selector(statusBarOrientationDidChange:) 718 | name:UIApplicationDidChangeStatusBarOrientationNotification object:nil]; 719 | } 720 | 721 | - (void)unregisterFromNotifications { 722 | NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; 723 | [nc removeObserver:self name:UIApplicationDidChangeStatusBarOrientationNotification object:nil]; 724 | } 725 | 726 | - (void)statusBarOrientationDidChange:(NSNotification *)notification { 727 | UIView *superview = self.superview; 728 | if (!superview) { 729 | return; 730 | } else { 731 | [self updateForCurrentOrientationAnimated:YES]; 732 | } 733 | } 734 | 735 | - (void)updateForCurrentOrientationAnimated:(BOOL)animated { 736 | // Stay in sync with the superview in any case 737 | if (self.superview) { 738 | self.bounds = self.superview.bounds; 739 | [self setNeedsDisplay]; 740 | } 741 | 742 | // Not needed on iOS 8+, compile out when the deployment target allows, 743 | // to avoid sharedApplication problems on extension targets 744 | #if __IPHONE_OS_VERSION_MIN_REQUIRED < 80000 745 | // Only needed pre iOS 7 when added to a window 746 | BOOL iOS8OrLater = kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_8_0; 747 | if (iOS8OrLater || ![self.superview isKindOfClass:[UIWindow class]]) return; 748 | 749 | UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; 750 | CGFloat radians = 0; 751 | if (UIInterfaceOrientationIsLandscape(orientation)) { 752 | if (orientation == UIInterfaceOrientationLandscapeLeft) { radians = -(CGFloat)M_PI_2; } 753 | else { radians = (CGFloat)M_PI_2; } 754 | // Window coordinates differ! 755 | self.bounds = CGRectMake(0, 0, self.bounds.size.height, self.bounds.size.width); 756 | } else { 757 | if (orientation == UIInterfaceOrientationPortraitUpsideDown) { radians = (CGFloat)M_PI; } 758 | else { radians = 0; } 759 | } 760 | rotationTransform = CGAffineTransformMakeRotation(radians); 761 | 762 | if (animated) { 763 | [UIView beginAnimations:nil context:nil]; 764 | [UIView setAnimationDuration:0.3]; 765 | } 766 | [self setTransform:rotationTransform]; 767 | if (animated) { 768 | [UIView commitAnimations]; 769 | } 770 | #endif 771 | } 772 | 773 | @end 774 | 775 | 776 | @implementation MBRoundProgressView 777 | 778 | #pragma mark - Lifecycle 779 | 780 | - (id)init { 781 | return [self initWithFrame:CGRectMake(0.f, 0.f, 37.f, 37.f)]; 782 | } 783 | 784 | - (id)initWithFrame:(CGRect)frame { 785 | self = [super initWithFrame:frame]; 786 | if (self) { 787 | self.backgroundColor = [UIColor clearColor]; 788 | self.opaque = NO; 789 | _progress = 0.f; 790 | _annular = NO; 791 | _progressTintColor = [[UIColor alloc] initWithWhite:1.f alpha:1.f]; 792 | _backgroundTintColor = [[UIColor alloc] initWithWhite:1.f alpha:.1f]; 793 | [self registerForKVO]; 794 | } 795 | return self; 796 | } 797 | 798 | - (void)dealloc { 799 | [self unregisterFromKVO]; 800 | #if !__has_feature(objc_arc) 801 | [_progressTintColor release]; 802 | [_backgroundTintColor release]; 803 | [super dealloc]; 804 | #endif 805 | } 806 | 807 | #pragma mark - Drawing 808 | 809 | - (void)drawRect:(CGRect)rect { 810 | 811 | CGRect allRect = self.bounds; 812 | CGRect circleRect = CGRectInset(allRect, 2.0f, 2.0f); 813 | CGContextRef context = UIGraphicsGetCurrentContext(); 814 | 815 | if (_annular) { 816 | // Draw background 817 | BOOL isPreiOS7 = kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iOS_7_0; 818 | CGFloat lineWidth = isPreiOS7 ? 5.f : 2.f; 819 | UIBezierPath *processBackgroundPath = [UIBezierPath bezierPath]; 820 | processBackgroundPath.lineWidth = lineWidth; 821 | processBackgroundPath.lineCapStyle = kCGLineCapButt; 822 | CGPoint center = CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2); 823 | CGFloat radius = (self.bounds.size.width - lineWidth)/2; 824 | CGFloat startAngle = - ((float)M_PI / 2); // 90 degrees 825 | CGFloat endAngle = (2 * (float)M_PI) + startAngle; 826 | [processBackgroundPath addArcWithCenter:center radius:radius startAngle:startAngle endAngle:endAngle clockwise:YES]; 827 | [_backgroundTintColor set]; 828 | [processBackgroundPath stroke]; 829 | // Draw progress 830 | UIBezierPath *processPath = [UIBezierPath bezierPath]; 831 | processPath.lineCapStyle = isPreiOS7 ? kCGLineCapRound : kCGLineCapSquare; 832 | processPath.lineWidth = lineWidth; 833 | endAngle = (self.progress * 2 * (float)M_PI) + startAngle; 834 | [processPath addArcWithCenter:center radius:radius startAngle:startAngle endAngle:endAngle clockwise:YES]; 835 | [_progressTintColor set]; 836 | [processPath stroke]; 837 | } else { 838 | // Draw background 839 | [_progressTintColor setStroke]; 840 | [_backgroundTintColor setFill]; 841 | CGContextSetLineWidth(context, 2.0f); 842 | CGContextFillEllipseInRect(context, circleRect); 843 | CGContextStrokeEllipseInRect(context, circleRect); 844 | // Draw progress 845 | CGPoint center = CGPointMake(allRect.size.width / 2, allRect.size.height / 2); 846 | CGFloat radius = (allRect.size.width - 4) / 2; 847 | CGFloat startAngle = - ((float)M_PI / 2); // 90 degrees 848 | CGFloat endAngle = (self.progress * 2 * (float)M_PI) + startAngle; 849 | [_progressTintColor setFill]; 850 | CGContextMoveToPoint(context, center.x, center.y); 851 | CGContextAddArc(context, center.x, center.y, radius, startAngle, endAngle, 0); 852 | CGContextClosePath(context); 853 | CGContextFillPath(context); 854 | } 855 | } 856 | 857 | #pragma mark - KVO 858 | 859 | - (void)registerForKVO { 860 | for (NSString *keyPath in [self observableKeypaths]) { 861 | [self addObserver:self forKeyPath:keyPath options:NSKeyValueObservingOptionNew context:NULL]; 862 | } 863 | } 864 | 865 | - (void)unregisterFromKVO { 866 | for (NSString *keyPath in [self observableKeypaths]) { 867 | [self removeObserver:self forKeyPath:keyPath]; 868 | } 869 | } 870 | 871 | - (NSArray *)observableKeypaths { 872 | return [NSArray arrayWithObjects:@"progressTintColor", @"backgroundTintColor", @"progress", @"annular", nil]; 873 | } 874 | 875 | - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { 876 | [self setNeedsDisplay]; 877 | } 878 | 879 | @end 880 | 881 | 882 | @implementation MBBarProgressView 883 | 884 | #pragma mark - Lifecycle 885 | 886 | - (id)init { 887 | return [self initWithFrame:CGRectMake(.0f, .0f, 120.0f, 20.0f)]; 888 | } 889 | 890 | - (id)initWithFrame:(CGRect)frame { 891 | self = [super initWithFrame:frame]; 892 | if (self) { 893 | _progress = 0.f; 894 | _lineColor = [UIColor whiteColor]; 895 | _progressColor = [UIColor whiteColor]; 896 | _progressRemainingColor = [UIColor clearColor]; 897 | self.backgroundColor = [UIColor clearColor]; 898 | self.opaque = NO; 899 | [self registerForKVO]; 900 | } 901 | return self; 902 | } 903 | 904 | - (void)dealloc { 905 | [self unregisterFromKVO]; 906 | #if !__has_feature(objc_arc) 907 | [_lineColor release]; 908 | [_progressColor release]; 909 | [_progressRemainingColor release]; 910 | [super dealloc]; 911 | #endif 912 | } 913 | 914 | #pragma mark - Drawing 915 | 916 | - (void)drawRect:(CGRect)rect { 917 | CGContextRef context = UIGraphicsGetCurrentContext(); 918 | 919 | CGContextSetLineWidth(context, 2); 920 | CGContextSetStrokeColorWithColor(context,[_lineColor CGColor]); 921 | CGContextSetFillColorWithColor(context, [_progressRemainingColor CGColor]); 922 | 923 | // Draw background 924 | float radius = (rect.size.height / 2) - 2; 925 | CGContextMoveToPoint(context, 2, rect.size.height/2); 926 | CGContextAddArcToPoint(context, 2, 2, radius + 2, 2, radius); 927 | CGContextAddLineToPoint(context, rect.size.width - radius - 2, 2); 928 | CGContextAddArcToPoint(context, rect.size.width - 2, 2, rect.size.width - 2, rect.size.height / 2, radius); 929 | CGContextAddArcToPoint(context, rect.size.width - 2, rect.size.height - 2, rect.size.width - radius - 2, rect.size.height - 2, radius); 930 | CGContextAddLineToPoint(context, radius + 2, rect.size.height - 2); 931 | CGContextAddArcToPoint(context, 2, rect.size.height - 2, 2, rect.size.height/2, radius); 932 | CGContextFillPath(context); 933 | 934 | // Draw border 935 | CGContextMoveToPoint(context, 2, rect.size.height/2); 936 | CGContextAddArcToPoint(context, 2, 2, radius + 2, 2, radius); 937 | CGContextAddLineToPoint(context, rect.size.width - radius - 2, 2); 938 | CGContextAddArcToPoint(context, rect.size.width - 2, 2, rect.size.width - 2, rect.size.height / 2, radius); 939 | CGContextAddArcToPoint(context, rect.size.width - 2, rect.size.height - 2, rect.size.width - radius - 2, rect.size.height - 2, radius); 940 | CGContextAddLineToPoint(context, radius + 2, rect.size.height - 2); 941 | CGContextAddArcToPoint(context, 2, rect.size.height - 2, 2, rect.size.height/2, radius); 942 | CGContextStrokePath(context); 943 | 944 | CGContextSetFillColorWithColor(context, [_progressColor CGColor]); 945 | radius = radius - 2; 946 | float amount = self.progress * rect.size.width; 947 | 948 | // Progress in the middle area 949 | if (amount >= radius + 4 && amount <= (rect.size.width - radius - 4)) { 950 | CGContextMoveToPoint(context, 4, rect.size.height/2); 951 | CGContextAddArcToPoint(context, 4, 4, radius + 4, 4, radius); 952 | CGContextAddLineToPoint(context, amount, 4); 953 | CGContextAddLineToPoint(context, amount, radius + 4); 954 | 955 | CGContextMoveToPoint(context, 4, rect.size.height/2); 956 | CGContextAddArcToPoint(context, 4, rect.size.height - 4, radius + 4, rect.size.height - 4, radius); 957 | CGContextAddLineToPoint(context, amount, rect.size.height - 4); 958 | CGContextAddLineToPoint(context, amount, radius + 4); 959 | 960 | CGContextFillPath(context); 961 | } 962 | 963 | // Progress in the right arc 964 | else if (amount > radius + 4) { 965 | float x = amount - (rect.size.width - radius - 4); 966 | 967 | CGContextMoveToPoint(context, 4, rect.size.height/2); 968 | CGContextAddArcToPoint(context, 4, 4, radius + 4, 4, radius); 969 | CGContextAddLineToPoint(context, rect.size.width - radius - 4, 4); 970 | float angle = -acos(x/radius); 971 | if (isnan(angle)) angle = 0; 972 | CGContextAddArc(context, rect.size.width - radius - 4, rect.size.height/2, radius, M_PI, angle, 0); 973 | CGContextAddLineToPoint(context, amount, rect.size.height/2); 974 | 975 | CGContextMoveToPoint(context, 4, rect.size.height/2); 976 | CGContextAddArcToPoint(context, 4, rect.size.height - 4, radius + 4, rect.size.height - 4, radius); 977 | CGContextAddLineToPoint(context, rect.size.width - radius - 4, rect.size.height - 4); 978 | angle = acos(x/radius); 979 | if (isnan(angle)) angle = 0; 980 | CGContextAddArc(context, rect.size.width - radius - 4, rect.size.height/2, radius, -M_PI, angle, 1); 981 | CGContextAddLineToPoint(context, amount, rect.size.height/2); 982 | 983 | CGContextFillPath(context); 984 | } 985 | 986 | // Progress is in the left arc 987 | else if (amount < radius + 4 && amount > 0) { 988 | CGContextMoveToPoint(context, 4, rect.size.height/2); 989 | CGContextAddArcToPoint(context, 4, 4, radius + 4, 4, radius); 990 | CGContextAddLineToPoint(context, radius + 4, rect.size.height/2); 991 | 992 | CGContextMoveToPoint(context, 4, rect.size.height/2); 993 | CGContextAddArcToPoint(context, 4, rect.size.height - 4, radius + 4, rect.size.height - 4, radius); 994 | CGContextAddLineToPoint(context, radius + 4, rect.size.height/2); 995 | 996 | CGContextFillPath(context); 997 | } 998 | } 999 | 1000 | #pragma mark - KVO 1001 | 1002 | - (void)registerForKVO { 1003 | for (NSString *keyPath in [self observableKeypaths]) { 1004 | [self addObserver:self forKeyPath:keyPath options:NSKeyValueObservingOptionNew context:NULL]; 1005 | } 1006 | } 1007 | 1008 | - (void)unregisterFromKVO { 1009 | for (NSString *keyPath in [self observableKeypaths]) { 1010 | [self removeObserver:self forKeyPath:keyPath]; 1011 | } 1012 | } 1013 | 1014 | - (NSArray *)observableKeypaths { 1015 | return [NSArray arrayWithObjects:@"lineColor", @"progressRemainingColor", @"progressColor", @"progress", nil]; 1016 | } 1017 | 1018 | - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { 1019 | [self setNeedsDisplay]; 1020 | } 1021 | 1022 | @end 1023 | -------------------------------------------------------------------------------- /AliPayDemo/SetpasswordViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // SetpasswordViewController.h 3 | // AliPayDemo 4 | // 5 | // Created by pg on 15/7/15. 6 | // Copyright (c) 2015年 pg. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface SetpasswordViewController : UIViewController 12 | 13 | 14 | @property(nonatomic , copy)NSString *string; 15 | 16 | 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /AliPayDemo/SetpasswordViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // SetpasswordViewController.m 3 | // AliPayDemo 4 | // 5 | // Created by pg on 15/7/15. 6 | // Copyright (c) 2015年 pg. All rights reserved. 7 | // 8 | 9 | #import "SetpasswordViewController.h" 10 | #import "AliPayViews.h" 11 | #import "KeychainData.h" 12 | 13 | @interface SetpasswordViewController () 14 | 15 | @end 16 | 17 | @implementation SetpasswordViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | // Do any additional setup after loading the view. 22 | 23 | 24 | /************************* start **********************************/ 25 | 26 | 27 | AliPayViews *alipay = [[AliPayViews alloc] initWithFrame:self.view.bounds]; 28 | 29 | if ([self.string isEqualToString:@"验证密码"]) { 30 | alipay.gestureModel = ValidatePwdModel; 31 | } else if ([self.string isEqualToString:@"修改密码"]) { 32 | alipay.gestureModel = AlertPwdModel; 33 | } else if ([self.string isEqualToString:@"重置密码"]) { 34 | alipay.gestureModel = SetPwdModel; 35 | } else { 36 | alipay.gestureModel = NoneModel; 37 | } 38 | alipay.block = ^(NSString *pswString) { 39 | NSLog(@"设置密码成功-----你的密码为 = 【%@】\n\n", pswString); 40 | [self dismissViewControllerAnimated:YES completion:nil]; 41 | }; 42 | 43 | [self.view addSubview:alipay]; 44 | 45 | 46 | /************************* end **********************************/ 47 | 48 | 49 | 50 | 51 | 52 | UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom]; 53 | backBtn.frame = CGRectMake(0, 0, 64, 64); 54 | [backBtn setTitle:@"返回" forState:UIControlStateNormal]; 55 | [backBtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside]; 56 | [self.view addSubview:backBtn]; 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | } 65 | 66 | - (void)back { 67 | [self dismissViewControllerAnimated:YES completion:nil]; 68 | } 69 | 70 | /* 71 | #pragma mark - Navigation 72 | 73 | // In a storyboard-based application, you will often want to do a little preparation before navigation 74 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 75 | // Get the new view controller using [segue destinationViewController]. 76 | // Pass the selected object to the new view controller. 77 | } 78 | */ 79 | 80 | @end 81 | -------------------------------------------------------------------------------- /AliPayDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // AliPayDemo 4 | // 5 | // Created by pg on 15/7/8. 6 | // Copyright (c) 2015年 pg. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /AliPayDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // AliPayDemo 4 | // 5 | // Created by pg on 15/7/8. 6 | // Copyright (c) 2015年 pg. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | #import "AliPayViews.h" 12 | #import "KeychainData.h" 13 | 14 | #import "SetpasswordViewController.h" 15 | #import "MBProgressHUD.h" 16 | 17 | 18 | #define BACKCOLOR [UIColor colorWithRed:0.05 green:0.2 blue:0.35 alpha:1] 19 | 20 | 21 | 22 | @interface ViewController () 23 | { 24 | UIButton *twoButton; 25 | } 26 | @end 27 | 28 | @implementation ViewController 29 | 30 | - (void)viewDidLoad { 31 | [super viewDidLoad]; 32 | // Do any additional setup after loading the view, typically from a nib. 33 | 34 | 35 | // AliPayView *aliView = [[AliPayView alloc] initWithFrame:self.view.frame]; 36 | // 37 | // [self.view addSubview:aliView]; 38 | 39 | 40 | 41 | // 42 | // AliPayViews *alipay = [[AliPayViews alloc] initWithFrame:self.view.bounds]; 43 | // 44 | // alipay.block = ^(NSMutableArray *pwdArr) 45 | // { 46 | // NSLog(@"\n\n你的密码为 = 【%@】\n\n", pwdArr); 47 | // }; 48 | // 49 | //// [self.view addSubview:alipay]; 50 | // 51 | 52 | 53 | 54 | UIButton *oneButton = [UIButton buttonWithType:UIButtonTypeCustom]; 55 | oneButton.frame = CGRectMake(0, 70, 320, 50); 56 | oneButton.backgroundColor = [UIColor grayColor]; 57 | [oneButton setTitle:@"重新设置密码(就密码自动作废)" forState:UIControlStateNormal]; 58 | [oneButton addTarget:self action:@selector(setPassword) forControlEvents:UIControlEventTouchUpInside]; 59 | [self.view addSubview:oneButton]; 60 | 61 | 62 | 63 | twoButton = [UIButton buttonWithType:UIButtonTypeCustom]; 64 | twoButton.frame = CGRectMake(0, 200, 320, 50); 65 | twoButton.backgroundColor = [UIColor grayColor]; 66 | [twoButton setTitle:@"忘记密码,没有任何提示,即已成功" forState:UIControlStateNormal]; 67 | [twoButton addTarget:self action:@selector(forgotPassword) forControlEvents:UIControlEventTouchUpInside]; 68 | [self.view addSubview:twoButton]; 69 | 70 | 71 | 72 | UIButton *threeButton = [UIButton buttonWithType:UIButtonTypeCustom]; 73 | threeButton.frame = CGRectMake(0, 320, 277, 50); 74 | threeButton.backgroundColor = [UIColor grayColor]; 75 | [threeButton setTitle:@" 修改密码" forState:UIControlStateNormal]; 76 | [threeButton addTarget:self action:@selector(alertPassword) forControlEvents:UIControlEventTouchUpInside]; 77 | [self.view addSubview:threeButton]; 78 | 79 | 80 | 81 | UIButton *fourButton = [UIButton buttonWithType:UIButtonTypeCustom]; 82 | fourButton.frame = CGRectMake(0, 470, 320, 50); 83 | fourButton.backgroundColor = [UIColor grayColor]; 84 | [fourButton setTitle:@"验证密码" forState:UIControlStateNormal]; 85 | [fourButton addTarget:self action:@selector(validatePassword) forControlEvents:UIControlEventTouchUpInside]; 86 | [self.view addSubview:fourButton]; 87 | 88 | 89 | 90 | 91 | } 92 | 93 | 94 | 95 | /** 96 | * 设置密码 97 | */ 98 | - (void)setPassword 99 | { 100 | [self forgotPassword]; 101 | SetpasswordViewController *setpass = [[SetpasswordViewController alloc] init]; 102 | setpass.string = @"重置密码"; 103 | [self presentViewController:setpass animated:YES completion:nil]; 104 | } 105 | 106 | /** 107 | * 忘记密码 108 | */ 109 | - (void)forgotPassword 110 | { 111 | [KeychainData forgotPsw]; 112 | [self hudAction:@"忘记密码"]; 113 | } 114 | /** 115 | * 修改密码 116 | */ 117 | - (void)alertPassword 118 | { 119 | BOOL isSave = [KeychainData isSave]; //是否有保存 120 | if (isSave) { 121 | SetpasswordViewController *setpass = [[SetpasswordViewController alloc] init]; 122 | setpass.string = @"修改密码"; 123 | [self presentViewController:setpass animated:YES completion:nil]; 124 | } else { 125 | [self hudAction:@"还没有设置密码,不能修改密码"]; 126 | } 127 | } 128 | /** 129 | * 验证密码 130 | */ 131 | - (void)validatePassword 132 | { 133 | BOOL isSave = [KeychainData isSave]; //是否有保存 134 | if (isSave) { 135 | 136 | SetpasswordViewController *setpass = [[SetpasswordViewController alloc] init]; 137 | setpass.string = @"验证密码"; 138 | [self presentViewController:setpass animated:YES completion:nil]; 139 | 140 | } else { 141 | [self hudAction:@"还没有设置密码,不能直接登录"]; 142 | } 143 | } 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | /** 155 | * hud 156 | */ 157 | 158 | - (void)hudAction:(NSString *)contextStr 159 | { 160 | MBProgressHUD *hud = [[MBProgressHUD alloc] init]; 161 | hud.mode = MBProgressHUDModeText; 162 | hud.labelText = contextStr; 163 | hud.animationType = MBProgressHUDAnimationZoom; 164 | [hud show:YES]; 165 | [self.view addSubview:hud]; 166 | [self performSelector:@selector(removeHUB:) withObject:hud afterDelay:1]; 167 | 168 | } 169 | - (void)removeHUB:(MBProgressHUD *)hud 170 | { 171 | if (hud) { 172 | [hud hide:YES]; 173 | [hud removeFromSuperview]; 174 | hud = nil; 175 | } 176 | } 177 | 178 | 179 | 180 | 181 | @end 182 | -------------------------------------------------------------------------------- /AliPayDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // AliPayDemo 4 | // 5 | // Created by pg on 15/7/8. 6 | // Copyright (c) 2015年 pg. 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 | -------------------------------------------------------------------------------- /AliPayDemoTests/AliPayDemoTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // AliPayDemoTests.m 3 | // AliPayDemoTests 4 | // 5 | // Created by pg on 15/7/8. 6 | // Copyright (c) 2015年 pg. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface AliPayDemoTests : XCTestCase 13 | 14 | @end 15 | 16 | @implementation AliPayDemoTests 17 | 18 | - (void)setUp { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown { 24 | // Put teardown code here. This method is called after the invocation of each test method in the class. 25 | [super tearDown]; 26 | } 27 | 28 | - (void)testExample { 29 | // This is an example of a functional test case. 30 | XCTAssert(YES, @"Pass"); 31 | } 32 | 33 | - (void)testPerformanceExample { 34 | // This is an example of a performance test case. 35 | [self measureBlock:^{ 36 | // Put the code you want to measure the time of here. 37 | }]; 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /AliPayDemoTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | BHYB.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /PGGPic.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guoxianlongw/PGGestureViews/9b55b382ab89e0e8dacf7aca90a9883976b88f65/PGGPic.gif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PGGestureViews 2 | 高仿支付宝手势解锁,用keychain保存密码,将苹果官方keychain进一步封装,用法和NSUserdefault相同。无图片,解耦性强,使用coregraphic绘制。 3 | 4 | ![gifImage](https://raw.githubusercontent.com/guoxianlongw/PGGestureViews/master/PGGPic.gif) 5 | 6 | 7 | ![PGGestureViews](https://raw.githubusercontent.com/guoxianlongw/PGGestureViews/master/1.png) 8 | ![PGGestureViews](https://raw.githubusercontent.com/guoxianlongw/PGGestureViews/master/2.png) 9 | 10 | 11 | //typedef enum { 12 | // AlertPwdModel, //修改密码 (需要先输入老密码) 13 | // SetPwdModel, //重置密码(无论存不存老密码都一并删除,在重新设置密码) 14 | // ValidatePwdModel, //验证密码 (输入一遍,进行验证) 15 | // DeletePwdModel, //删除密码 16 | // NoneModel 17 | //}GestureModel; 18 | 19 | 20 | 21 | ///调用手势解锁页面 22 | AliPayViews *alipay = [[AliPayViews alloc] initWithFrame:self.view.bounds]; 23 | alipay.gestureModel = ValidatePwdModel; 24 | 25 | alipay.block = ^(NSString *pswString) { 26 | NSLog(@"设置密码成功-----你的密码为 = 【%@】\n\n", pswString); 27 | [self dismissViewControllerAnimated:YES completion:nil]; // 消失你的页面 28 | 29 | }; 30 | [self.view addSubview:alipay]; 31 | 32 | 33 | 34 | /**** KeychainData.m *****/ 35 | /***************** 根据keychain官网的,封装,增,取,删。都只需一句话 *********************/ 36 | + (void)setObject:(id)object forKey:(id)key; 37 | + (id)objectForKey:(id)key; 38 | + (void)removeObjectForKey:(id)key; 39 | 40 | 41 | 42 | --------------------------------------------------------------------------------