├── IOKit ├── IOKit.framework ├── ProgressViewDemo.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcuserdata │ └── mrcao.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── ProgressViewDemo.xcscheme │ └── xcschememanagement.plist ├── ProgressViewDemo ├── CCAppDelegate.h ├── CCAppDelegate.m ├── CCProgressView.h ├── CCProgressView.m ├── CCViewController.h ├── CCViewController.m ├── CCViewController.xib ├── IOPSKeys.h ├── IOPowerSources.h ├── Images.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── LaunchImage.launchimage │ │ └── Contents.json ├── ProgressViewDemo-Info.plist ├── ProgressViewDemo-Prefix.pch ├── en.lproj │ └── InfoPlist.strings └── main.m ├── ProgressViewDemoTests ├── ProgressViewDemoTests-Info.plist ├── ProgressViewDemoTests.m └── en.lproj │ └── InfoPlist.strings ├── README.md ├── UICountingLabel ├── LICENSE ├── README.md ├── UICountingLabel.h └── UICountingLabel.m ├── UIDevice+ProcessesAdditions.h ├── UIDevice+ProcessesAdditions.m └── jinshan.gif /IOKit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrcao2011/ProgressView/2825fe0f0e34685e6b97ce4dcdc31b2a98d22183/IOKit -------------------------------------------------------------------------------- /IOKit.framework: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrcao2011/ProgressView/2825fe0f0e34685e6b97ce4dcdc31b2a98d22183/IOKit.framework -------------------------------------------------------------------------------- /ProgressViewDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | C6676C23193472B600DD5706 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C6676C22193472B600DD5706 /* Foundation.framework */; }; 11 | C6676C25193472B600DD5706 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C6676C24193472B600DD5706 /* CoreGraphics.framework */; }; 12 | C6676C27193472B600DD5706 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C6676C26193472B600DD5706 /* UIKit.framework */; }; 13 | C6676C2D193472B600DD5706 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = C6676C2B193472B600DD5706 /* InfoPlist.strings */; }; 14 | C6676C2F193472B600DD5706 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = C6676C2E193472B600DD5706 /* main.m */; }; 15 | C6676C33193472B600DD5706 /* CCAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = C6676C32193472B600DD5706 /* CCAppDelegate.m */; }; 16 | C6676C35193472B600DD5706 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C6676C34193472B600DD5706 /* Images.xcassets */; }; 17 | C6676C3C193472B600DD5706 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C6676C3B193472B600DD5706 /* XCTest.framework */; }; 18 | C6676C3D193472B600DD5706 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C6676C22193472B600DD5706 /* Foundation.framework */; }; 19 | C6676C3E193472B600DD5706 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C6676C26193472B600DD5706 /* UIKit.framework */; }; 20 | C6676C46193472B600DD5706 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = C6676C44193472B600DD5706 /* InfoPlist.strings */; }; 21 | C6676C48193472B600DD5706 /* ProgressViewDemoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C6676C47193472B600DD5706 /* ProgressViewDemoTests.m */; }; 22 | C6676C541934733000DD5706 /* CCViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C6676C521934733000DD5706 /* CCViewController.m */; }; 23 | C6676C551934733000DD5706 /* CCViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = C6676C531934733000DD5706 /* CCViewController.xib */; }; 24 | C6676C581934749A00DD5706 /* CCProgressView.m in Sources */ = {isa = PBXBuildFile; fileRef = C6676C571934749A00DD5706 /* CCProgressView.m */; }; 25 | C6678846193475E300DD5706 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = C6678842193475E200DD5706 /* LICENSE */; }; 26 | C6678847193475E300DD5706 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = C6678843193475E300DD5706 /* README.md */; }; 27 | C6678848193475E300DD5706 /* UICountingLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = C6678845193475E300DD5706 /* UICountingLabel.m */; }; 28 | C6B3617E19357631001F7140 /* IOKit in Frameworks */ = {isa = PBXBuildFile; fileRef = C6B3617D19357631001F7140 /* IOKit */; }; 29 | C6B361851935C561001F7140 /* UIDevice+ProcessesAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = C6B361841935C561001F7140 /* UIDevice+ProcessesAdditions.m */; }; 30 | /* End PBXBuildFile section */ 31 | 32 | /* Begin PBXContainerItemProxy section */ 33 | C6676C3F193472B600DD5706 /* PBXContainerItemProxy */ = { 34 | isa = PBXContainerItemProxy; 35 | containerPortal = C6676C17193472B600DD5706 /* Project object */; 36 | proxyType = 1; 37 | remoteGlobalIDString = C6676C1E193472B600DD5706; 38 | remoteInfo = ProgressViewDemo; 39 | }; 40 | /* End PBXContainerItemProxy section */ 41 | 42 | /* Begin PBXFileReference section */ 43 | C6676C1F193472B600DD5706 /* ProgressViewDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ProgressViewDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 44 | C6676C22193472B600DD5706 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 45 | C6676C24193472B600DD5706 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 46 | C6676C26193472B600DD5706 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 47 | C6676C2A193472B600DD5706 /* ProgressViewDemo-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "ProgressViewDemo-Info.plist"; sourceTree = ""; }; 48 | C6676C2C193472B600DD5706 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 49 | C6676C2E193472B600DD5706 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 50 | C6676C30193472B600DD5706 /* ProgressViewDemo-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ProgressViewDemo-Prefix.pch"; sourceTree = ""; }; 51 | C6676C31193472B600DD5706 /* CCAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CCAppDelegate.h; sourceTree = ""; }; 52 | C6676C32193472B600DD5706 /* CCAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CCAppDelegate.m; sourceTree = ""; }; 53 | C6676C34193472B600DD5706 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 54 | C6676C3A193472B600DD5706 /* ProgressViewDemoTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ProgressViewDemoTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 55 | C6676C3B193472B600DD5706 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 56 | C6676C43193472B600DD5706 /* ProgressViewDemoTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "ProgressViewDemoTests-Info.plist"; sourceTree = ""; }; 57 | C6676C45193472B600DD5706 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 58 | C6676C47193472B600DD5706 /* ProgressViewDemoTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ProgressViewDemoTests.m; sourceTree = ""; }; 59 | C6676C511934733000DD5706 /* CCViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCViewController.h; path = ProgressViewDemo/CCViewController.h; sourceTree = ""; }; 60 | C6676C521934733000DD5706 /* CCViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CCViewController.m; path = ProgressViewDemo/CCViewController.m; sourceTree = ""; }; 61 | C6676C531934733000DD5706 /* CCViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = CCViewController.xib; path = ProgressViewDemo/CCViewController.xib; sourceTree = ""; }; 62 | C6676C561934749A00DD5706 /* CCProgressView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCProgressView.h; path = ProgressViewDemo/CCProgressView.h; sourceTree = ""; }; 63 | C6676C571934749A00DD5706 /* CCProgressView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CCProgressView.m; path = ProgressViewDemo/CCProgressView.m; sourceTree = ""; }; 64 | C6678842193475E200DD5706 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = ""; }; 65 | C6678843193475E300DD5706 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README.md; sourceTree = ""; }; 66 | C6678844193475E300DD5706 /* UICountingLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UICountingLabel.h; sourceTree = ""; }; 67 | C6678845193475E300DD5706 /* UICountingLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UICountingLabel.m; sourceTree = ""; }; 68 | C6B3617D19357631001F7140 /* IOKit */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; path = IOKit; sourceTree = ""; }; 69 | C6B3618119357669001F7140 /* IOPowerSources.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = IOPowerSources.h; path = ProgressViewDemo/IOPowerSources.h; sourceTree = ""; }; 70 | C6B3618219357669001F7140 /* IOPSKeys.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = IOPSKeys.h; path = ProgressViewDemo/IOPSKeys.h; sourceTree = ""; }; 71 | C6B361831935C561001F7140 /* UIDevice+ProcessesAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIDevice+ProcessesAdditions.h"; sourceTree = ""; }; 72 | C6B361841935C561001F7140 /* UIDevice+ProcessesAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIDevice+ProcessesAdditions.m"; sourceTree = ""; }; 73 | /* End PBXFileReference section */ 74 | 75 | /* Begin PBXFrameworksBuildPhase section */ 76 | C6676C1C193472B600DD5706 /* Frameworks */ = { 77 | isa = PBXFrameworksBuildPhase; 78 | buildActionMask = 2147483647; 79 | files = ( 80 | C6676C25193472B600DD5706 /* CoreGraphics.framework in Frameworks */, 81 | C6B3617E19357631001F7140 /* IOKit in Frameworks */, 82 | C6676C27193472B600DD5706 /* UIKit.framework in Frameworks */, 83 | C6676C23193472B600DD5706 /* Foundation.framework in Frameworks */, 84 | ); 85 | runOnlyForDeploymentPostprocessing = 0; 86 | }; 87 | C6676C37193472B600DD5706 /* Frameworks */ = { 88 | isa = PBXFrameworksBuildPhase; 89 | buildActionMask = 2147483647; 90 | files = ( 91 | C6676C3C193472B600DD5706 /* XCTest.framework in Frameworks */, 92 | C6676C3E193472B600DD5706 /* UIKit.framework in Frameworks */, 93 | C6676C3D193472B600DD5706 /* Foundation.framework in Frameworks */, 94 | ); 95 | runOnlyForDeploymentPostprocessing = 0; 96 | }; 97 | /* End PBXFrameworksBuildPhase section */ 98 | 99 | /* Begin PBXGroup section */ 100 | C6676C16193472B600DD5706 = { 101 | isa = PBXGroup; 102 | children = ( 103 | C6B361831935C561001F7140 /* UIDevice+ProcessesAdditions.h */, 104 | C6B361841935C561001F7140 /* UIDevice+ProcessesAdditions.m */, 105 | C6B3618119357669001F7140 /* IOPowerSources.h */, 106 | C6B3618219357669001F7140 /* IOPSKeys.h */, 107 | C6B3617D19357631001F7140 /* IOKit */, 108 | C6678841193475E200DD5706 /* UICountingLabel */, 109 | C6676C561934749A00DD5706 /* CCProgressView.h */, 110 | C6676C571934749A00DD5706 /* CCProgressView.m */, 111 | C6676C511934733000DD5706 /* CCViewController.h */, 112 | C6676C521934733000DD5706 /* CCViewController.m */, 113 | C6676C531934733000DD5706 /* CCViewController.xib */, 114 | C6676C28193472B600DD5706 /* ProgressViewDemo */, 115 | C6676C41193472B600DD5706 /* ProgressViewDemoTests */, 116 | C6676C21193472B600DD5706 /* Frameworks */, 117 | C6676C20193472B600DD5706 /* Products */, 118 | ); 119 | sourceTree = ""; 120 | }; 121 | C6676C20193472B600DD5706 /* Products */ = { 122 | isa = PBXGroup; 123 | children = ( 124 | C6676C1F193472B600DD5706 /* ProgressViewDemo.app */, 125 | C6676C3A193472B600DD5706 /* ProgressViewDemoTests.xctest */, 126 | ); 127 | name = Products; 128 | sourceTree = ""; 129 | }; 130 | C6676C21193472B600DD5706 /* Frameworks */ = { 131 | isa = PBXGroup; 132 | children = ( 133 | C6676C22193472B600DD5706 /* Foundation.framework */, 134 | C6676C24193472B600DD5706 /* CoreGraphics.framework */, 135 | C6676C26193472B600DD5706 /* UIKit.framework */, 136 | C6676C3B193472B600DD5706 /* XCTest.framework */, 137 | ); 138 | name = Frameworks; 139 | sourceTree = ""; 140 | }; 141 | C6676C28193472B600DD5706 /* ProgressViewDemo */ = { 142 | isa = PBXGroup; 143 | children = ( 144 | C6676C31193472B600DD5706 /* CCAppDelegate.h */, 145 | C6676C32193472B600DD5706 /* CCAppDelegate.m */, 146 | C6676C34193472B600DD5706 /* Images.xcassets */, 147 | C6676C29193472B600DD5706 /* Supporting Files */, 148 | ); 149 | path = ProgressViewDemo; 150 | sourceTree = ""; 151 | }; 152 | C6676C29193472B600DD5706 /* Supporting Files */ = { 153 | isa = PBXGroup; 154 | children = ( 155 | C6676C2A193472B600DD5706 /* ProgressViewDemo-Info.plist */, 156 | C6676C2B193472B600DD5706 /* InfoPlist.strings */, 157 | C6676C2E193472B600DD5706 /* main.m */, 158 | C6676C30193472B600DD5706 /* ProgressViewDemo-Prefix.pch */, 159 | ); 160 | name = "Supporting Files"; 161 | sourceTree = ""; 162 | }; 163 | C6676C41193472B600DD5706 /* ProgressViewDemoTests */ = { 164 | isa = PBXGroup; 165 | children = ( 166 | C6676C47193472B600DD5706 /* ProgressViewDemoTests.m */, 167 | C6676C42193472B600DD5706 /* Supporting Files */, 168 | ); 169 | path = ProgressViewDemoTests; 170 | sourceTree = ""; 171 | }; 172 | C6676C42193472B600DD5706 /* Supporting Files */ = { 173 | isa = PBXGroup; 174 | children = ( 175 | C6676C43193472B600DD5706 /* ProgressViewDemoTests-Info.plist */, 176 | C6676C44193472B600DD5706 /* InfoPlist.strings */, 177 | ); 178 | name = "Supporting Files"; 179 | sourceTree = ""; 180 | }; 181 | C6678841193475E200DD5706 /* UICountingLabel */ = { 182 | isa = PBXGroup; 183 | children = ( 184 | C6678842193475E200DD5706 /* LICENSE */, 185 | C6678843193475E300DD5706 /* README.md */, 186 | C6678844193475E300DD5706 /* UICountingLabel.h */, 187 | C6678845193475E300DD5706 /* UICountingLabel.m */, 188 | ); 189 | path = UICountingLabel; 190 | sourceTree = ""; 191 | }; 192 | /* End PBXGroup section */ 193 | 194 | /* Begin PBXNativeTarget section */ 195 | C6676C1E193472B600DD5706 /* ProgressViewDemo */ = { 196 | isa = PBXNativeTarget; 197 | buildConfigurationList = C6676C4B193472B600DD5706 /* Build configuration list for PBXNativeTarget "ProgressViewDemo" */; 198 | buildPhases = ( 199 | C6676C1B193472B600DD5706 /* Sources */, 200 | C6676C1C193472B600DD5706 /* Frameworks */, 201 | C6676C1D193472B600DD5706 /* Resources */, 202 | ); 203 | buildRules = ( 204 | ); 205 | dependencies = ( 206 | ); 207 | name = ProgressViewDemo; 208 | productName = ProgressViewDemo; 209 | productReference = C6676C1F193472B600DD5706 /* ProgressViewDemo.app */; 210 | productType = "com.apple.product-type.application"; 211 | }; 212 | C6676C39193472B600DD5706 /* ProgressViewDemoTests */ = { 213 | isa = PBXNativeTarget; 214 | buildConfigurationList = C6676C4E193472B600DD5706 /* Build configuration list for PBXNativeTarget "ProgressViewDemoTests" */; 215 | buildPhases = ( 216 | C6676C36193472B600DD5706 /* Sources */, 217 | C6676C37193472B600DD5706 /* Frameworks */, 218 | C6676C38193472B600DD5706 /* Resources */, 219 | ); 220 | buildRules = ( 221 | ); 222 | dependencies = ( 223 | C6676C40193472B600DD5706 /* PBXTargetDependency */, 224 | ); 225 | name = ProgressViewDemoTests; 226 | productName = ProgressViewDemoTests; 227 | productReference = C6676C3A193472B600DD5706 /* ProgressViewDemoTests.xctest */; 228 | productType = "com.apple.product-type.bundle.unit-test"; 229 | }; 230 | /* End PBXNativeTarget section */ 231 | 232 | /* Begin PBXProject section */ 233 | C6676C17193472B600DD5706 /* Project object */ = { 234 | isa = PBXProject; 235 | attributes = { 236 | CLASSPREFIX = CC; 237 | LastUpgradeCheck = 0510; 238 | ORGANIZATIONNAME = mrcao; 239 | TargetAttributes = { 240 | C6676C39193472B600DD5706 = { 241 | TestTargetID = C6676C1E193472B600DD5706; 242 | }; 243 | }; 244 | }; 245 | buildConfigurationList = C6676C1A193472B600DD5706 /* Build configuration list for PBXProject "ProgressViewDemo" */; 246 | compatibilityVersion = "Xcode 3.2"; 247 | developmentRegion = English; 248 | hasScannedForEncodings = 0; 249 | knownRegions = ( 250 | en, 251 | Base, 252 | ); 253 | mainGroup = C6676C16193472B600DD5706; 254 | productRefGroup = C6676C20193472B600DD5706 /* Products */; 255 | projectDirPath = ""; 256 | projectRoot = ""; 257 | targets = ( 258 | C6676C1E193472B600DD5706 /* ProgressViewDemo */, 259 | C6676C39193472B600DD5706 /* ProgressViewDemoTests */, 260 | ); 261 | }; 262 | /* End PBXProject section */ 263 | 264 | /* Begin PBXResourcesBuildPhase section */ 265 | C6676C1D193472B600DD5706 /* Resources */ = { 266 | isa = PBXResourcesBuildPhase; 267 | buildActionMask = 2147483647; 268 | files = ( 269 | C6676C2D193472B600DD5706 /* InfoPlist.strings in Resources */, 270 | C6676C551934733000DD5706 /* CCViewController.xib in Resources */, 271 | C6678847193475E300DD5706 /* README.md in Resources */, 272 | C6678846193475E300DD5706 /* LICENSE in Resources */, 273 | C6676C35193472B600DD5706 /* Images.xcassets in Resources */, 274 | ); 275 | runOnlyForDeploymentPostprocessing = 0; 276 | }; 277 | C6676C38193472B600DD5706 /* Resources */ = { 278 | isa = PBXResourcesBuildPhase; 279 | buildActionMask = 2147483647; 280 | files = ( 281 | C6676C46193472B600DD5706 /* InfoPlist.strings in Resources */, 282 | ); 283 | runOnlyForDeploymentPostprocessing = 0; 284 | }; 285 | /* End PBXResourcesBuildPhase section */ 286 | 287 | /* Begin PBXSourcesBuildPhase section */ 288 | C6676C1B193472B600DD5706 /* Sources */ = { 289 | isa = PBXSourcesBuildPhase; 290 | buildActionMask = 2147483647; 291 | files = ( 292 | C6676C33193472B600DD5706 /* CCAppDelegate.m in Sources */, 293 | C6B361851935C561001F7140 /* UIDevice+ProcessesAdditions.m in Sources */, 294 | C6676C581934749A00DD5706 /* CCProgressView.m in Sources */, 295 | C6678848193475E300DD5706 /* UICountingLabel.m in Sources */, 296 | C6676C2F193472B600DD5706 /* main.m in Sources */, 297 | C6676C541934733000DD5706 /* CCViewController.m in Sources */, 298 | ); 299 | runOnlyForDeploymentPostprocessing = 0; 300 | }; 301 | C6676C36193472B600DD5706 /* Sources */ = { 302 | isa = PBXSourcesBuildPhase; 303 | buildActionMask = 2147483647; 304 | files = ( 305 | C6676C48193472B600DD5706 /* ProgressViewDemoTests.m in Sources */, 306 | ); 307 | runOnlyForDeploymentPostprocessing = 0; 308 | }; 309 | /* End PBXSourcesBuildPhase section */ 310 | 311 | /* Begin PBXTargetDependency section */ 312 | C6676C40193472B600DD5706 /* PBXTargetDependency */ = { 313 | isa = PBXTargetDependency; 314 | target = C6676C1E193472B600DD5706 /* ProgressViewDemo */; 315 | targetProxy = C6676C3F193472B600DD5706 /* PBXContainerItemProxy */; 316 | }; 317 | /* End PBXTargetDependency section */ 318 | 319 | /* Begin PBXVariantGroup section */ 320 | C6676C2B193472B600DD5706 /* InfoPlist.strings */ = { 321 | isa = PBXVariantGroup; 322 | children = ( 323 | C6676C2C193472B600DD5706 /* en */, 324 | ); 325 | name = InfoPlist.strings; 326 | sourceTree = ""; 327 | }; 328 | C6676C44193472B600DD5706 /* InfoPlist.strings */ = { 329 | isa = PBXVariantGroup; 330 | children = ( 331 | C6676C45193472B600DD5706 /* en */, 332 | ); 333 | name = InfoPlist.strings; 334 | sourceTree = ""; 335 | }; 336 | /* End PBXVariantGroup section */ 337 | 338 | /* Begin XCBuildConfiguration section */ 339 | C6676C49193472B600DD5706 /* Debug */ = { 340 | isa = XCBuildConfiguration; 341 | buildSettings = { 342 | ALWAYS_SEARCH_USER_PATHS = NO; 343 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 344 | CLANG_CXX_LIBRARY = "libc++"; 345 | CLANG_ENABLE_MODULES = YES; 346 | CLANG_ENABLE_OBJC_ARC = YES; 347 | CLANG_WARN_BOOL_CONVERSION = YES; 348 | CLANG_WARN_CONSTANT_CONVERSION = YES; 349 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 350 | CLANG_WARN_EMPTY_BODY = YES; 351 | CLANG_WARN_ENUM_CONVERSION = YES; 352 | CLANG_WARN_INT_CONVERSION = YES; 353 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 354 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 355 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 356 | COPY_PHASE_STRIP = NO; 357 | GCC_C_LANGUAGE_STANDARD = gnu99; 358 | GCC_DYNAMIC_NO_PIC = NO; 359 | GCC_OPTIMIZATION_LEVEL = 0; 360 | GCC_PREPROCESSOR_DEFINITIONS = ( 361 | "DEBUG=1", 362 | "$(inherited)", 363 | ); 364 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 365 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 366 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 367 | GCC_WARN_UNDECLARED_SELECTOR = YES; 368 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 369 | GCC_WARN_UNUSED_FUNCTION = YES; 370 | GCC_WARN_UNUSED_VARIABLE = YES; 371 | IPHONEOS_DEPLOYMENT_TARGET = 7.1; 372 | ONLY_ACTIVE_ARCH = YES; 373 | SDKROOT = iphoneos; 374 | }; 375 | name = Debug; 376 | }; 377 | C6676C4A193472B600DD5706 /* Release */ = { 378 | isa = XCBuildConfiguration; 379 | buildSettings = { 380 | ALWAYS_SEARCH_USER_PATHS = NO; 381 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 382 | CLANG_CXX_LIBRARY = "libc++"; 383 | CLANG_ENABLE_MODULES = YES; 384 | CLANG_ENABLE_OBJC_ARC = YES; 385 | CLANG_WARN_BOOL_CONVERSION = YES; 386 | CLANG_WARN_CONSTANT_CONVERSION = YES; 387 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 388 | CLANG_WARN_EMPTY_BODY = YES; 389 | CLANG_WARN_ENUM_CONVERSION = YES; 390 | CLANG_WARN_INT_CONVERSION = YES; 391 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 392 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 393 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 394 | COPY_PHASE_STRIP = YES; 395 | ENABLE_NS_ASSERTIONS = NO; 396 | GCC_C_LANGUAGE_STANDARD = gnu99; 397 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 398 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 399 | GCC_WARN_UNDECLARED_SELECTOR = YES; 400 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 401 | GCC_WARN_UNUSED_FUNCTION = YES; 402 | GCC_WARN_UNUSED_VARIABLE = YES; 403 | IPHONEOS_DEPLOYMENT_TARGET = 7.1; 404 | SDKROOT = iphoneos; 405 | VALIDATE_PRODUCT = YES; 406 | }; 407 | name = Release; 408 | }; 409 | C6676C4C193472B600DD5706 /* Debug */ = { 410 | isa = XCBuildConfiguration; 411 | buildSettings = { 412 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 413 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 414 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 415 | GCC_PREFIX_HEADER = "ProgressViewDemo/ProgressViewDemo-Prefix.pch"; 416 | INFOPLIST_FILE = "ProgressViewDemo/ProgressViewDemo-Info.plist"; 417 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 418 | LIBRARY_SEARCH_PATHS = ( 419 | "$(inherited)", 420 | "/项目/防丢自拍/new/BLELoss0417", 421 | addbaidu, 422 | "map/BLELoss/libs/Release-iphoneos", 423 | "/项目/防丢自拍/new/BLELoss0417", 424 | addbaidu, 425 | "map/BLELoss/libs/Release-iphonesimulator", 426 | "$(PROJECT_DIR)", 427 | ); 428 | PRODUCT_NAME = "$(TARGET_NAME)"; 429 | WRAPPER_EXTENSION = app; 430 | }; 431 | name = Debug; 432 | }; 433 | C6676C4D193472B600DD5706 /* Release */ = { 434 | isa = XCBuildConfiguration; 435 | buildSettings = { 436 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 437 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 438 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 439 | GCC_PREFIX_HEADER = "ProgressViewDemo/ProgressViewDemo-Prefix.pch"; 440 | INFOPLIST_FILE = "ProgressViewDemo/ProgressViewDemo-Info.plist"; 441 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 442 | LIBRARY_SEARCH_PATHS = ( 443 | "$(inherited)", 444 | "/项目/防丢自拍/new/BLELoss0417", 445 | addbaidu, 446 | "map/BLELoss/libs/Release-iphoneos", 447 | "/项目/防丢自拍/new/BLELoss0417", 448 | addbaidu, 449 | "map/BLELoss/libs/Release-iphonesimulator", 450 | "$(PROJECT_DIR)", 451 | ); 452 | PRODUCT_NAME = "$(TARGET_NAME)"; 453 | WRAPPER_EXTENSION = app; 454 | }; 455 | name = Release; 456 | }; 457 | C6676C4F193472B600DD5706 /* Debug */ = { 458 | isa = XCBuildConfiguration; 459 | buildSettings = { 460 | BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/ProgressViewDemo.app/ProgressViewDemo"; 461 | FRAMEWORK_SEARCH_PATHS = ( 462 | "$(SDKROOT)/Developer/Library/Frameworks", 463 | "$(inherited)", 464 | "$(DEVELOPER_FRAMEWORKS_DIR)", 465 | ); 466 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 467 | GCC_PREFIX_HEADER = "ProgressViewDemo/ProgressViewDemo-Prefix.pch"; 468 | GCC_PREPROCESSOR_DEFINITIONS = ( 469 | "DEBUG=1", 470 | "$(inherited)", 471 | ); 472 | INFOPLIST_FILE = "ProgressViewDemoTests/ProgressViewDemoTests-Info.plist"; 473 | PRODUCT_NAME = "$(TARGET_NAME)"; 474 | TEST_HOST = "$(BUNDLE_LOADER)"; 475 | WRAPPER_EXTENSION = xctest; 476 | }; 477 | name = Debug; 478 | }; 479 | C6676C50193472B600DD5706 /* Release */ = { 480 | isa = XCBuildConfiguration; 481 | buildSettings = { 482 | BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/ProgressViewDemo.app/ProgressViewDemo"; 483 | FRAMEWORK_SEARCH_PATHS = ( 484 | "$(SDKROOT)/Developer/Library/Frameworks", 485 | "$(inherited)", 486 | "$(DEVELOPER_FRAMEWORKS_DIR)", 487 | ); 488 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 489 | GCC_PREFIX_HEADER = "ProgressViewDemo/ProgressViewDemo-Prefix.pch"; 490 | INFOPLIST_FILE = "ProgressViewDemoTests/ProgressViewDemoTests-Info.plist"; 491 | PRODUCT_NAME = "$(TARGET_NAME)"; 492 | TEST_HOST = "$(BUNDLE_LOADER)"; 493 | WRAPPER_EXTENSION = xctest; 494 | }; 495 | name = Release; 496 | }; 497 | /* End XCBuildConfiguration section */ 498 | 499 | /* Begin XCConfigurationList section */ 500 | C6676C1A193472B600DD5706 /* Build configuration list for PBXProject "ProgressViewDemo" */ = { 501 | isa = XCConfigurationList; 502 | buildConfigurations = ( 503 | C6676C49193472B600DD5706 /* Debug */, 504 | C6676C4A193472B600DD5706 /* Release */, 505 | ); 506 | defaultConfigurationIsVisible = 0; 507 | defaultConfigurationName = Release; 508 | }; 509 | C6676C4B193472B600DD5706 /* Build configuration list for PBXNativeTarget "ProgressViewDemo" */ = { 510 | isa = XCConfigurationList; 511 | buildConfigurations = ( 512 | C6676C4C193472B600DD5706 /* Debug */, 513 | C6676C4D193472B600DD5706 /* Release */, 514 | ); 515 | defaultConfigurationIsVisible = 0; 516 | defaultConfigurationName = Release; 517 | }; 518 | C6676C4E193472B600DD5706 /* Build configuration list for PBXNativeTarget "ProgressViewDemoTests" */ = { 519 | isa = XCConfigurationList; 520 | buildConfigurations = ( 521 | C6676C4F193472B600DD5706 /* Debug */, 522 | C6676C50193472B600DD5706 /* Release */, 523 | ); 524 | defaultConfigurationIsVisible = 0; 525 | defaultConfigurationName = Release; 526 | }; 527 | /* End XCConfigurationList section */ 528 | }; 529 | rootObject = C6676C17193472B600DD5706 /* Project object */; 530 | } 531 | -------------------------------------------------------------------------------- /ProgressViewDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ProgressViewDemo.xcodeproj/xcuserdata/mrcao.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /ProgressViewDemo.xcodeproj/xcuserdata/mrcao.xcuserdatad/xcschemes/ProgressViewDemo.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 49 | 50 | 51 | 52 | 61 | 62 | 68 | 69 | 70 | 71 | 72 | 73 | 79 | 80 | 86 | 87 | 88 | 89 | 91 | 92 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /ProgressViewDemo.xcodeproj/xcuserdata/mrcao.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | ProgressViewDemo.xcscheme 8 | 9 | orderHint 10 | 28 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | C6676C1E193472B600DD5706 16 | 17 | primary 18 | 19 | 20 | C6676C39193472B600DD5706 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /ProgressViewDemo/CCAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // CCAppDelegate.h 3 | // ProgressViewDemo 4 | // 5 | // Created by mr.cao on 14-5-27. 6 | // Copyright (c) 2014年 mrcao. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CCAppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /ProgressViewDemo/CCAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // CCAppDelegate.m 3 | // ProgressViewDemo 4 | // 5 | // Created by mr.cao on 14-5-27. 6 | // Copyright (c) 2014年 mrcao. All rights reserved. 7 | // 8 | 9 | #import "CCAppDelegate.h" 10 | #import "CCViewController.h" 11 | @implementation CCAppDelegate 12 | 13 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 14 | { 15 | self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 16 | // Override point for customization after application launch. 17 | self.window.backgroundColor = [UIColor whiteColor]; 18 | 19 | //CGRect rect = [[UIScreen mainScreen] bounds]; 20 | 21 | self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 22 | // Override point for customization after application launch. 23 | self.window.backgroundColor = [UIColor whiteColor]; 24 | self.window.rootViewController=[[CCViewController alloc]initWithNibName:@"CCViewController" bundle:nil];; 25 | 26 | [self.window makeKeyAndVisible]; 27 | return YES; 28 | } 29 | 30 | - (void)applicationWillResignActive:(UIApplication *)application 31 | { 32 | // 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. 33 | // 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. 34 | } 35 | 36 | - (void)applicationDidEnterBackground:(UIApplication *)application 37 | { 38 | // 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. 39 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 40 | } 41 | 42 | - (void)applicationWillEnterForeground:(UIApplication *)application 43 | { 44 | // 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. 45 | } 46 | 47 | - (void)applicationDidBecomeActive:(UIApplication *)application 48 | { 49 | // 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. 50 | } 51 | 52 | - (void)applicationWillTerminate:(UIApplication *)application 53 | { 54 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 55 | } 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /ProgressViewDemo/CCProgressView.h: -------------------------------------------------------------------------------- 1 | // 2 | // CCProgressView.h 3 | // ProgressViewDemo 4 | // 5 | // Created by mr.cao on 14-5-27. 6 | // Copyright (c) 2014年 mrcao. All rights reserved. 7 | // 8 | 9 | #import 10 | #define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI) 11 | 12 | @interface CCProgressView : UIView 13 | @property (nonatomic) NSNumber *lineWidth; 14 | @property (nonatomic) CAShapeLayer *circleBG; 15 | @property (nonatomic, readonly) CAGradientLayer* gradientLayer; 16 | @property (nonatomic , strong) NSTimer *theTimer; 17 | - (void)setProgress:(CGFloat)progress animated:(BOOL)animated; 18 | 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /ProgressViewDemo/CCProgressView.m: -------------------------------------------------------------------------------- 1 | // 2 | // CCProgressView.m 3 | // ProgressViewDemo 4 | // 5 | // Created by mr.cao on 14-5-27. 6 | // Copyright (c) 2014年 mrcao. All rights reserved. 7 | // 8 | 9 | #import "CCProgressView.h" 10 | #import "UICountingLabel.h" 11 | 12 | @interface CCProgressView() 13 | { 14 | UIColor *_currentWaterColor; 15 | 16 | float _currentLinePointY; 17 | 18 | float a; 19 | float b; 20 | 21 | BOOL jia; 22 | 23 | } 24 | @end 25 | 26 | @implementation CCProgressView 27 | 28 | + (Class)layerClass 29 | { 30 | return [CAGradientLayer class]; 31 | } 32 | 33 | - (CAGradientLayer *)gradientLayer 34 | { 35 | return (CAGradientLayer*)self.layer; 36 | } 37 | 38 | 39 | /* 40 | // Only override drawRect: if you perform custom drawing. 41 | // An empty implementation adversely affects performance during animation. 42 | - (void)drawRect:(CGRect)rect 43 | { 44 | // Drawing code 45 | } 46 | */ 47 | 48 | - (id)initWithFrame:(CGRect)frame 49 | { 50 | self = [super initWithFrame:frame]; 51 | 52 | if (self) { 53 | 54 | CGFloat startAngle =0; 55 | CGFloat endAngle = 360; 56 | 57 | _lineWidth = [NSNumber numberWithFloat:15.0]; 58 | UIBezierPath *circlePath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(frame.size.width/2,frame.size.height/2) radius:self.frame.size.height * 0.5 startAngle:DEGREES_TO_RADIANS(startAngle) endAngle:DEGREES_TO_RADIANS(endAngle) clockwise:YES]; 59 | 60 | _circleBG = [CAShapeLayer layer]; 61 | _circleBG.path = circlePath.CGPath; 62 | _circleBG.lineCap = kCALineCapRound; 63 | _circleBG.fillColor = [UIColor clearColor].CGColor; 64 | _circleBG.lineWidth = [_lineWidth floatValue]; 65 | _circleBG.strokeColor = [UIColor grayColor].CGColor; 66 | _circleBG.zPosition = -1; 67 | 68 | 69 | [self.layer addSublayer:_circleBG]; 70 | 71 | CAShapeLayer* maskLayer = [CAShapeLayer layer]; 72 | maskLayer.path = circlePath.CGPath; 73 | self.gradientLayer.mask = maskLayer; 74 | self.gradientLayer.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithRed:86/255.0f green:202/255.0f blue:139/255.0f alpha:1]CGColor],(id)[[UIColor lightGrayColor] CGColor], nil]; 75 | self.gradientLayer.locations = @[@0.f, @0.f]; 76 | 77 | self.gradientLayer.startPoint =CGPointMake(0.5, 1); 78 | self.gradientLayer.endPoint = CGPointMake(0.5, 0); 79 | 80 | } 81 | 82 | return self; 83 | } 84 | 85 | - (void)setProgress:(CGFloat)progress animated:(BOOL)animated 86 | { 87 | CGFloat rescaledProgress = MIN(MAX(progress, 0.f), 1.f); 88 | NSArray* newLocations =@[[NSNumber numberWithFloat:rescaledProgress], [NSNumber numberWithFloat:rescaledProgress]]; 89 | 90 | if (animated) 91 | { 92 | NSTimeInterval duration = 0.5; 93 | [UIView animateWithDuration:duration animations:^{ 94 | CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"locations"]; 95 | animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 96 | animation.duration = duration; 97 | animation.delegate = self; 98 | animation.fromValue = self.gradientLayer.locations; 99 | animation.toValue = newLocations; 100 | [self.gradientLayer addAnimation:animation forKey:@"animateLocations"]; 101 | }]; 102 | } 103 | else 104 | { 105 | [self.gradientLayer setNeedsDisplay]; 106 | } 107 | 108 | self.gradientLayer.locations = newLocations; 109 | a = 1.5; 110 | b = 0; 111 | jia = NO; 112 | _currentLinePointY = self.frame.size.height*(1-progress); 113 | _currentWaterColor = [UIColor colorWithRed:86/255.0f green:202/255.0f blue:139/255.0f alpha:1]; 114 | //_currentLinePointY = 250; 115 | if(_theTimer) 116 | { 117 | [_theTimer invalidate]; 118 | _theTimer=nil; 119 | } 120 | _theTimer=[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(animateWave) userInfo:nil repeats:YES]; 121 | 122 | 123 | } 124 | -(void)animateWave 125 | { 126 | if (jia) { 127 | a += 0.01; 128 | }else{ 129 | a -= 0.01; 130 | } 131 | 132 | 133 | if (a<=1) { 134 | jia = YES; 135 | } 136 | 137 | if (a>=1.5) { 138 | jia = NO; 139 | } 140 | 141 | 142 | b+=0.1; 143 | 144 | [self setNeedsDisplay]; 145 | } 146 | 147 | 148 | - (void)drawRect:(CGRect)rect 149 | { 150 | 151 | CGContextRef context = UIGraphicsGetCurrentContext(); 152 | CGMutablePathRef path = CGPathCreateMutable(); 153 | 154 | //画水 155 | CGContextSetLineWidth(context, 1); 156 | CGContextSetFillColorWithColor(context, [_currentWaterColor CGColor]); 157 | 158 | float y=_currentLinePointY; 159 | CGPathMoveToPoint(path, NULL, 0, y); 160 | for(float x=0;x<=ViewWidth;x++){ 161 | y= a * sin( x/180*M_PI + 8*b/M_PI ) * 10 + _currentLinePointY; 162 | CGPathAddLineToPoint(path, nil, x, y); 163 | } 164 | 165 | CGPathAddLineToPoint(path, nil, ViewWidth, rect.size.height); 166 | CGPathAddLineToPoint(path, nil, 0, rect.size.height); 167 | //CGPathAddLineToPoint(path, nil, 0, _currentLinePointY); 168 | 169 | CGContextAddPath(context, path); 170 | CGContextFillPath(context); 171 | CGContextDrawPath(context, kCGPathStroke); 172 | CGPathRelease(path); 173 | 174 | 175 | } 176 | 177 | @end -------------------------------------------------------------------------------- /ProgressViewDemo/CCViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CCViewController.h 3 | // 4 | // 5 | // Created by mr.cao on 14-5-27. 6 | // Copyright (c) 2014年 mrcao. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class CCProgressView; 12 | @interface CCViewController : UIViewController 13 | { 14 | CGAffineTransform currentTransform; 15 | CGAffineTransform newTransform; 16 | double r; 17 | } 18 | @property (nonatomic , strong) NSTimer *theTimer; 19 | @property(nonatomic,strong)CCProgressView * circleChart; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /ProgressViewDemo/CCViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // CCViewController.m 3 | // 4 | // 5 | // Created by mr.cao on 14-5-27. 6 | // Copyright (c) 2014年 mrcao. All rights reserved. 7 | // 8 | 9 | #import "CCViewController.h" 10 | #import 11 | #import "CCProgressView.h" 12 | #import "IOPowerSources.h" 13 | #import "IOPSKeys.h" 14 | #import 15 | #import "UICountingLabel.h" 16 | #import "UIDevice+ProcessesAdditions.h" 17 | #define EPSILON 1e-6 18 | #define kDuration 1.0 // 动画持续时间(秒) 19 | @interface CCViewController () 20 | { 21 | UICountingLabel *_gradeLabel; 22 | UICountingLabel *_titleLabel; 23 | 24 | } 25 | @property (nonatomic, strong) CMMotionManager* motionManager; 26 | @property (nonatomic, strong) CADisplayLink* motionDisplayLink; 27 | @property (nonatomic) float motionLastYaw; 28 | 29 | @end 30 | 31 | @implementation CCViewController 32 | 33 | - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 34 | { 35 | self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 36 | if (self) { 37 | // Custom initialization 38 | 39 | 40 | } 41 | return self; 42 | } 43 | 44 | - (void)viewDidLoad 45 | { 46 | [super viewDidLoad]; 47 | // Do any additional setup after loading 48 | 49 | self.view.userInteractionEnabled=YES; 50 | _circleChart = [[CCProgressView alloc] initWithFrame:CGRectMake(30, 100, ViewWidth-30*2,ViewWidth-30*2)]; 51 | _circleChart.backgroundColor = [UIColor clearColor]; 52 | 53 | [self.view addSubview:_circleChart]; 54 | 55 | r=_circleChart.frame.size.height; 56 | 57 | 58 | _gradeLabel = [[UICountingLabel alloc] initWithFrame:CGRectMake(_circleChart.frame.origin.x, _circleChart.frame.origin.y, 50.0, 50.0)]; 59 | _titleLabel=[[UICountingLabel alloc]initWithFrame:CGRectMake(_circleChart.frame.origin.x, _circleChart.frame.origin.x, 50.0, 50.0)]; 60 | [_titleLabel setTextAlignment:NSTextAlignmentCenter]; 61 | [_titleLabel setFont:[UIFont boldSystemFontOfSize:33.0f]]; 62 | [_titleLabel setTextColor:[UIColor whiteColor]]; 63 | _titleLabel.method = UILabelCountingMethodEaseInOut; 64 | [self.view addSubview:_titleLabel]; 65 | [_titleLabel setHidden:YES]; 66 | [_titleLabel setCenter:CGPointMake(r,r-30)]; 67 | [_gradeLabel setTextAlignment:NSTextAlignmentCenter]; 68 | [_gradeLabel setFont:[UIFont boldSystemFontOfSize:33.0f]]; 69 | [_gradeLabel setTextColor:[UIColor whiteColor]]; 70 | 71 | [_gradeLabel setCenter:CGPointMake(r,r-30)]; 72 | _gradeLabel.method = UILabelCountingMethodEaseInOut; 73 | 74 | 75 | [self.view addSubview:_gradeLabel]; 76 | [_gradeLabel setHidden:YES]; 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | UIDevice *device = [UIDevice currentDevice]; 86 | device.batteryMonitoringEnabled = YES; 87 | // NSLog(@"%.2f", device.batteryLevel); 88 | NSLog(@"%.2f---%.2f", device.batteryLevel, [self batteryLevel]); 89 | 90 | //[device addObserver:self forKeyPath:@"batteryLevel" options:0x0 context:nil]; 91 | [[UIDevice currentDevice] setBatteryMonitoringEnabled:YES]; 92 | [[NSNotificationCenter defaultCenter] 93 | addObserverForName:UIDeviceBatteryLevelDidChangeNotification 94 | object:nil queue:[NSOperationQueue mainQueue] 95 | usingBlock:^(NSNotification *notification) { 96 | // Level has changed 97 | NSLog(@"Battery Level Change"); 98 | NSLog(@"%.2f---%.2f", device.batteryLevel, [self batteryLevel]); 99 | }]; 100 | [self startGravity]; 101 | currentTransform=_circleChart.transform; 102 | /*NSArray * processes = [[UIDevice currentDevice] runningProcesses]; 103 | for (NSDictionary * dict in processes){ 104 | NSLog(@"%@- %@ - %@",[dict allKeys], [dict objectForKey:@"ProcessID"], [dict objectForKey:@"ProcessName"]); 105 | }*/ 106 | 107 | } 108 | - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { 109 | UIDevice *device = [UIDevice currentDevice]; 110 | if ([object isEqual:device] && [keyPath isEqual:@"batteryLevel"]) { 111 | 112 | NSLog(@"%.2f---%.2f", device.batteryLevel, [self batteryLevel]); 113 | } 114 | } 115 | - (void)viewDidAppear:(BOOL)animated { 116 | 117 | [super viewDidAppear:animated]; 118 | 119 | } 120 | 121 | - (void)didReceiveMemoryWarning 122 | { 123 | [super didReceiveMemoryWarning]; 124 | // Dispose of any resources that can be recreated. 125 | } 126 | 127 | - (double) batteryLevel 128 | { 129 | CFTypeRef blob = IOPSCopyPowerSourcesInfo(); 130 | CFArrayRef sources = IOPSCopyPowerSourcesList(blob); 131 | 132 | CFDictionaryRef pSource = NULL; 133 | const void *psValue; 134 | 135 | int numOfSources = CFArrayGetCount(sources); 136 | if (numOfSources == 0) { 137 | NSLog(@"Error in CFArrayGetCount"); 138 | return -1.0f; 139 | } 140 | 141 | for (int i = 0 ; i < numOfSources ; i++) 142 | { 143 | pSource = IOPSGetPowerSourceDescription(blob, CFArrayGetValueAtIndex(sources, i)); 144 | if (!pSource) { 145 | NSLog(@"Error in IOPSGetPowerSourceDescription"); 146 | return -1.0f; 147 | } 148 | psValue = (CFStringRef)CFDictionaryGetValue(pSource, CFSTR(kIOPSNameKey)); 149 | 150 | //int curCapacity = 0; 151 | // int maxCapacity = 0; 152 | 153 | float curCapacity = 0; 154 | float maxCapacity = 0; 155 | double percent; 156 | 157 | psValue = CFDictionaryGetValue(pSource, CFSTR(kIOPSCurrentCapacityKey)); 158 | CFNumberGetValue((CFNumberRef)psValue, kCFNumberFloat32Type, &curCapacity); 159 | 160 | psValue = CFDictionaryGetValue(pSource, CFSTR(kIOPSMaxCapacityKey)); 161 | CFNumberGetValue((CFNumberRef)psValue, kCFNumberFloat32Type, &maxCapacity); 162 | // NSLog(@"curCapacity:%f-maxCapacity:%f",curCapacity,maxCapacity); 163 | percent = ((double)(curCapacity)/(double)maxCapacity * 100.0f); 164 | [_circleChart setProgress:percent/100 animated:YES]; 165 | [_titleLabel setHidden:NO]; 166 | _titleLabel.frame=CGRectMake(0, 0, r, r); 167 | _titleLabel.text=[NSString stringWithFormat:@"%.0f%%",percent]; 168 | [_titleLabel setCenter:CGPointMake(r/2+_circleChart.frame.origin.x,r+_circleChart.frame.origin.y-80)]; 169 | [_gradeLabel setHidden:NO]; 170 | _gradeLabel.frame=CGRectMake(0, 0, r, r); 171 | _gradeLabel.text=@"当前电量"; 172 | [_gradeLabel setCenter:CGPointMake(r/2+_circleChart.frame.origin.x,r-40+_circleChart.frame.origin.y)]; 173 | 174 | return percent; 175 | } 176 | return -1.0f; 177 | } 178 | - (BOOL)isGravityActive 179 | { 180 | return self.motionDisplayLink != nil; 181 | } 182 | 183 | - (void)startGravity 184 | { 185 | if ( ! [self isGravityActive]) { 186 | self.motionManager = [[CMMotionManager alloc] init]; 187 | self.motionManager.deviceMotionUpdateInterval =0.1;// 0.02; // 50 Hz 188 | 189 | self.motionLastYaw = 0; 190 | //self.motionDisplayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(motionRefresh:)]; 191 | // self.motionDisplayLink.frameInterval=1; 192 | // [self.motionDisplayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; 193 | _theTimer= [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(motionRefresh:) userInfo:nil repeats:YES]; 194 | } 195 | if ([self.motionManager isDeviceMotionAvailable]) { 196 | // to avoid using more CPU than necessary we use ``CMAttitudeReferenceFrameXArbitraryZVertical`` 197 | [self.motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXArbitraryZVertical]; 198 | } 199 | } 200 | - (void)motionRefresh:(id)sender 201 | { 202 | 203 | // compute the device yaw from the attitude quaternion 204 | // http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles 205 | CMQuaternion quat = self.motionManager.deviceMotion.attitude.quaternion; 206 | double yaw = asin(2*(quat.x*quat.z - quat.w*quat.y)); 207 | 208 | // TODO improve the yaw interval (stuck to [-PI/2, PI/2] due to arcsin definition 209 | 210 | yaw *= -1; // reverse the angle so that it reflect a *liquid-like* behavior 211 | //yaw += M_PI_2; // because for the motion manager 0 is the calibration value (but for us 0 is the horizontal axis) 212 | 213 | if (self.motionLastYaw == 0) { 214 | self.motionLastYaw = yaw; 215 | } 216 | 217 | // kalman filtering 218 | static float q = 0.1; // process noise 219 | static float s = 0.1; // sensor noise 220 | static float p = 0.1; // estimated error 221 | static float k = 0.5; // kalman filter gain 222 | 223 | float x = self.motionLastYaw; 224 | p = p + q; 225 | k = p / (p + s); 226 | x = x + k*(yaw - x); 227 | p = (1 - k)*p; 228 | 229 | //NSLog(@"xxxx:%f",x); 230 | // update starting & ending point of the gradient 231 | // if(abs(x-self.motionLastYaw) 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /ProgressViewDemo/IOPSKeys.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2010 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | 24 | /*! 25 | * @header IOPSKeys.h 26 | * 27 | * @discussion 28 | * IOPSKeys.h defines C strings for use accessing power source data in IOPowerSource 29 | * CFDictionaries, as returned by @link //apple_ref/c/func/IOPSGetPowerSourceDescription IOPSGetPowerSourceDescription @/link 30 | * Note that all of these C strings must be converted to CFStrings before use. You can wrap 31 | * them with the CFSTR() macro, or create a CFStringRef (that you must later CFRelease()) using CFStringCreateWithCString(). 32 | */ 33 | 34 | #ifndef _IOPSKEYS_H_ 35 | #define _IOPSKEYS_H_ 36 | 37 | /*! 38 | * @group IOPSPowerAdapter Keys 39 | * 40 | * @discussion 41 | * Use these kIOPSPowerAdapter keys to decipher the dictionary returned 42 | * by @link //apple_ref/c/func/IOPSCopyExternalPowerAdapterDetails IOPSCopyExternalPowerAdapterDetails @/link 43 | */ 44 | 45 | /*! 46 | * @define kIOPSPowerAdapterIDKey 47 | * 48 | * @abstract This key refers to the attached external AC power adapter's ID. 49 | * The value associated with this key is a CFNumberRef kCFNumberIntType integer. 50 | * 51 | * @discussion This key may be present in the dictionary returned from 52 | * @link //apple_ref/c/func/IOPSCopyExternalPowerAdapterDetails IOPSCopyExternalPowerAdapterDetails @/link 53 | * This key might not be defined in the adapter details dictionary. 54 | */ 55 | #define kIOPSPowerAdapterIDKey "AdapterID" 56 | 57 | /*! 58 | * @define kIOPSPowerAdapterWattsKey 59 | * 60 | * @abstract This key refers to the wattage of the external AC power adapter attached to a portable. 61 | * The value associated with this key is a CFNumberRef kCFNumberIntType integer value, in units of watts. 62 | * 63 | * @discussion This key may be present in the dictionary returned from 64 | * @link //apple_ref/c/func/IOPSCopyExternalPowerAdapterDetails IOPSCopyExternalPowerAdapterDetails @/link 65 | * This key might not be defined in the adapter details dictionary. 66 | */ 67 | #define kIOPSPowerAdapterWattsKey "Watts" 68 | 69 | /*! 70 | * @define kIOPSPowerAdapterRevisionKey 71 | * 72 | * @abstract The power adapter's revision. 73 | * The value associated with this key is a CFNumberRef kCFNumberIntType integer value 74 | * 75 | * @discussion This key may be present in the dictionary returned from 76 | * @link //apple_ref/c/func/IOPSCopyExternalPowerAdapterDetails IOPSCopyExternalPowerAdapterDetails @/link 77 | * This key might not be defined in the adapter details dictionary. 78 | */ 79 | #define kIOPSPowerAdapterRevisionKey "AdapterRevision" 80 | 81 | /*! 82 | * @define kIOPSPowerAdapterSerialNumberKey 83 | * 84 | * @abstract The power adapter's serial number. 85 | * The value associated with this key is a CFNumberRef kCFNumberIntType integer value 86 | * 87 | * @discussion This key may be present in the dictionary returned from 88 | * @link //apple_ref/c/func/IOPSCopyExternalPowerAdapterDetails IOPSCopyExternalPowerAdapterDetails @/link 89 | * This key might not be defined in the adapter details dictionary. 90 | */ 91 | #define kIOPSPowerAdapterSerialNumberKey "SerialNumber" 92 | 93 | /*! 94 | * @define kIOPSPowerAdapterFamilyKey 95 | * 96 | * @abstract The power adapter's family code. 97 | * The value associated with this key is a CFNumberRef kCFNumberIntType integer value 98 | * 99 | * @discussion This key may be present in the dictionary returned from 100 | * @link //apple_ref/c/func/IOPSCopyExternalPowerAdapterDetails IOPSCopyExternalPowerAdapterDetails @/link 101 | * This key might not be defined in the adapter details dictionary. 102 | */ 103 | #define kIOPSPowerAdapterFamilyKey "FamilyCode" 104 | 105 | /*! 106 | * @define kIOPSPowerAdapterCurrentKey 107 | * 108 | * @abstract This key refers to the current of the external AC power adapter attached to a portable. 109 | * The value associated with this key is a CFNumberRef kCFNumberIntType integer value, in units of mAmps. 110 | * 111 | * @discussion This key may be present in the dictionary returned from 112 | * @link //apple_ref/c/func/IOPSCopyExternalPowerAdapterDetails IOPSCopyExternalPowerAdapterDetails @/link 113 | * This key might not be defined in the adapter details dictionary. 114 | */ 115 | #define kIOPSPowerAdapterCurrentKey "Current" 116 | 117 | /*! 118 | * @define kIOPSPowerAdapterSourceKey 119 | * 120 | * @abstract This key refers to the source of the power. 121 | * The value associated with this key is a CFNumberRef kCFNumberIntType integer value. 122 | * 123 | * @discussion This key may be present in the dictionary returned from 124 | * @link //apple_ref/c/func/IOPSCopyExternalPowerAdapterDetails IOPSCopyExternalPowerAdapterDetails @/link 125 | * This key might not be defined in the adapter details dictionary. 126 | */ 127 | #define kIOPSPowerAdapterSourceKey "Source" 128 | 129 | 130 | /*! 131 | * @group Internal Keys 132 | * 133 | */ 134 | 135 | /*! 136 | * @define kIOPSUPSManagementClaimed 137 | * 138 | * @abstract Claims UPS management for a third-party driver. 139 | * @discussion kIOPSUPSManagementClaimed is obsolete. Do not use. 140 | * @deprecated Unsupported in OS X 10.5 and later. 141 | */ 142 | #define kIOPSUPSManagementClaimed "/IOKit/UPSPowerManagementClaimed" 143 | 144 | /*! 145 | * @define kIOPSLowWarnLevelKey 146 | * 147 | * @abstract Key for the "Warning" UPS low power trigger-level. Default is 50%. 148 | */ 149 | #define kIOPSLowWarnLevelKey "Low Warn Level" 150 | 151 | /*! 152 | * @define kIOPSDeadWarnLevelKey 153 | * 154 | * @abstract Key for the "Shutdown System" low power trigger-level. Default is 20%. 155 | */ 156 | #define kIOPSDeadWarnLevelKey "Shutdown Level" 157 | 158 | 159 | /*! 160 | * @define kIOPSDynamicStorePath 161 | * 162 | * @abstract This is only used for internal bookkeeping, and should be ignored. 163 | */ 164 | #define kIOPSDynamicStorePath "/IOKit/PowerSources" 165 | 166 | 167 | /*! 168 | * @group Power Source Commands (UPS) 169 | * 170 | */ 171 | 172 | /*! 173 | * @define kIOPSCommandDelayedRemovePowerKey 174 | * 175 | * @abstract Command to give a UPS when it should remove power from its AC plugs in a specified amount of time 176 | * @discussion 177 | *
    178 | *
  • The matching argument should be a CFNumber of kCFNumberIntType specifying when the UPS should 179 | *
  • remove power from its AC power ports. 180 | *
181 | */ 182 | #define kIOPSCommandDelayedRemovePowerKey "Delayed Remove Power" 183 | 184 | /*! 185 | * @define kIOPSCommandEnableAudibleAlarmKey 186 | * 187 | * @abstract Command to give a UPS when it should either enable or disable the audible alarm. 188 | * @discussion 189 | *
    190 | *
  • The matching argument should be a CFBooleanRef where kCFBooleanTrue enables the alarm and 191 | *
  • kCFBooleanFalse diables the alarm 192 | *
193 | */ 194 | 195 | #define kIOPSCommandEnableAudibleAlarmKey "Enable Audible Alarm" 196 | 197 | /*! 198 | * @define kIOPSCommandStartupDelayKey 199 | * 200 | * @abstract Tell UPS how long it should wait for 201 | * @discussion 202 | *
    203 | *
  • The matching argument should be a CFNumber of kCFNumberIntType specifying when the UPS should 204 | *
  • remove power from its AC power ports. 205 | *
206 | */ 207 | #define kIOPSCommandStartupDelayKey "Startup Delay" 208 | 209 | 210 | /*! 211 | * @group Power Source data keys 212 | * 213 | */ 214 | 215 | /* These keys specify the values in a dictionary of PowerSource details. 216 | * Use these keys in conjunction with the dictionary returned by 217 | * @link //apple_ref/c/func/IOPSGetPowerSourceDescription IOPSGetPowerSourceDescription @/link 218 | * 219 | * Clients of @link //apple_ref/c/func/IOPSCreatePowerSource IOPSCreatePowerSource @/link 220 | * must specify these keys in their power source dictionaries. 221 | * Each key is labelled with one of these labels that indicate what information is REQUIRED. to 222 | * represent a power source in OS X. 223 | * 224 | *
    225 | *
  • For power source creators: Providing this key is REQUIRED. 226 | *
  • For power source creators: Providing this key is RECOMMENDED. 227 | *
  • For power source creators: Providing this key is OPTIONAL. 228 | *
  • This key is DEPRECATED, do not provide it. 229 | *
230 | * 231 | */ 232 | 233 | /*! 234 | * @define kIOPSPowerSourceIDKey 235 | * 236 | * @abstract CFNumber key uniquely identifying a UPS attached to the system. 237 | * 238 | * @discussion 239 | *
    240 | *
  • Apple UPS power sources will publish this key. 241 | *
  • Callers should not set this key; OS X power management will publish this key for UPS's. 242 | *
  • Type CFNumber, kCFNumberIntType, uniquely identifying an attached UPS. 243 | *
244 | */ 245 | 246 | #define kIOPSPowerSourceIDKey "Power Source ID" 247 | 248 | 249 | /*! 250 | * @define kIOPSPowerSourceStateKey 251 | * 252 | * @abstract CFDictionary key for the current source of power. 253 | * 254 | * @discussion 255 | *
    256 | *
  • Apple-defined power sources will publish this key. 257 | *
  • For power source creators: Providing this key is REQUIRED. 258 | *
  • @link kIOPSBatteryPowerValue @/link indicates power source is drawing internal power; 259 | * @link kIOPSACPowerValue@/link indicates power source is connected to an external power source. 260 | *
  • Type CFString, value is @link kIOPSACPowerValue@/link, @link kIOPSBatteryPowerValue@/link, or @link kIOPSOffLineValue@/link. 261 | *
262 | */ 263 | 264 | #define kIOPSPowerSourceStateKey "Power Source State" 265 | 266 | /*! 267 | * @define kIOPSCurrentCapacityKey 268 | * @abstract CFDictionary key for the current power source's capacity. 269 | * 270 | * @discussion 271 | *
    272 | *
  • Apple-defined power sources will publish this key in units of percent. 273 | *
  • The power source's software may specify the units for this key. 274 | * The units must be consistent for all capacities reported by this power source. 275 | * The power source will usually define this number in units of percent, or mAh. 276 | *
  • Clients may derive a percentage of power source battery remaining by dividing "Current Capacity" by "Max Capacity" 277 | *
  • For power source creators: Providing this key is REQUIRED. 278 | *
  • Type CFNumber kCFNumberIntType (signed integer) 279 | *
280 | */ 281 | 282 | #define kIOPSCurrentCapacityKey "Current Capacity" 283 | 284 | /*! 285 | * @define kIOPSMaxCapacityKey 286 | * @abstract CFDictionary key for the current power source's maximum or "Full Charge Capacity" 287 | * @discussion 288 | *
    289 | *
  • Apple-defined power sources will publish this key in units of percent. The value is usually 100%. 290 | *
  • The power source's software may specify the units for this key. The units must be consistent for all capacities reported by this power source. 291 | *
  • For power source creators: Providing this key is REQUIRED. 292 | *
  • Type CFNumber kCFNumberIntType (signed integer) 293 | *
294 | */ 295 | 296 | #define kIOPSMaxCapacityKey "Max Capacity" 297 | 298 | /*! 299 | * @define kIOPSDesignCapacityKey 300 | * @abstract CFDictionary key for the current power source's design capacity 301 | * @discussion 302 | *
    303 | *
  • Apple-defined power sources might not publish this key. 304 | *
  • The power source's software may specify the units for this key. The units must be consistent for all capacities reported by this power source. 305 | *
  • For power source creators: Providing this key is RECOMMENDED. 306 | *
  • Type CFNumber kCFNumberIntType (signed integer) 307 | *
308 | */ 309 | 310 | #define kIOPSDesignCapacityKey "DesignCapacity" 311 | 312 | /*! 313 | * @define kIOPSTimeToEmptyKey 314 | * @abstract CFDictionary key for the current power source's time remaining until empty. 315 | * @discussion 316 | * Only valid if the power source is running off its own power. That's when the 317 | * @link kIOPSPowerSourceStateKey @/link has value @link kIOPSBatteryPowerValue @/link 318 | * and the value of @link kIOPSIsChargingKey @/link is kCFBooleanFalse. 319 | *
    320 | *
  • Apple-defined power sources will publish this key. 321 | *
  • For power source creators: Providing this key is RECOMMENDED. 322 | *
  • Type CFNumber kCFNumberIntType (signed integer), units are minutes 323 | *
  • A value of -1 indicates "Still Calculating the Time", otherwise estimated minutes left on the battery. 324 | *
325 | */ 326 | 327 | 328 | #define kIOPSTimeToEmptyKey "Time to Empty" 329 | 330 | /*! 331 | * @define kIOPSTimeToFullChargeKey 332 | * @abstract CFDictionary key for the current power source's time remaining until empty. 333 | * @discussion 334 | * Only valid if the value of @link kIOPSIsChargingKey @/link is kCFBooleanTrue. 335 | *
    336 | *
  • Apple-defined power sources will publish this key. 337 | *
  • For power source creators: Providing this key is RECOMMENDED. 338 | *
  • Type CFNumber kCFNumberIntType (signed integer), units are minutes 339 | *
  • A value of -1 indicates "Still Calculating the Time", otherwise estimated minutes until fully charged. 340 | *
341 | */ 342 | 343 | #define kIOPSTimeToFullChargeKey "Time to Full Charge" 344 | 345 | /*! 346 | * @define kIOPSIsChargingKey 347 | * @abstract CFDictionary key for the current power source's charging state 348 | * @discussion 349 | *
    350 | *
  • Apple-defined power sources will publish this key. 351 | *
  • For power source creators: Providing this key is REQUIRED. 352 | *
  • Type CFBoolean - kCFBooleanTrue or kCFBooleanFalse 353 | *
354 | */ 355 | 356 | #define kIOPSIsChargingKey "Is Charging" 357 | 358 | /*! 359 | * @define kIOPSIsPresentKey 360 | * @abstract CFDictionary key for the current power source's presence. 361 | * @discussion 362 | *
    363 | *
  • Apple-defined power sources will publish this key. 364 | *
  • For instance, a portable with the capacity for two batteries but 365 | * with only one present would show two power source dictionaries, 366 | * but kIOPSIsPresentKey would have the value kCFBooleanFalse in one of them. 367 | *
  • For power source creators: Providing this key is REQUIRED. 368 | *
  • Type CFBoolean - kCFBooleanTrue or kCFBooleanFalse 369 | *
370 | */ 371 | 372 | #define kIOPSIsPresentKey "Is Present" 373 | 374 | /*! 375 | * @define kIOPSVoltageKey 376 | * @abstract CFDictionary key for the current power source's electrical voltage. 377 | * @discussion 378 | *
    379 | *
  • Apple-defined power sources will publish this key. 380 | *
  • For power source creators: Providing this key is RECOMMENDED. 381 | *
  • Type CFNumber kCFNumberIntType (signed integer) - units are mV 382 | *
383 | */ 384 | 385 | #define kIOPSVoltageKey "Voltage" 386 | 387 | /*! 388 | * @define kIOPSCurrentKey 389 | * @abstract CFDictionary key for the current power source's electrical current. 390 | * @discussion 391 | *
    392 | *
  • Apple-defined power sources will publish this key. 393 | *
  • For power source creators: Providing this key is RECOMMENDED. 394 | *
  • Type CFNumber kCFNumberIntType (signed integer) - units are mA 395 | *
396 | */ 397 | 398 | #define kIOPSCurrentKey "Current" 399 | 400 | /*! 401 | * @define kIOPSNameKey 402 | * @abstract CFDictionary key for the current power source's name. 403 | * @discussion 404 | *
    405 | *
  • Apple-defined power sources will publish this key. 406 | *
  • For power source creators: Providing this key is REQUIRED. 407 | *
  • Type CFStringRef 408 | *
409 | */ 410 | 411 | #define kIOPSNameKey "Name" 412 | 413 | 414 | /*! 415 | * @define kIOPSTypeKey 416 | * @abstract CFDictionary key for the type of the power source 417 | * @discussion 418 | *
    419 | *
  • Apple-defined power sources will publish this key. 420 | *
  • For power source creators: Providing this key is REQUIRED. 421 | *
  • Type CFStringRef. Valid transport types are kIOPSUPSType or kIOPSInternalBatteryType. 422 | *
423 | */ 424 | 425 | #define kIOPSTypeKey "Type" 426 | 427 | 428 | /*! 429 | * @define kIOPSTransportTypeKey 430 | * @abstract CFDictionary key for the current power source's data transport type (e.g. the means that the power source conveys power source data to the OS X machine). 431 | * @discussion 432 | *
    433 | *
  • Apple-defined power sources will publish this key. 434 | *
  • A value of @link kIOPSInternalType @/link describes an internal power source. 435 | *
  • @link kIOPSUSBTransportType @/link, @link kIOPSNetworkTransportType @/link, and @link kIOPSSerialTransportType @/link usually describe UPS's. 436 | *
  • For power source creators: Providing this key is REQUIRED. 437 | *
  • Type CFStringRef. Valid transport types are kIOPSSerialTransportType, 438 | * kIOPSUSBTransportType, kIOPSNetworkTransportType, kIOPSInternalType 439 | *
440 | */ 441 | 442 | #define kIOPSTransportTypeKey "Transport Type" 443 | 444 | /*! 445 | * @define kIOPSVendorDataKey 446 | * @abstract CFDictionary key for arbitrary vendor data. 447 | * @discussion 448 | *
    449 | *
  • Apple-defined power sources are not required to publish this key. 450 | *
  • For power source creators: Providing this key is OPTIONAL. 451 | *
  • CFDictionary; contents determined by the power source software. OS X will not look at this data. 452 | *
453 | */ 454 | 455 | #define kIOPSVendorDataKey "Vendor Specific Data" 456 | 457 | /*! 458 | * @define kIOPSBatteryHealthKey 459 | * @abstract CFDictionary key for the current power source's "health" estimate. 460 | * @discussion 461 | *
    462 | *
  • Apple-defined battery power sources will publish this key. 463 | *
  • Use value @link kIOPSGoodValue @/link to describe a well-performing power source, 464 | *
  • Use @link kIOPSFairValue @/link to describe a functional power source with limited capacity 465 | *
  • And use @link kIOPSPoorValue @/link to describe a power source that's not capable of Providing power. 466 | *
  • For power source creators: Providing this key is OPTIONAL. 467 | *
  • Type CFStringRef 468 | *
469 | */ 470 | 471 | #define kIOPSBatteryHealthKey "BatteryHealth" 472 | 473 | /*! 474 | * @define kIOPSBatteryHealthConditionKey 475 | * @abstract kIOPSBatteryHealthConditionKey broadly describes the battery's health. 476 | * @discussion 477 | *
    478 | *
  • Apple-defined power sources will publish this key. 479 | *
  • Value is one of the "Battery Health Condition Values" strings described in this file. 480 | *
  • For power source creators: Providing this key is OPTIONAL - these keys have values only used by Apple power sources. 481 | *
  • Type CFStringRef 482 | *
483 | */ 484 | 485 | #define kIOPSBatteryHealthConditionKey "BatteryHealthCondition" 486 | 487 | /*! 488 | * @define kIOPSBatteryFailureModesKey 489 | * @abstract Enumerates a battery's failures and error conditions. 490 | * @discussion 491 | * Various battery failures will be listed here. A battery may suffer from more than one 492 | * type of failure simultaneously, so this key has a CFArray value. 493 | * 494 | * If BatteryFailureModesKey is not defined (or is set to an empty dictionary), 495 | * then the battery has no detectable failures. 496 | * 497 | * Each entry in the array should be a short descriptive string describing the error. 498 | *
  • Apple-defined power sources will publish this key if any battery errors exist. 499 | *
  • For power source creators: Providing this key is RECOMMENDED. 500 | *
  • Type CFArrayRef 501 | * 502 | */ 503 | #define kIOPSBatteryFailureModesKey "BatteryFailureModes" 504 | 505 | /*! 506 | * @define kIOPSHealthConfidenceKey 507 | * @abstract CFDictionary key for our confidence in the accuracy of our 508 | * power source's "health" estimate. 509 | * @deprecated In OS X 10.6 and later. 510 | * @discussion 511 | *
      512 | *
    • Apple-defined power sources will no longer publish this key. 513 | *
    • Power source creators should not publish this key. 514 | *
    • For power source creators: This key is DEPRECATED, do not implement it. 515 | *
    • Type CFStringRef 516 | *
    517 | */ 518 | 519 | #define kIOPSHealthConfidenceKey "HealthConfidence" 520 | 521 | 522 | /*! 523 | * @define kIOPSMaxErrKey 524 | * @abstract CFDictionary key for the current power source's percentage error in capacity reporting. 525 | * @discussion 526 | * In internal batteries, this refers to the battery pack's estimated percentage error. 527 | *
      528 | *
    • Apple-defined battery power sources will publish this key, but only if it's defined for the battery. 529 | *
    • For power source creators: Providing this key is OPTIONAL. 530 | *
    • Type CFNumberRef kCFNumberIntType, non-negative integer 531 | *
    532 | */ 533 | 534 | #define kIOPSMaxErrKey "MaxErr" 535 | 536 | /*! 537 | * @define kIOPSIsChargedKey 538 | * @abstract CFDictionary key indicates whether the battery is charged. 539 | * @discussion 540 | * A battery must be plugged in to an external power source in order to be fully charged. 541 | * Note that a battery may validly be plugged in, not charging, and <100% charge. 542 | * e.g. A battery with capacity >= 95% and not charging, is defined as charged. 543 | *
      544 | *
    • Apple-defined power sources will publish this key. 545 | *
    • For power source creators: Providing this key is REQUIRED. 546 | *
    • Type CFBoolean - kCFBooleanTrue or kCFBooleanFalse 547 | *
    548 | */ 549 | 550 | #define kIOPSIsChargedKey "Is Charged" 551 | 552 | /*! 553 | * @define kIOPSIsFinishingChargeKey 554 | * @abstract CFDictionary key indicates whether the battery is finishing off its charge. 555 | * @discussion 556 | * When this is true, the system UI should indicate that the battery is "Finishing Charge." 557 | * Some batteries may continue charging after they report 100% capacity. 558 | *
      559 | *
    • Apple-defined battery power sources will publish this key. 560 | *
    • For power source creators: Providing this key is RECOMMENDED. 561 | *
    • Type CFBoolean - kCFBooleanTrue or kCFBooleanFalse 562 | *
    563 | */ 564 | 565 | #define kIOPSIsFinishingChargeKey "Is Finishing Charge" 566 | 567 | /*! 568 | * @define kIOPSHardwareSerialNumberKey 569 | * @abstract A unique serial number that identifies the power source. 570 | * @discussion For Apple-manufactured batteries, this is an alphanumeric string generated 571 | * during the battery manufacturing process. 572 | *
      573 | *
    • Apple-defined power sources will publish this key if the hardware provides the serial number. 574 | *
    • For power source creators: Providing this key is RECOMMENDED. 575 | *
    • Type CFStringRef 576 | *
    577 | */ 578 | 579 | 580 | #define kIOPSHardwareSerialNumberKey "Hardware Serial Number" 581 | 582 | 583 | 584 | /* 585 | * @group Transport types 586 | * @abstract Possible values for @link kIOPSTransportTypeKey @/link 587 | */ 588 | /*! 589 | * @define kIOPSSerialTransportType 590 | * @abstract Value for key @link kIOPSTransportTypeKey @/link. 591 | * @discussion Indicates the power source is a UPS attached over a serial connection. 592 | */ 593 | #define kIOPSSerialTransportType "Serial" 594 | 595 | /*! 596 | * @define kIOPSUSBTransportType 597 | * @abstract Value for key @link kIOPSTransportTypeKey @/link. 598 | * @discussion Indicates the power source is a UPS attached over a USB connection. 599 | */ 600 | #define kIOPSUSBTransportType "USB" 601 | 602 | /*! 603 | * @define kIOPSNetworkTransportType 604 | * @abstract Value for key @link kIOPSTransportTypeKey @/link. 605 | * @discussion Indicates the power source is a UPS attached over a network connection (and it may be managing several computers). 606 | */ 607 | #define kIOPSNetworkTransportType "Ethernet" 608 | 609 | /*! 610 | * @define kIOPSInternalType 611 | * @abstract Value for key @link kIOPSTransportTypeKey @/link. Indicates the power source is an internal battery. 612 | */ 613 | #define kIOPSInternalType "Internal" 614 | 615 | 616 | /* 617 | * @group PowerSource Types 618 | * @discussion 619 | * A string that broadly describes the type of power source. One of these strings must be passed 620 | * as an argument to IOPSCreatePowerSource() when defining a new system power source. 621 | */ 622 | 623 | /*! 624 | * @define kIOPSInternalBatteryType 625 | * 626 | * @abstract Represents a battery residing inside a Mac. 627 | */ 628 | #define kIOPSInternalBatteryType "InternalBattery" 629 | 630 | /*! 631 | * @define kIOPSUPSType 632 | * 633 | * @abstract Represents an external attached UPS. 634 | */ 635 | #define kIOPSUPSType "UPS" 636 | 637 | /* 638 | * PS state 639 | */ 640 | /*! 641 | * @define kIOPSOffLineValue 642 | * @abstract Value for key kIOPSPowerSourceStateKey. Power source is off-line or no longer connected. 643 | */ 644 | #define kIOPSOffLineValue "Off Line" 645 | 646 | /*! 647 | * @define kIOPSACPowerValue 648 | * @abstract Value for key kIOPSPowerSourceStateKey. Power source is connected to external or AC power, and is not draining the internal battery. 649 | */ 650 | #define kIOPSACPowerValue "AC Power" 651 | 652 | /*! 653 | * @define kIOPSBatteryPowerValue 654 | * @abstract Value for key kIOPSPowerSourceStateKey. Power source is currently using the internal battery. 655 | */ 656 | #define kIOPSBatteryPowerValue "Battery Power" 657 | 658 | 659 | 660 | /*! 661 | * @group Battery Health values 662 | */ 663 | /*! 664 | * @define kIOPSPoorValue 665 | * @abstract Value for key @link kIOPSBatteryHealthKey @/link. 666 | */ 667 | #define kIOPSPoorValue "Poor" 668 | 669 | /*! 670 | * @define kIOPSFairValue 671 | * @abstract Value for key @link kIOPSBatteryHealthKey @/link. 672 | */ 673 | #define kIOPSFairValue "Fair" 674 | 675 | /*! 676 | * @define kIOPSGoodValue 677 | * @abstract Value for key @link kIOPSBatteryHealthKey @/link. 678 | */ 679 | #define kIOPSGoodValue "Good" 680 | 681 | 682 | 683 | /* 684 | * @group Battery Health Condition values 685 | */ 686 | /*! 687 | * @define kIOPSCheckBatteryValue 688 | * 689 | * @abstract Value for key @link kIOPSBatteryHealthConditionKey @/link 690 | * 691 | * @discussion This value indicates that the battery should be checked out by a licensed Mac repair service. 692 | */ 693 | #define kIOPSCheckBatteryValue "Check Battery" 694 | 695 | /*! 696 | * @define kIOPSPermanentFailureValue 697 | * 698 | * @abstract Value for key @link kIOPSBatteryHealthConditionKey @/link 699 | * 700 | * @discussion Indicates the battery needs replacement. 701 | */ 702 | #define kIOPSPermanentFailureValue "Permanent Battery Failure" 703 | 704 | 705 | /*! 706 | * @group Battery Failure Mode values 707 | */ 708 | 709 | /*! 710 | * @define kIOPSFailureExternalInput 711 | * 712 | * @abstract Value for key @link kIOPSBatteryFailureModesKey@/link 713 | */ 714 | #define kIOPSFailureExternalInput "Externally Indicated Failure" 715 | /*! 716 | * @define kIOPSFailureSafetyOverVoltage 717 | * 718 | * @abstract Potential value for key @link kIOPSBatteryFailureModesKey@/link 719 | */ 720 | #define kIOPSFailureSafetyOverVoltage "Safety Over-Voltage" 721 | /*! 722 | * @define kIOPSFailureChargeOverTemp 723 | * 724 | * @abstract Potential value for key @link kIOPSBatteryFailureModesKey@/link 725 | */ 726 | #define kIOPSFailureChargeOverTemp "Charge Over-Temperature" 727 | /*! 728 | * @define kIOPSFailureDischargeOverTemp 729 | * 730 | * @abstract Potential value for key @link kIOPSBatteryFailureModesKey@/link 731 | */ 732 | #define kIOPSFailureDischargeOverTemp "Discharge Over-Temperature" 733 | /*! 734 | * @define kIOPSFailureCellImbalance 735 | * 736 | * @abstract Potential value for key @link kIOPSBatteryFailureModesKey@/link 737 | */ 738 | #define kIOPSFailureCellImbalance "Cell Imbalance" 739 | /*! 740 | * @define kIOPSFailureChargeFET 741 | * 742 | * @abstract Potential value for key @link kIOPSBatteryFailureModesKey@/link 743 | */ 744 | #define kIOPSFailureChargeFET "Charge FET" 745 | /*! 746 | * @define kIOPSFailureDischargeFET 747 | * 748 | * @abstract Potential value for key @link kIOPSBatteryFailureModesKey@/link 749 | */ 750 | #define kIOPSFailureDischargeFET "Discharge FET" 751 | /*! 752 | * @define kIOPSFailureDataFlushFault 753 | * 754 | * @abstract Potential value for key @link kIOPSBatteryFailureModesKey@/link 755 | */ 756 | #define kIOPSFailureDataFlushFault "Data Flush Fault" 757 | /*! 758 | * @define kIOPSFailurePermanentAFEComms 759 | * 760 | * @abstract Potential value for key @link kIOPSBatteryFailureModesKey@/link 761 | */ 762 | #define kIOPSFailurePermanentAFEComms "Permanent AFE Comms" 763 | /*! 764 | * @define kIOPSFailurePeriodicAFEComms 765 | * 766 | * @abstract Potential value for key @link kIOPSBatteryFailureModesKey@/link 767 | */ 768 | #define kIOPSFailurePeriodicAFEComms "Periodic AFE Comms" 769 | /*! 770 | * @define kIOPSFailureChargeOverCurrent 771 | * 772 | * @abstract Potential value for key @link kIOPSBatteryFailureModesKey@/link 773 | */ 774 | #define kIOPSFailureChargeOverCurrent "Charge Over-Current" 775 | /*! 776 | * @define kIOPSFailureDischargeOverCurrent 777 | * 778 | * @abstract Potential value for key @link kIOPSBatteryFailureModesKey@/link 779 | */ 780 | #define kIOPSFailureDischargeOverCurrent "Discharge Over-Current" 781 | /*! 782 | * @define kIOPSFailureOpenThermistor 783 | * 784 | * @abstract Potential value for key @link kIOPSBatteryFailureModesKey@/link 785 | */ 786 | #define kIOPSFailureOpenThermistor "Open Thermistor" 787 | /*! 788 | * @define kIOPSFailureFuseBlown 789 | * 790 | * @abstract Potential value for key @link kIOPSBatteryFailureModesKey@/link 791 | */ 792 | #define kIOPSFailureFuseBlown "Fuse Blown" 793 | 794 | 795 | #endif 796 | -------------------------------------------------------------------------------- /ProgressViewDemo/IOPowerSources.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | /* 24 | * HISTORY 25 | * 26 | */ 27 | 28 | #ifndef _IOKIT_IOPOWERSOURCES_H 29 | #define _IOKIT_IOPOWERSOURCES_H 30 | 31 | #include 32 | __BEGIN_DECLS 33 | 34 | 35 | /*! 36 | * @header IOPowerSources.h 37 | * 38 | * @discussion IOPowerSources provides uniform access to the state of power sources attached to the system. 39 | * You can receive a change notification when any power source data changes. 40 | * "Power sources" currently include batteries and UPS devices. 41 | * 42 | * The header follows CF semantics in that it is the caller's responsibility to 43 | * CFRelease() anything returned by a "Copy" function, and the caller should not 44 | * CFRelease() anything returned by a "Get" function. 45 | */ 46 | 47 | /*! 48 | * @functiongroup Low Power Warnings 49 | */ 50 | 51 | /*! @constant kIOPSNotifyLowBattery 52 | * 53 | * @abstract Notify(3) key. IOKit posts kIOPSNotifyLowBattery notifications when the 54 | * system is drawing from limited battery power, and the battery time 55 | * remaining drops into a warnable level. 56 | * 57 | * See also kIOPSNotifyPowerSource, and kIOPSNotifyTimeRemaining 58 | */ 59 | #define kIOPSNotifyLowBattery "com.apple.system.powersources.lowbattery" 60 | 61 | /*! 62 | * @enum IOPSLowBatteryWarningLevel 63 | * 64 | * @discussion Possible return values from @link IOPSGetBatteryWarningLevel@/link 65 | */ 66 | typedef enum { 67 | /*! @constant kIOPSLowBatteryWarningNone 68 | * 69 | * @abstract The system is not in a low battery situation, or is on drawing from an external power source. 70 | * 71 | * @discussion The system displays no low power warnings; neither should application clients of this 72 | * API. 73 | */ 74 | kIOPSLowBatteryWarningNone = 1, 75 | 76 | /*! @constant kIOPSLowBatteryWarningEarly 77 | * 78 | * @abstract The system is in an early low battery situation. 79 | * 80 | * @discussion Per Apple's definition, the battery has dropped below 22% remaining power. 81 | * OS X alerts the user by changing the color of BatteryMonitor to red. 82 | * Warning the user is optional for full screen apps. 83 | */ 84 | kIOPSLowBatteryWarningEarly = 2, 85 | 86 | /*! @constant kIOPSLowBatteryWarningFinal 87 | * 88 | * @abstract The battery can provide no more than 10 minutes of runtime. 89 | * 90 | * @discussion OS X makes no guarantees that the system shall remain in Final Warning for 10 minutes. 91 | * Batteries are frequently calibrated differently and may provide runtime 92 | * for more, or less, than the estimated 10 minutes. 93 | */ 94 | kIOPSLowBatteryWarningFinal = 3 95 | } IOPSLowBatteryWarningLevel; 96 | 97 | /*! @function IOPSGetBatteryWarningLevel 98 | * 99 | * @abstract Indicates whether the system is at a low battery warning level. 100 | * 101 | * @discussion If your app runs in full screen mode and occludes OS X's battery monitor's low 102 | * battery warnings, you should alert the user at least when the system 103 | * is in kIOPSLowBatteryWarnFinal. 104 | */ 105 | IOPSLowBatteryWarningLevel IOPSGetBatteryWarningLevel(void); 106 | 107 | /*! 108 | * @functiongroup Quick Power Source Info 109 | */ 110 | 111 | /*! 112 | * @define kIOPSNotifyTimeRemaining 113 | * C-string key for a notification of changes to any power source's time remaining estimate. 114 | * IOKit also posts this notification when the active power source changes between AC, Battery, and UPS. 115 | * 116 | * If you only need to detect when the power source changes between AC, Battery, or UPS, please use 117 | * @link kIOPSNotifyPowerSource @/link; your code will run less often and conserve battery life. 118 | * 119 | * See API @link IOPSGetTimeRemainingEstimate @/link to determine whether the active power source is 120 | * limited or unlimited; and to determine the estimated time remaining until empty. 121 | * 122 | * Use notify(3) API to register for notifications. 123 | */ 124 | #define kIOPSNotifyTimeRemaining "com.apple.system.powersources.timeremaining" 125 | #define kIOPSTimeRemainingNotificationKey kIOPSNotifyTimeRemaining 126 | 127 | /*! 128 | * @define kIOPSNotifyPowerSource 129 | * @abstract C-string key for a notification of changes to the active power source. 130 | * @discussion Use this notification to discover when the active power source changes from AC power (unlimited/wall power), 131 | * to Battery Power or UPS Power (limited power). IOKit will not deliver this notification when a battery's 132 | * time remaining changes, only when the active power source changes. This makes it a more effiicent 133 | * choice for clients only interested in differentiating AC vs Battery. 134 | * 135 | * See API @link IOPSGetTimeRemainingEstimate @/link to determine whether the active power source is 136 | * limited or unlimited. 137 | * 138 | * Example: IOKit posts kIOPSNotifyPowerSource upon connecting or disconnecting AC power to a laptop. 139 | * IOKit posts kIOPSNotifyPowerSource upon a UPS losing AC Power; as the system switches to a limited 140 | * UPS battery power source. 141 | * 142 | * Use notify(3) API to register for notifications. 143 | * */ 144 | #define kIOPSNotifyPowerSource "com.apple.system.powersources.source" 145 | 146 | /*! 147 | * @define kIOPSNotifyAttach 148 | * @abstract C-string key for a notification when a power source is attached or detached. 149 | * @discussion Example: IOKit posts kIOPSNotifyAttach upon detection of internal battery. 150 | * IOKit posts kIOPSNotifyAttach when a user attaches or detaches an external UPS. 151 | * 152 | * Note that IOKit doesn't deliver kIOPSNotifyAttach upon plugging or unplugging AC Power to a laptop; see 153 | * @link kIOPSNotifyPowerSource@/link for changes to the active power source. 154 | * 155 | * IOKit may take many seconds to discover a built-in battery at boot time. If your user process runs 156 | * at early boot, use kIOPSNotifyAttach to detect an IOPowerSource's appearance. 157 | * Use notify(3) API to register for notifications. 158 | */ 159 | #define kIOPSNotifyAttach "com.apple.system.powersources.attach" 160 | 161 | /*! 162 | * @define kIOPSNotifyAnyPowerSource 163 | * @abstract C-string key for a notification that of changes to any attribute of any IOPowerSource. 164 | * @discussion Use notify(3) API to register for notifications. 165 | * IOKit posts this notificatino more frequently than the other notifications, and thus uses more 166 | * energy to run your code. To conserve CPU cycles and battery life, please consider another notification 167 | * that also fits your needs. Please consider these instead: 168 | * @link kIOPSNotifyPowerSource @/link, 169 | * @link kIOPSNotifyTimeRemaining @/link 170 | * 171 | */ 172 | #define kIOPSNotifyAnyPowerSource "com.apple.system.powersources" 173 | 174 | /*! 175 | * @constant kIOPSTimeRemainingUnknown 176 | * Possible return value from @link IOPSGetTimeRemainingEstimate@/link 177 | * Indicates the system is connected to a limited power source, but the system is still 178 | * calculating a time remaining estimate. Check for a valid estimate again when IOKit posts the 179 | * notification @link kIOPSPowerSourcesNotificationKey@/link. 180 | */ 181 | #define kIOPSTimeRemainingUnknown ((CFTimeInterval)-1.0) 182 | 183 | /*! 184 | * @constant kIOPSTimeRemainingUnlimited 185 | * Possible return value from @link IOPSGetTimeRemainingEstimate@/link 186 | * Indicates the system is connected to an external power source, without a time limit. 187 | */ 188 | #define kIOPSTimeRemainingUnlimited ((CFTimeInterval)-2.0) 189 | 190 | /*! 191 | * @function IOPSGetTimeRemainingEstimate 192 | * 193 | * @abstract Returns the estimated minutes remaining until all power sources 194 | * (battery and/or UPS's) are empty, or returns @link kIOPSTimeRemainingUnlimited@/link 195 | * if attached to an unlimited power source. 196 | * 197 | * @discussion 198 | * If attached to an "Unlimited" power source, like AC power or any external source, the 199 | * return value is @link kIOPSTimeRemainingUnlimited@/link 200 | * 201 | * If the system is on "Limited" power, like a battery or UPS, 202 | * but is still calculating the time remaining, which may 203 | * take several seconds after each system power event 204 | * (e.g. waking from sleep, or unplugging AC Power), the return value is 205 | * @link kIOPSTimeRemainingUnknown@/link 206 | * 207 | * Otherwise, if the system is on "Limited" power and the system has an accurate time 208 | * remaining estimate, the system returns a CFTimeInterval estimate of the time 209 | * remaining until the system is out of battery power. 210 | * 211 | * If you require more detailed battery information, use 212 | * @link IOPSCopyPowerSourcesInfo @/link> 213 | * and @link IOPSGetPowerSourceDescription @/link>. 214 | * 215 | * @result 216 | * Returns @link kIOPSTimeRemainingUnknown@/link if the 217 | * OS cannot determine the time remaining. 218 | * 219 | * Returns @link kIOPSTimeRemainingUnlimited@/link if the 220 | * system has an unlimited power source. 221 | * 222 | * Otherwise returns a positive number of type CFTimeInterval, indicating the time 223 | * remaining in seconds until all power sources are depleted. 224 | */ 225 | CFTimeInterval IOPSGetTimeRemainingEstimate(void); 226 | 227 | 228 | /*! 229 | * @functiongroup Power Source Descriptions 230 | */ 231 | 232 | typedef void (*IOPowerSourceCallbackType)(void *context); 233 | 234 | /*! @function IOPSCopyPowerSourcesInfo 235 | * 236 | * @abstract Returns a blob of Power Source information in an opaque CFTypeRef. 237 | * 238 | * @discussion Clients should not directly access data in the returned CFTypeRef - 239 | * they should use the accessor functions IOPSCopyPowerSourcesList and 240 | * IOPSGetPowerSourceDescription, instead. 241 | * 242 | * @result NULL if errors were encountered, a CFTypeRef otherwise. 243 | * Caller must CFRelease() the return value when done accessing it. 244 | */ 245 | CFTypeRef IOPSCopyPowerSourcesInfo(void); 246 | 247 | /*! 248 | * @function IOPSGetProvidingPowerSourceType 249 | * 250 | * @abstract Indicates the power source the computer is currently drawing from. 251 | * 252 | * @discussion Determines which power source is providing power. 253 | * 254 | * @param snapshot The CFTypeRef returned by IOPSCopyPowerSourcesInfo(); caller may pass NULL. 255 | * 256 | * @result One of: CFSTR(kIOPMACPowerKey), CFSTR(kIOPMBatteryPowerKey), CFSTR(kIOPMUPSPowerKey) 257 | */ 258 | CFStringRef IOPSGetProvidingPowerSourceType(CFTypeRef snapshot); 259 | 260 | /*! @function IOPSCopyPowerSourcesList 261 | * 262 | * @abstract Returns a CFArray of Power Source handles, each of type CFTypeRef. 263 | * 264 | * @discussion The caller shouldn't directly access the CFTypeRefs, but should use 265 | * IOPSGetPowerSourceDescription on each member of the CFArrayRef. 266 | * 267 | * @param blob Takes the CFTypeRef returned by IOPSCopyPowerSourcesInfo() 268 | * 269 | * @result Returns NULL if errors were encountered, otherwise a CFArray of CFTypeRefs. 270 | * Caller must CFRelease() the returned CFArrayRef. 271 | */ 272 | CFArrayRef IOPSCopyPowerSourcesList(CFTypeRef blob); 273 | 274 | /*! @function IOPSGetPowerSourceDescription 275 | * 276 | * @abstract Returns a CFDictionary with readable information about the specific power source. 277 | * 278 | * @discussion See the C-strings defined in IOPSKeys.h for specific keys into the dictionary. 279 | * Don't expect all keys to be present in any dictionary. Some power sources, for example, 280 | * may not support the "Time Remaining To Empty" key and it will not be present in their dictionaries. 281 | * 282 | * @param blob The CFTypeRef returned by IOPSCopyPowerSourcesInfo() 283 | * 284 | * @param ps One of the CFTypeRefs in the CFArray returned by IOPSCopyPowerSourcesList() 285 | * 286 | * @result Returns NULL if an error was encountered, otherwise a CFDictionary. Caller should 287 | * NOT release the returned CFDictionary - it will be released as part of the CFTypeRef returned by 288 | * IOPSCopyPowerSourcesInfo(). 289 | */ 290 | CFDictionaryRef IOPSGetPowerSourceDescription(CFTypeRef blob, CFTypeRef ps); 291 | 292 | /*! @function IOPSGetProvidingPowerSourceType 293 | * 294 | * @abstract Indicates the power source the computer is currently drawing from. 295 | * 296 | * @discussion Determines which power source is providing power. 297 | * 298 | * @param snapshot The CFTypeRef returned by IOPSCopyPowerSourcesInfo() 299 | * 300 | * @result One of: CFSTR(kIOPMACPowerKey), CFSTR(kIOPMBatteryPowerKey), CFSTR(kIOPMUPSPowerKey) 301 | */ 302 | CFStringRef IOPSGetProvidingPowerSourceType(CFTypeRef snapshot); 303 | 304 | /*! @function IOPSNotificationCreateRunLoopSource 305 | * 306 | * @abstract Returns a CFRunLoopSourceRef that notifies the caller when power source 307 | * information changes. 308 | * 309 | * @discussion Returns a CFRunLoopSourceRef for scheduling with your CFRunLoop. 310 | * If your project does not use a CFRunLoop, you can alternatively 311 | * receive notifications via mach port, dispatch, or signal, via notify.h 312 | * using the name @link kIOPSTimeRemainingNotificationKey @/link. 313 | * 314 | * IOKit delivers this notification when percent remaining or time remaining changes. 315 | * Thus it fires fairly frequently while discharging or charging the battery; 316 | * please consider using: 317 | * @link IOPSCreateLimitedPowerNotification @/link if you only require 318 | * notifications when the power source type changes from limited to unlimited. 319 | * 320 | * @param callback A function to be called whenever any power source is added, removed, or changes. 321 | * 322 | * @param context Any user-defined pointer, passed to the IOPowerSource callback. 323 | * 324 | * @result Returns NULL if an error was encountered, otherwise a CFRunLoopSource. Caller must 325 | * release the CFRunLoopSource. 326 | */ 327 | CFRunLoopSourceRef IOPSNotificationCreateRunLoopSource(IOPowerSourceCallbackType callback, void *context); 328 | 329 | /*! @function IOPSCreateLimitedPowerNotification 330 | * 331 | * @abstract Returns a CFRunLoopSourceRef that notifies the caller when power source 332 | * changes from an unlimited power source (like attached to wall, car, or airplane power), to a limited 333 | * power source (like a battery or UPS). 334 | * 335 | * @discussion Returns a CFRunLoopSourceRef for scheduling with your CFRunLoop. 336 | * If your project does not use a CFRunLoop, you can alternatively 337 | * receive this notification via notify.h 338 | * using the name @link kIOPSNotifyPowerSource @/link 339 | * 340 | * @param callback A function to be called whenever the power source changes from AC to DC.. 341 | * 342 | * @param context Any user-defined pointer, passed to the IOPowerSource callback. 343 | * 344 | * @result Returns NULL if an error was encountered, otherwise a CFRunLoopSource. Caller must 345 | * release the CFRunLoopSource. 346 | */ 347 | CFRunLoopSourceRef IOPSCreateLimitedPowerNotification(IOPowerSourceCallbackType callback, void *context) __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0); 348 | 349 | /*! @function IOPSCopyExternalPowerAdapterDetails 350 | * 351 | * @abstract Returns a CFDictionary that describes the attached (AC) external 352 | * power adapter (if any external power adapter is attached. 353 | * 354 | * @discussion Use the kIOPSPowerAdapter... keys described in IOPSKeys.h 355 | * to interpret the returned CFDictionary. 356 | * 357 | * @result Returns a CFDictionary on success. Caller must release the returned 358 | * dictionary. If no adapter is attached, or if there's an error, returns NULL. 359 | */ 360 | CFDictionaryRef IOPSCopyExternalPowerAdapterDetails(void); 361 | 362 | __END_DECLS 363 | 364 | #endif /* _IOKIT_IOPOWERSOURCES_H */ 365 | -------------------------------------------------------------------------------- /ProgressViewDemo/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" : "40x40", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "60x60", 16 | "scale" : "2x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /ProgressViewDemo/Images.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "iphone", 6 | "extent" : "full-screen", 7 | "minimum-system-version" : "7.0", 8 | "scale" : "2x" 9 | }, 10 | { 11 | "orientation" : "portrait", 12 | "idiom" : "iphone", 13 | "subtype" : "retina4", 14 | "extent" : "full-screen", 15 | "minimum-system-version" : "7.0", 16 | "scale" : "2x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /ProgressViewDemo/ProgressViewDemo-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | com.mypower.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /ProgressViewDemo/ProgressViewDemo-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #import 8 | 9 | #ifndef __IPHONE_3_0 10 | #warning "This project uses features only available in iOS SDK 3.0 and later." 11 | #endif 12 | 13 | #ifdef __OBJC__ 14 | #import 15 | #import 16 | #define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0] 17 | 18 | 19 | #define iPad ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) 20 | #define iPhone ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) 21 | 22 | #define ViewHeight [[UIScreen mainScreen] bounds].size.height 23 | #define ViewWidth [[UIScreen mainScreen] bounds].size.width 24 | 25 | #define iPhone5 ([[UIScreen mainScreen] bounds].size.height >=568) 26 | //判断是否为iPhone 27 | #define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) 28 | //判断是否为iPad 29 | #define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 30 | //判断是否为ipod 31 | #define IS_IPOD ([[[UIDevice currentDevice] model] isEqualToString:@"iPod touch"]) 32 | //判断是否为iPhone5 33 | #define IS_IPHONE_5_SCREEN [[UIScreen mainScreen] bounds].size.height >= 568.0f && [[UIScreen mainScreen] bounds].size.height < 1024.0f 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /ProgressViewDemo/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /ProgressViewDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // ProgressViewDemo 4 | // 5 | // Created by mr.cao on 14-5-27. 6 | // Copyright (c) 2014年 mrcao. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "CCAppDelegate.h" 12 | 13 | int main(int argc, char * argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([CCAppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ProgressViewDemoTests/ProgressViewDemoTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | com.mypower.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /ProgressViewDemoTests/ProgressViewDemoTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // ProgressViewDemoTests.m 3 | // ProgressViewDemoTests 4 | // 5 | // Created by mr.cao on 14-5-27. 6 | // Copyright (c) 2014年 mrcao. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ProgressViewDemoTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation ProgressViewDemoTests 16 | 17 | - (void)setUp 18 | { 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 | { 25 | // Put teardown code here. This method is called after the invocation of each test method in the class. 26 | [super tearDown]; 27 | } 28 | 29 | - (void)testExample 30 | { 31 | XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__); 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /ProgressViewDemoTests/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ProgressView 2 | ============ 3 | 4 | iOS Jinshan imitate animation battery power, power 1% error, the progress bar can be tilted with equipment, water ripple effect 模仿金山电池电量的动画效果,电量有1%的误差,进度条可随着设备倾斜,有水波纹效果 5 | 6 | 7 | ![image](https://github.com/caoguoqing/ProgressView/raw/master/jinshan.gif) 8 | -------------------------------------------------------------------------------- /UICountingLabel/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Tim Gostony 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /UICountingLabel/README.md: -------------------------------------------------------------------------------- 1 | # UICountingLabel #### 2 | 3 | Adds animated counting support to `UILabel`. 4 | 5 | 6 | ## Setup ###### 7 | Simply initialize a `UICountingLabel` the same way you set up a regular `UILabel`: 8 | 9 | UICountingLabel* myLabel = [[UICountingLabel alloc] initWithFrame:CGRectMake(10, 10, 100, 40)]; 10 | [self.view addSubview:myLabel]; 11 | [myLabel release]; 12 | 13 | You can also add it to your XIB file, just make sure you set the class type to `UICountingLabel` instead of `UILabel` and be sure to `#import "UICountingLabel.h"` in the header file. 14 | 15 | ## Use ##### 16 | 17 | Set the format of your label. This will be filled with a single int or float (depending on how you format it) when it updates: 18 | 19 | myLabel.format = @"%d"; 20 | 21 | Optionally, set the mode. The default is `UILabelCountingMethodEaseInOut`, which will start slow, speed up, and then slow down as it reaches the end. Other options are described below in the Methods section. 22 | 23 | myLabel.method = UILabelCountingMethodLinear; 24 | 25 | When you want the label to start counting, just call: 26 | 27 | [myLabel countFrom:0 to:100]; 28 | 29 | You can also specify the duration. The default is 2.0 seconds. 30 | 31 | [myLabel countFrom:0 to:100 withDuration:5.0f]; 32 | 33 | The full signature is: 34 | 35 | [myLabel countFrom:(float)startValue 36 | to:(float)endValue 37 | withDuration:(NSTimeInterval)duration]; 38 | 39 | ## Formats ##### 40 | 41 | When you set the `format` property, the label will look for the presence of `%(.*)d` or `%(.*)i`, and if found, will cast the value to `int` before formatting the string. Otherwise, it will format it using a `float`. 42 | 43 | If you're using a `float` value, it's recommended to limit the number of digits with a format string, such as `@"%.1f"` for one decimal place. 44 | 45 | Because it uses the standard `stringWithFormat:` method, you can also include arbitrary text in your format, such as `@"Points: %i"`. 46 | 47 | ## Modes ##### 48 | There are currently four modes of counting. 49 | 50 | ### `UILabelCountingMethodLinear` ##### 51 | Counts linearly from the start to the end. 52 | 53 | ### `UILabelCountingMethodEaseIn` ##### 54 | Ease In starts out slow and speeds up counting as it gets to the end, stopping suddenly at the final value. 55 | 56 | ### `UILabelCountingMethodEaseOut` ##### 57 | Ease Out starts out fast and slows down as it gets to the destination value. 58 | 59 | ### `UILabelCountingMethodEaseInOut` ##### 60 | Ease In/Out starts out slow, speeds up towards the middle, and then slows down as it approaches the destination. It is a nice, smooth curve that looks great, and is the default method. 61 | -------------------------------------------------------------------------------- /UICountingLabel/UICountingLabel.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | typedef enum { 5 | UILabelCountingMethodEaseInOut, 6 | UILabelCountingMethodEaseIn, 7 | UILabelCountingMethodEaseOut, 8 | UILabelCountingMethodLinear 9 | } UILabelCountingMethod; 10 | 11 | typedef NSString* (^UICountingLabelFormatBlock)(float value); 12 | 13 | 14 | @interface UICountingLabel : UILabel 15 | 16 | @property (nonatomic, strong) NSString *format; 17 | @property (nonatomic, assign) UILabelCountingMethod method; 18 | 19 | @property (nonatomic, copy) UICountingLabelFormatBlock formatBlock; 20 | @property (nonatomic, copy) void (^completionBlock)(); 21 | 22 | 23 | -(void)countFrom:(float)startValue to:(float)endValue; 24 | -(void)countFrom:(float)startValue to:(float)endValue withDuration:(NSTimeInterval)duration; 25 | 26 | @end 27 | 28 | -------------------------------------------------------------------------------- /UICountingLabel/UICountingLabel.m: -------------------------------------------------------------------------------- 1 | #import "UICountingLabel.h" 2 | 3 | 4 | #pragma mark - UILabelCounter 5 | 6 | // This whole class & subclasses are private to UICountingLabel, which is why they are declared here in the .m file 7 | 8 | @interface UILabelCounter : NSObject 9 | 10 | -(float)update:(float)t; 11 | 12 | @property float rate; 13 | 14 | @end 15 | 16 | @interface UILabelCounterLinear : UILabelCounter 17 | 18 | @end 19 | 20 | @interface UILabelCounterEaseIn : UILabelCounter 21 | 22 | @end 23 | 24 | @interface UILabelCounterEaseOut : UILabelCounter 25 | 26 | @end 27 | 28 | @interface UILabelCounterEaseInOut : UILabelCounter 29 | 30 | @end 31 | 32 | @implementation UILabelCounter 33 | 34 | -(float)update:(float)t{ 35 | return 0; 36 | } 37 | 38 | @end 39 | 40 | @implementation UILabelCounterLinear 41 | 42 | -(float)update:(float)t 43 | { 44 | return t; 45 | } 46 | 47 | @end 48 | 49 | @implementation UILabelCounterEaseIn 50 | 51 | -(float)update:(float)t 52 | { 53 | return powf(t, self.rate); 54 | } 55 | 56 | @end 57 | 58 | @implementation UILabelCounterEaseOut 59 | 60 | -(float)update:(float)t{ 61 | return 1.0-powf((1.0-t), self.rate); 62 | } 63 | 64 | @end 65 | 66 | @implementation UILabelCounterEaseInOut 67 | 68 | -(float) update: (float) t 69 | { 70 | int sign =1; 71 | int r = (int) self.rate; 72 | if (r % 2 == 0) 73 | sign = -1; 74 | t *= 2; 75 | if (t < 1) 76 | return 0.5f * powf (t, self.rate); 77 | else 78 | return sign*0.5f * (powf (t-2, self.rate) + sign*2); 79 | } 80 | 81 | @end 82 | 83 | #pragma mark - UICountingLabel 84 | 85 | @interface UICountingLabel () 86 | 87 | @property float startingValue; 88 | @property float destinationValue; 89 | @property NSTimeInterval progress; 90 | @property NSTimeInterval lastUpdate; 91 | @property NSTimeInterval totalTime; 92 | @property float easingRate; 93 | 94 | @property (nonatomic, retain) UILabelCounter* counter; 95 | 96 | @end 97 | 98 | @implementation UICountingLabel 99 | 100 | -(void)countFrom:(float)value to:(float)endValue 101 | { 102 | [self countFrom:value to:endValue withDuration:2.0f]; 103 | } 104 | 105 | -(void)countFrom:(float)startValue to:(float)endValue withDuration:(NSTimeInterval)duration 106 | { 107 | 108 | self.easingRate = 3.0f; 109 | self.startingValue = startValue; 110 | self.destinationValue = endValue; 111 | self.progress = 0; 112 | self.totalTime = duration; 113 | self.lastUpdate = [NSDate timeIntervalSinceReferenceDate]; 114 | 115 | if(self.format == nil) 116 | //self.format = @"%f"; 117 | self.format = @"%d"; 118 | 119 | switch(self.method) 120 | { 121 | case UILabelCountingMethodLinear: 122 | self.counter = [[UILabelCounterLinear alloc] init]; 123 | break; 124 | case UILabelCountingMethodEaseIn: 125 | self.counter = [[UILabelCounterEaseIn alloc] init]; 126 | break; 127 | case UILabelCountingMethodEaseOut: 128 | self.counter = [[UILabelCounterEaseOut alloc] init]; 129 | break; 130 | case UILabelCountingMethodEaseInOut: 131 | self.counter = [[UILabelCounterEaseInOut alloc] init]; 132 | break; 133 | } 134 | 135 | self.counter.rate = 3.0f; 136 | 137 | NSTimer* timer = [NSTimer timerWithTimeInterval:(1.0f/30.0f) target:self selector:@selector(updateValue:) userInfo:nil repeats:YES]; 138 | [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode]; 139 | } 140 | 141 | -(void)updateValue:(NSTimer*)timer 142 | { 143 | // update progress 144 | NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate]; 145 | self.progress += now - self.lastUpdate; 146 | self.lastUpdate = now; 147 | 148 | if(self.progress >= self.totalTime) 149 | { 150 | [timer invalidate]; 151 | self.progress = self.totalTime; 152 | } 153 | 154 | float percent = self.progress / self.totalTime; 155 | float updateVal =[self.counter update:percent]; 156 | float value = self.startingValue + (updateVal * (self.destinationValue - self.startingValue)); 157 | 158 | 159 | if(self.formatBlock != nil) 160 | { 161 | self.text = self.formatBlock(value); 162 | } 163 | else 164 | { 165 | // check if counting with ints - cast to int 166 | if([self.format rangeOfString:@"%(.*)d" options:NSRegularExpressionSearch].location != NSNotFound || [self.format rangeOfString:@"%(.*)i"].location != NSNotFound ) 167 | { 168 | self.text = [NSString stringWithFormat:self.format,(int)value]; 169 | } 170 | else 171 | { 172 | self.text = [NSString stringWithFormat:self.format,value]; 173 | } 174 | } 175 | 176 | if(self.progress == self.totalTime && self.completionBlock != nil) 177 | { 178 | self.completionBlock(); 179 | self.completionBlock = nil; 180 | } 181 | } 182 | 183 | @end 184 | -------------------------------------------------------------------------------- /UIDevice+ProcessesAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIDevice+ProcessesAdditions.h 3 | // ProgressViewDemo 4 | // 5 | // Created by mr.cao on 14-5-28. 6 | // Copyright (c) 2014年 mrcao. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIDevice (ProcessesAdditions) 12 | - (NSArray *)runningProcesses; 13 | @end 14 | -------------------------------------------------------------------------------- /UIDevice+ProcessesAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIDevice+ProcessesAdditions.m 3 | // ProgressViewDemo 4 | // 5 | // Created by mr.cao on 14-5-28. 6 | // Copyright (c) 2014年 mrcao. All rights reserved. 7 | // 8 | 9 | #import "UIDevice+ProcessesAdditions.h" 10 | #import 11 | @implementation UIDevice (ProcessesAdditions) 12 | - (NSArray *)runningProcesses { 13 | 14 | int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0}; 15 | size_t miblen = 4; 16 | 17 | size_t size; 18 | int st = sysctl(mib, miblen, NULL, &size, NULL, 0); 19 | 20 | struct kinfo_proc * process = NULL; 21 | struct kinfo_proc * newprocess = NULL; 22 | 23 | do { 24 | 25 | size += size / 10; 26 | newprocess = realloc(process, size); 27 | 28 | if (!newprocess){ 29 | 30 | if (process){ 31 | free(process); 32 | } 33 | 34 | return nil; 35 | } 36 | 37 | process = newprocess; 38 | st = sysctl(mib, miblen, process, &size, NULL, 0); 39 | 40 | } while (st == -1 && errno == ENOMEM); 41 | 42 | if (st == 0){ 43 | 44 | if (size % sizeof(struct kinfo_proc) == 0){ 45 | int nprocess = size / sizeof(struct kinfo_proc); 46 | 47 | if (nprocess){ 48 | 49 | NSMutableArray * array = [[NSMutableArray alloc] init]; 50 | 51 | for (int i = nprocess - 1; i >= 0; i--){ 52 | 53 | NSString * processID = [[NSString alloc] initWithFormat:@"%d", process[i].kp_proc.p_pid]; 54 | NSString * processName = [[NSString alloc] initWithFormat:@"%s", process[i].kp_proc.p_comm]; 55 | 56 | NSDictionary * dict = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:processID, processName, nil] 57 | forKeys:[NSArray arrayWithObjects:@"ProcessID", @"ProcessName", nil]]; 58 | //[processID release]; 59 | //[processName release]; 60 | [array addObject:dict]; 61 | //[dict release]; 62 | } 63 | 64 | free(process); 65 | return array;//[array autorelease]; 66 | } 67 | } 68 | } 69 | 70 | return nil; 71 | } 72 | 73 | @end 74 | -------------------------------------------------------------------------------- /jinshan.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrcao2011/ProgressView/2825fe0f0e34685e6b97ce4dcdc31b2a98d22183/jinshan.gif --------------------------------------------------------------------------------