├── .gitignore ├── AVFlatSwitch.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── AVFlatSwitch ├── AppDelegate.h ├── AppDelegate.m ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard ├── Images.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Info.plist ├── ViewController.h ├── ViewController.m ├── ZDFlatSwitch.h ├── ZDFlatSwitch.m └── main.m ├── AVFlatSwitchTests ├── AVFlatSwitchTests.m └── Info.plist ├── LICENSE ├── README.md └── ZDFlatSwitch ├── ZDFlatSwitch.h └── ZDFlatSwitch.m /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | #Pods/ 27 | -------------------------------------------------------------------------------- /AVFlatSwitch.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | D889DF2C1B2A8133006651AD /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = D889DF2B1B2A8133006651AD /* main.m */; }; 11 | D889DF2F1B2A8133006651AD /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = D889DF2E1B2A8133006651AD /* AppDelegate.m */; }; 12 | D889DF321B2A8133006651AD /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D889DF311B2A8133006651AD /* ViewController.m */; }; 13 | D889DF351B2A8133006651AD /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D889DF331B2A8133006651AD /* Main.storyboard */; }; 14 | D889DF371B2A8133006651AD /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D889DF361B2A8133006651AD /* Images.xcassets */; }; 15 | D889DF3A1B2A8133006651AD /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = D889DF381B2A8133006651AD /* LaunchScreen.xib */; }; 16 | D889DF461B2A8133006651AD /* AVFlatSwitchTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D889DF451B2A8133006651AD /* AVFlatSwitchTests.m */; }; 17 | D889DF511B2A8182006651AD /* ZDFlatSwitch.m in Sources */ = {isa = PBXBuildFile; fileRef = D889DF501B2A8182006651AD /* ZDFlatSwitch.m */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXContainerItemProxy section */ 21 | D889DF401B2A8133006651AD /* PBXContainerItemProxy */ = { 22 | isa = PBXContainerItemProxy; 23 | containerPortal = D889DF1E1B2A8133006651AD /* Project object */; 24 | proxyType = 1; 25 | remoteGlobalIDString = D889DF251B2A8133006651AD; 26 | remoteInfo = AVFlatSwitch; 27 | }; 28 | /* End PBXContainerItemProxy section */ 29 | 30 | /* Begin PBXFileReference section */ 31 | D889DF261B2A8133006651AD /* AVFlatSwitch.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AVFlatSwitch.app; sourceTree = BUILT_PRODUCTS_DIR; }; 32 | D889DF2A1B2A8133006651AD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 33 | D889DF2B1B2A8133006651AD /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 34 | D889DF2D1B2A8133006651AD /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 35 | D889DF2E1B2A8133006651AD /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 36 | D889DF301B2A8133006651AD /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 37 | D889DF311B2A8133006651AD /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 38 | D889DF341B2A8133006651AD /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 39 | D889DF361B2A8133006651AD /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 40 | D889DF391B2A8133006651AD /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 41 | D889DF3F1B2A8133006651AD /* AVFlatSwitchTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AVFlatSwitchTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 42 | D889DF441B2A8133006651AD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 43 | D889DF451B2A8133006651AD /* AVFlatSwitchTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AVFlatSwitchTests.m; sourceTree = ""; }; 44 | D889DF4F1B2A8182006651AD /* ZDFlatSwitch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ZDFlatSwitch.h; sourceTree = ""; }; 45 | D889DF501B2A8182006651AD /* ZDFlatSwitch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ZDFlatSwitch.m; sourceTree = ""; }; 46 | /* End PBXFileReference section */ 47 | 48 | /* Begin PBXFrameworksBuildPhase section */ 49 | D889DF231B2A8133006651AD /* Frameworks */ = { 50 | isa = PBXFrameworksBuildPhase; 51 | buildActionMask = 2147483647; 52 | files = ( 53 | ); 54 | runOnlyForDeploymentPostprocessing = 0; 55 | }; 56 | D889DF3C1B2A8133006651AD /* Frameworks */ = { 57 | isa = PBXFrameworksBuildPhase; 58 | buildActionMask = 2147483647; 59 | files = ( 60 | ); 61 | runOnlyForDeploymentPostprocessing = 0; 62 | }; 63 | /* End PBXFrameworksBuildPhase section */ 64 | 65 | /* Begin PBXGroup section */ 66 | D889DF1D1B2A8133006651AD = { 67 | isa = PBXGroup; 68 | children = ( 69 | D889DF281B2A8133006651AD /* AVFlatSwitch */, 70 | D889DF421B2A8133006651AD /* AVFlatSwitchTests */, 71 | D889DF271B2A8133006651AD /* Products */, 72 | ); 73 | sourceTree = ""; 74 | }; 75 | D889DF271B2A8133006651AD /* Products */ = { 76 | isa = PBXGroup; 77 | children = ( 78 | D889DF261B2A8133006651AD /* AVFlatSwitch.app */, 79 | D889DF3F1B2A8133006651AD /* AVFlatSwitchTests.xctest */, 80 | ); 81 | name = Products; 82 | sourceTree = ""; 83 | }; 84 | D889DF281B2A8133006651AD /* AVFlatSwitch */ = { 85 | isa = PBXGroup; 86 | children = ( 87 | D889DF2D1B2A8133006651AD /* AppDelegate.h */, 88 | D889DF2E1B2A8133006651AD /* AppDelegate.m */, 89 | D889DF301B2A8133006651AD /* ViewController.h */, 90 | D889DF311B2A8133006651AD /* ViewController.m */, 91 | D889DF331B2A8133006651AD /* Main.storyboard */, 92 | D889DF361B2A8133006651AD /* Images.xcassets */, 93 | D889DF381B2A8133006651AD /* LaunchScreen.xib */, 94 | D889DF291B2A8133006651AD /* Supporting Files */, 95 | D889DF4F1B2A8182006651AD /* ZDFlatSwitch.h */, 96 | D889DF501B2A8182006651AD /* ZDFlatSwitch.m */, 97 | ); 98 | path = AVFlatSwitch; 99 | sourceTree = ""; 100 | }; 101 | D889DF291B2A8133006651AD /* Supporting Files */ = { 102 | isa = PBXGroup; 103 | children = ( 104 | D889DF2A1B2A8133006651AD /* Info.plist */, 105 | D889DF2B1B2A8133006651AD /* main.m */, 106 | ); 107 | name = "Supporting Files"; 108 | sourceTree = ""; 109 | }; 110 | D889DF421B2A8133006651AD /* AVFlatSwitchTests */ = { 111 | isa = PBXGroup; 112 | children = ( 113 | D889DF451B2A8133006651AD /* AVFlatSwitchTests.m */, 114 | D889DF431B2A8133006651AD /* Supporting Files */, 115 | ); 116 | path = AVFlatSwitchTests; 117 | sourceTree = ""; 118 | }; 119 | D889DF431B2A8133006651AD /* Supporting Files */ = { 120 | isa = PBXGroup; 121 | children = ( 122 | D889DF441B2A8133006651AD /* Info.plist */, 123 | ); 124 | name = "Supporting Files"; 125 | sourceTree = ""; 126 | }; 127 | /* End PBXGroup section */ 128 | 129 | /* Begin PBXNativeTarget section */ 130 | D889DF251B2A8133006651AD /* AVFlatSwitch */ = { 131 | isa = PBXNativeTarget; 132 | buildConfigurationList = D889DF491B2A8133006651AD /* Build configuration list for PBXNativeTarget "AVFlatSwitch" */; 133 | buildPhases = ( 134 | D889DF221B2A8133006651AD /* Sources */, 135 | D889DF231B2A8133006651AD /* Frameworks */, 136 | D889DF241B2A8133006651AD /* Resources */, 137 | ); 138 | buildRules = ( 139 | ); 140 | dependencies = ( 141 | ); 142 | name = AVFlatSwitch; 143 | productName = AVFlatSwitch; 144 | productReference = D889DF261B2A8133006651AD /* AVFlatSwitch.app */; 145 | productType = "com.apple.product-type.application"; 146 | }; 147 | D889DF3E1B2A8133006651AD /* AVFlatSwitchTests */ = { 148 | isa = PBXNativeTarget; 149 | buildConfigurationList = D889DF4C1B2A8133006651AD /* Build configuration list for PBXNativeTarget "AVFlatSwitchTests" */; 150 | buildPhases = ( 151 | D889DF3B1B2A8133006651AD /* Sources */, 152 | D889DF3C1B2A8133006651AD /* Frameworks */, 153 | D889DF3D1B2A8133006651AD /* Resources */, 154 | ); 155 | buildRules = ( 156 | ); 157 | dependencies = ( 158 | D889DF411B2A8133006651AD /* PBXTargetDependency */, 159 | ); 160 | name = AVFlatSwitchTests; 161 | productName = AVFlatSwitchTests; 162 | productReference = D889DF3F1B2A8133006651AD /* AVFlatSwitchTests.xctest */; 163 | productType = "com.apple.product-type.bundle.unit-test"; 164 | }; 165 | /* End PBXNativeTarget section */ 166 | 167 | /* Begin PBXProject section */ 168 | D889DF1E1B2A8133006651AD /* Project object */ = { 169 | isa = PBXProject; 170 | attributes = { 171 | LastUpgradeCheck = 0630; 172 | ORGANIZATIONNAME = zhidier; 173 | TargetAttributes = { 174 | D889DF251B2A8133006651AD = { 175 | CreatedOnToolsVersion = 6.3.2; 176 | }; 177 | D889DF3E1B2A8133006651AD = { 178 | CreatedOnToolsVersion = 6.3.2; 179 | TestTargetID = D889DF251B2A8133006651AD; 180 | }; 181 | }; 182 | }; 183 | buildConfigurationList = D889DF211B2A8133006651AD /* Build configuration list for PBXProject "AVFlatSwitch" */; 184 | compatibilityVersion = "Xcode 3.2"; 185 | developmentRegion = English; 186 | hasScannedForEncodings = 0; 187 | knownRegions = ( 188 | en, 189 | Base, 190 | ); 191 | mainGroup = D889DF1D1B2A8133006651AD; 192 | productRefGroup = D889DF271B2A8133006651AD /* Products */; 193 | projectDirPath = ""; 194 | projectRoot = ""; 195 | targets = ( 196 | D889DF251B2A8133006651AD /* AVFlatSwitch */, 197 | D889DF3E1B2A8133006651AD /* AVFlatSwitchTests */, 198 | ); 199 | }; 200 | /* End PBXProject section */ 201 | 202 | /* Begin PBXResourcesBuildPhase section */ 203 | D889DF241B2A8133006651AD /* Resources */ = { 204 | isa = PBXResourcesBuildPhase; 205 | buildActionMask = 2147483647; 206 | files = ( 207 | D889DF351B2A8133006651AD /* Main.storyboard in Resources */, 208 | D889DF3A1B2A8133006651AD /* LaunchScreen.xib in Resources */, 209 | D889DF371B2A8133006651AD /* Images.xcassets in Resources */, 210 | ); 211 | runOnlyForDeploymentPostprocessing = 0; 212 | }; 213 | D889DF3D1B2A8133006651AD /* Resources */ = { 214 | isa = PBXResourcesBuildPhase; 215 | buildActionMask = 2147483647; 216 | files = ( 217 | ); 218 | runOnlyForDeploymentPostprocessing = 0; 219 | }; 220 | /* End PBXResourcesBuildPhase section */ 221 | 222 | /* Begin PBXSourcesBuildPhase section */ 223 | D889DF221B2A8133006651AD /* Sources */ = { 224 | isa = PBXSourcesBuildPhase; 225 | buildActionMask = 2147483647; 226 | files = ( 227 | D889DF511B2A8182006651AD /* ZDFlatSwitch.m in Sources */, 228 | D889DF321B2A8133006651AD /* ViewController.m in Sources */, 229 | D889DF2F1B2A8133006651AD /* AppDelegate.m in Sources */, 230 | D889DF2C1B2A8133006651AD /* main.m in Sources */, 231 | ); 232 | runOnlyForDeploymentPostprocessing = 0; 233 | }; 234 | D889DF3B1B2A8133006651AD /* Sources */ = { 235 | isa = PBXSourcesBuildPhase; 236 | buildActionMask = 2147483647; 237 | files = ( 238 | D889DF461B2A8133006651AD /* AVFlatSwitchTests.m in Sources */, 239 | ); 240 | runOnlyForDeploymentPostprocessing = 0; 241 | }; 242 | /* End PBXSourcesBuildPhase section */ 243 | 244 | /* Begin PBXTargetDependency section */ 245 | D889DF411B2A8133006651AD /* PBXTargetDependency */ = { 246 | isa = PBXTargetDependency; 247 | target = D889DF251B2A8133006651AD /* AVFlatSwitch */; 248 | targetProxy = D889DF401B2A8133006651AD /* PBXContainerItemProxy */; 249 | }; 250 | /* End PBXTargetDependency section */ 251 | 252 | /* Begin PBXVariantGroup section */ 253 | D889DF331B2A8133006651AD /* Main.storyboard */ = { 254 | isa = PBXVariantGroup; 255 | children = ( 256 | D889DF341B2A8133006651AD /* Base */, 257 | ); 258 | name = Main.storyboard; 259 | sourceTree = ""; 260 | }; 261 | D889DF381B2A8133006651AD /* LaunchScreen.xib */ = { 262 | isa = PBXVariantGroup; 263 | children = ( 264 | D889DF391B2A8133006651AD /* Base */, 265 | ); 266 | name = LaunchScreen.xib; 267 | sourceTree = ""; 268 | }; 269 | /* End PBXVariantGroup section */ 270 | 271 | /* Begin XCBuildConfiguration section */ 272 | D889DF471B2A8133006651AD /* Debug */ = { 273 | isa = XCBuildConfiguration; 274 | buildSettings = { 275 | ALWAYS_SEARCH_USER_PATHS = NO; 276 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 277 | CLANG_CXX_LIBRARY = "libc++"; 278 | CLANG_ENABLE_MODULES = YES; 279 | CLANG_ENABLE_OBJC_ARC = YES; 280 | CLANG_WARN_BOOL_CONVERSION = YES; 281 | CLANG_WARN_CONSTANT_CONVERSION = YES; 282 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 283 | CLANG_WARN_EMPTY_BODY = YES; 284 | CLANG_WARN_ENUM_CONVERSION = YES; 285 | CLANG_WARN_INT_CONVERSION = YES; 286 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 287 | CLANG_WARN_UNREACHABLE_CODE = YES; 288 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 289 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 290 | COPY_PHASE_STRIP = NO; 291 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 292 | ENABLE_STRICT_OBJC_MSGSEND = YES; 293 | GCC_C_LANGUAGE_STANDARD = gnu99; 294 | GCC_DYNAMIC_NO_PIC = NO; 295 | GCC_NO_COMMON_BLOCKS = YES; 296 | GCC_OPTIMIZATION_LEVEL = 0; 297 | GCC_PREPROCESSOR_DEFINITIONS = ( 298 | "DEBUG=1", 299 | "$(inherited)", 300 | ); 301 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 302 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 303 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 304 | GCC_WARN_UNDECLARED_SELECTOR = YES; 305 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 306 | GCC_WARN_UNUSED_FUNCTION = YES; 307 | GCC_WARN_UNUSED_VARIABLE = YES; 308 | IPHONEOS_DEPLOYMENT_TARGET = 8.3; 309 | MTL_ENABLE_DEBUG_INFO = YES; 310 | ONLY_ACTIVE_ARCH = YES; 311 | SDKROOT = iphoneos; 312 | }; 313 | name = Debug; 314 | }; 315 | D889DF481B2A8133006651AD /* Release */ = { 316 | isa = XCBuildConfiguration; 317 | buildSettings = { 318 | ALWAYS_SEARCH_USER_PATHS = NO; 319 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 320 | CLANG_CXX_LIBRARY = "libc++"; 321 | CLANG_ENABLE_MODULES = YES; 322 | CLANG_ENABLE_OBJC_ARC = YES; 323 | CLANG_WARN_BOOL_CONVERSION = YES; 324 | CLANG_WARN_CONSTANT_CONVERSION = YES; 325 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 326 | CLANG_WARN_EMPTY_BODY = YES; 327 | CLANG_WARN_ENUM_CONVERSION = YES; 328 | CLANG_WARN_INT_CONVERSION = YES; 329 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 330 | CLANG_WARN_UNREACHABLE_CODE = YES; 331 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 332 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 333 | COPY_PHASE_STRIP = NO; 334 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 335 | ENABLE_NS_ASSERTIONS = NO; 336 | ENABLE_STRICT_OBJC_MSGSEND = YES; 337 | GCC_C_LANGUAGE_STANDARD = gnu99; 338 | GCC_NO_COMMON_BLOCKS = YES; 339 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 340 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 341 | GCC_WARN_UNDECLARED_SELECTOR = YES; 342 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 343 | GCC_WARN_UNUSED_FUNCTION = YES; 344 | GCC_WARN_UNUSED_VARIABLE = YES; 345 | IPHONEOS_DEPLOYMENT_TARGET = 8.3; 346 | MTL_ENABLE_DEBUG_INFO = NO; 347 | SDKROOT = iphoneos; 348 | VALIDATE_PRODUCT = YES; 349 | }; 350 | name = Release; 351 | }; 352 | D889DF4A1B2A8133006651AD /* Debug */ = { 353 | isa = XCBuildConfiguration; 354 | buildSettings = { 355 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 356 | INFOPLIST_FILE = AVFlatSwitch/Info.plist; 357 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 358 | PRODUCT_NAME = "$(TARGET_NAME)"; 359 | }; 360 | name = Debug; 361 | }; 362 | D889DF4B1B2A8133006651AD /* Release */ = { 363 | isa = XCBuildConfiguration; 364 | buildSettings = { 365 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 366 | INFOPLIST_FILE = AVFlatSwitch/Info.plist; 367 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 368 | PRODUCT_NAME = "$(TARGET_NAME)"; 369 | }; 370 | name = Release; 371 | }; 372 | D889DF4D1B2A8133006651AD /* Debug */ = { 373 | isa = XCBuildConfiguration; 374 | buildSettings = { 375 | BUNDLE_LOADER = "$(TEST_HOST)"; 376 | FRAMEWORK_SEARCH_PATHS = ( 377 | "$(SDKROOT)/Developer/Library/Frameworks", 378 | "$(inherited)", 379 | ); 380 | GCC_PREPROCESSOR_DEFINITIONS = ( 381 | "DEBUG=1", 382 | "$(inherited)", 383 | ); 384 | INFOPLIST_FILE = AVFlatSwitchTests/Info.plist; 385 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 386 | PRODUCT_NAME = "$(TARGET_NAME)"; 387 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/AVFlatSwitch.app/AVFlatSwitch"; 388 | }; 389 | name = Debug; 390 | }; 391 | D889DF4E1B2A8133006651AD /* Release */ = { 392 | isa = XCBuildConfiguration; 393 | buildSettings = { 394 | BUNDLE_LOADER = "$(TEST_HOST)"; 395 | FRAMEWORK_SEARCH_PATHS = ( 396 | "$(SDKROOT)/Developer/Library/Frameworks", 397 | "$(inherited)", 398 | ); 399 | INFOPLIST_FILE = AVFlatSwitchTests/Info.plist; 400 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 401 | PRODUCT_NAME = "$(TARGET_NAME)"; 402 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/AVFlatSwitch.app/AVFlatSwitch"; 403 | }; 404 | name = Release; 405 | }; 406 | /* End XCBuildConfiguration section */ 407 | 408 | /* Begin XCConfigurationList section */ 409 | D889DF211B2A8133006651AD /* Build configuration list for PBXProject "AVFlatSwitch" */ = { 410 | isa = XCConfigurationList; 411 | buildConfigurations = ( 412 | D889DF471B2A8133006651AD /* Debug */, 413 | D889DF481B2A8133006651AD /* Release */, 414 | ); 415 | defaultConfigurationIsVisible = 0; 416 | defaultConfigurationName = Release; 417 | }; 418 | D889DF491B2A8133006651AD /* Build configuration list for PBXNativeTarget "AVFlatSwitch" */ = { 419 | isa = XCConfigurationList; 420 | buildConfigurations = ( 421 | D889DF4A1B2A8133006651AD /* Debug */, 422 | D889DF4B1B2A8133006651AD /* Release */, 423 | ); 424 | defaultConfigurationIsVisible = 0; 425 | }; 426 | D889DF4C1B2A8133006651AD /* Build configuration list for PBXNativeTarget "AVFlatSwitchTests" */ = { 427 | isa = XCConfigurationList; 428 | buildConfigurations = ( 429 | D889DF4D1B2A8133006651AD /* Debug */, 430 | D889DF4E1B2A8133006651AD /* Release */, 431 | ); 432 | defaultConfigurationIsVisible = 0; 433 | }; 434 | /* End XCConfigurationList section */ 435 | }; 436 | rootObject = D889DF1E1B2A8133006651AD /* Project object */; 437 | } 438 | -------------------------------------------------------------------------------- /AVFlatSwitch.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /AVFlatSwitch/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // AVFlatSwitch 4 | // 5 | // Created by Alexcai on 15/6/12. 6 | // Copyright (c) 2015年 zhidier. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /AVFlatSwitch/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // AVFlatSwitch 4 | // 5 | // Created by Alexcai on 15/6/12. 6 | // Copyright (c) 2015年 zhidier. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /AVFlatSwitch/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /AVFlatSwitch/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /AVFlatSwitch/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /AVFlatSwitch/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.zhidier.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /AVFlatSwitch/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // AVFlatSwitch 4 | // 5 | // Created by Alexcai on 15/6/12. 6 | // Copyright (c) 2015年 zhidier. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /AVFlatSwitch/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // AVFlatSwitch 4 | // 5 | // Created by Alexcai on 15/6/12. 6 | // Copyright (c) 2015年 zhidier. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "ZDFlatSwitch.h" 11 | 12 | @interface ViewController () 13 | @property (weak, nonatomic) IBOutlet ZDFlatSwitch *flatSwitch; 14 | 15 | @end 16 | 17 | @implementation ViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | self.flatSwitch.lineWidth = 10; 22 | self.flatSwitch.strokeColor = [UIColor redColor]; 23 | self.flatSwitch.trailStrokeColor = [UIColor grayColor]; 24 | 25 | // Do any additional setup after loading the view, typically from a nib. 26 | } 27 | 28 | - (void)didReceiveMemoryWarning { 29 | [super didReceiveMemoryWarning]; 30 | // Dispose of any resources that can be recreated. 31 | } 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /AVFlatSwitch/ZDFlatSwitch.h: -------------------------------------------------------------------------------- 1 | // 2 | // ZDFlatSwitch.h 3 | // AVFlatSwitch 4 | // 5 | // Created by Alexcai on 15/6/12. 6 | // Copyright (c) 2015年 zhidier. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | static CGFloat finalStrokeEndForCheckmark = 0.85; 13 | static CGFloat finalStrokeStartForCheckmark = 0.3; 14 | static CGFloat checkmarkBounceAmount = 0.1; 15 | static CFTimeInterval animationDuration = 0.3; 16 | 17 | 18 | IB_DESIGNABLE 19 | @interface ZDFlatSwitch : UIControl 20 | 21 | /** 22 | * 线的宽度:默认为 23 | */ 24 | @property (nonatomic, assign)IBInspectable CGFloat lineWidth; 25 | @property (nonatomic, strong) IBInspectable UIColor *strokeColor; 26 | @property (nonatomic, strong) IBInspectable UIColor *trailStrokeColor; 27 | @property (nonatomic, assign) BOOL select; 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /AVFlatSwitch/ZDFlatSwitch.m: -------------------------------------------------------------------------------- 1 | // 2 | // ZDFlatSwitch.m 3 | // AVFlatSwitch 4 | // 5 | // Created by Alexcai on 15/6/12. 6 | // Copyright (c) 2015年 zhidier. All rights reserved. 7 | // 8 | 9 | #import "ZDFlatSwitch.h" 10 | 11 | 12 | @interface ZDFlatSwitch () 13 | 14 | @property (nonatomic, strong) CAShapeLayer *trailCircle; 15 | @property (nonatomic, strong) CAShapeLayer *circle; 16 | @property (nonatomic, strong) CAShapeLayer *checkmark; 17 | @property (nonatomic, assign) CGPoint checkmarkMidPoint; 18 | @property (nonatomic, assign) BOOL selected_internal; 19 | 20 | @end 21 | 22 | @implementation ZDFlatSwitch 23 | 24 | - (instancetype)initWithCoder:(NSCoder *)aDecoder{ 25 | if (self = [super initWithCoder:aDecoder]) { 26 | [self configure]; 27 | } 28 | return self; 29 | } 30 | 31 | - (instancetype)initWithFrame:(CGRect)frame{ 32 | if (self = [super initWithFrame:frame]) { 33 | [self configure]; 34 | } 35 | return self; 36 | } 37 | 38 | - (void)awakeFromNib{ 39 | [super awakeFromNib]; 40 | [self configure]; 41 | } 42 | -(instancetype)init{ 43 | self = [super init]; 44 | if (!self) { 45 | return nil; 46 | } 47 | 48 | [self configure]; 49 | 50 | return self; 51 | } 52 | 53 | - (void)layoutSublayersOfLayer:(CALayer *)layer{ 54 | [super layoutSublayersOfLayer:layer]; 55 | if (layer == self.layer) { 56 | CGPoint offset = CGPointZero; 57 | CGFloat radius = fmin(self.bounds.size.width, self.bounds.size.height) / 2; 58 | offset.x = (self.bounds.size.width - radius * 2) / 2.0; 59 | offset.y = (self.bounds.size.height - radius * 2) / 2.0; 60 | 61 | [CATransaction begin]; 62 | [CATransaction setDisableActions:YES]; 63 | CGRect ovalRect = CGRectMake(offset.x, offset.y, radius * 2, radius * 2); 64 | UIBezierPath *circlePath = [UIBezierPath bezierPathWithOvalInRect:ovalRect]; 65 | _trailCircle.path = circlePath.CGPath; 66 | 67 | _circle.transform = CATransform3DIdentity; 68 | _circle.frame = self.bounds; 69 | _circle.path = [UIBezierPath bezierPathWithOvalInRect:ovalRect].CGPath; 70 | _circle.transform = CATransform3DMakeRotation((212 * M_PI / 180), 0, 0, 1); 71 | CGPoint origin = CGPointMake(offset.x + radius, offset.y + radius); 72 | CGPoint checkStartPoint = CGPointZero; 73 | checkStartPoint.x = origin.x + radius * (cos(212 * M_PI / 180)); 74 | checkStartPoint.y = origin.y + radius * (sin(212 * M_PI / 180)); 75 | UIBezierPath *checkmarkPath = [UIBezierPath new]; 76 | [checkmarkPath moveToPoint:checkStartPoint]; 77 | self.checkmarkMidPoint = CGPointMake(offset.x + radius * 0.9, offset.y + radius * 1.4); 78 | [checkmarkPath addLineToPoint:self.checkmarkMidPoint]; 79 | CGPoint checkEndPoint = CGPointZero; 80 | checkEndPoint.x = origin.x + radius * (cos(320 * M_PI / 180)); 81 | checkEndPoint.y = origin.y + radius * (sin(320 * M_PI / 180)); 82 | 83 | [checkmarkPath addLineToPoint:checkEndPoint]; 84 | 85 | _checkmark.frame = self.bounds; 86 | _checkmark.path = checkmarkPath.CGPath; 87 | [CATransaction commit]; 88 | } 89 | 90 | } 91 | 92 | - (void)configure{ 93 | self.lineWidth = 4.0; 94 | self.strokeColor = [UIColor redColor]; 95 | self.trailStrokeColor = [UIColor greenColor]; 96 | 97 | self.backgroundColor = [UIColor clearColor]; 98 | [self configureShapeLayer:self.trailCircle]; 99 | self.trailCircle.strokeColor = self.trailStrokeColor.CGColor; 100 | 101 | [self configureShapeLayer:self.circle]; 102 | self.circle.strokeColor = self.strokeColor.CGColor; 103 | 104 | [self configureShapeLayer:self.checkmark]; 105 | self.checkmark.strokeColor = self.strokeColor.CGColor; 106 | [self setSelect:NO Animated:NO]; 107 | 108 | [self addTarget:self action:@selector(onTouchUpInside) forControlEvents:UIControlEventTouchUpInside]; 109 | 110 | } 111 | 112 | - (void)configureShapeLayer:( CAShapeLayer *)shapeLayer { 113 | shapeLayer.lineJoin = kCALineJoinRound; 114 | shapeLayer.lineCap = kCALineCapRound; 115 | shapeLayer.lineWidth = self.lineWidth; 116 | shapeLayer.fillColor = [UIColor clearColor].CGColor; 117 | [self.layer addSublayer:shapeLayer]; 118 | } 119 | 120 | - (void)onTouchUpInside{ 121 | self.select = !self.select; 122 | [self setSelect:self.select Animated:YES]; 123 | [self sendActionsForControlEvents:UIControlEventValueChanged]; 124 | } 125 | 126 | /* 127 | // Only override drawRect: if you perform custom drawing. 128 | // An empty implementation adversely affects performance during animation. 129 | - (void)drawRect:(CGRect)rect { 130 | // Drawing code 131 | } 132 | */ 133 | 134 | - (void)setSelect:(BOOL)select Animated:(BOOL)animation{ 135 | self.selected_internal = select; 136 | [_checkmark removeAllAnimations]; 137 | [_circle removeAllAnimations]; 138 | [_trailCircle removeAllAnimations]; 139 | 140 | [self resetValuesWithAnimation:animation]; 141 | 142 | if (animation) { 143 | [self addAnimationsForSelected:_selected_internal]; 144 | } 145 | } 146 | 147 | - (void)resetValuesWithAnimation:(BOOL)animation{ 148 | [CATransaction begin]; 149 | [CATransaction setDisableActions:YES]; 150 | if ((_selected_internal && animation) || (_selected_internal == NO && animation == NO) ) { 151 | _checkmark.strokeEnd = 0.0; 152 | _checkmark.strokeStart = 0.0; 153 | _trailCircle.opacity = 0.0; 154 | _circle.strokeStart = 0.0; 155 | _circle.strokeEnd = 1.0; 156 | } else { 157 | _checkmark.strokeEnd = finalStrokeEndForCheckmark; 158 | _checkmark.strokeStart = finalStrokeStartForCheckmark; 159 | _trailCircle.opacity = 1.0; 160 | _circle.strokeStart = 0.0; 161 | _circle.strokeEnd = 0.0; 162 | } 163 | [CATransaction commit]; 164 | } 165 | 166 | - (void)addAnimationsForSelected:(BOOL)selection{ 167 | CGFloat circleAnimationDuration = animationDuration * 0.5; 168 | CGFloat checkmarkEndDuration = animationDuration * 0.8; 169 | CGFloat checkmarkStartDuration = checkmarkEndDuration - circleAnimationDuration; 170 | CGFloat checkmarkBounceDuration = animationDuration - checkmarkEndDuration; 171 | 172 | CAAnimationGroup *checkmarkAnimationGroup = [CAAnimationGroup new]; 173 | checkmarkAnimationGroup.removedOnCompletion = NO; 174 | checkmarkAnimationGroup.fillMode = kCAFillModeForwards; 175 | checkmarkAnimationGroup.duration = animationDuration; 176 | checkmarkAnimationGroup.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; 177 | //CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear) 178 | 179 | CAKeyframeAnimation *checkmarkStrokeEnd = [CAKeyframeAnimation new]; 180 | checkmarkStrokeEnd.keyPath = @"strokeEnd"; 181 | checkmarkStrokeEnd.duration = checkmarkEndDuration + checkmarkBounceDuration; 182 | checkmarkStrokeEnd.removedOnCompletion = NO; 183 | checkmarkStrokeEnd.fillMode = kCAFillModeForwards; 184 | checkmarkStrokeEnd.calculationMode = kCAAnimationPaced; 185 | 186 | if (selection) { 187 | checkmarkStrokeEnd.values = @[@(0.0), @((finalStrokeEndForCheckmark + checkmarkBounceAmount)), @((finalStrokeEndForCheckmark))]; 188 | checkmarkStrokeEnd.keyTimes = @[@(0.0), @(checkmarkEndDuration),@(checkmarkEndDuration + checkmarkBounceDuration)]; 189 | 190 | } else { 191 | checkmarkStrokeEnd.values = @[@(finalStrokeEndForCheckmark), @(finalStrokeEndForCheckmark + checkmarkBounceAmount), @(-0.1)]; 192 | checkmarkStrokeEnd.keyTimes = @[@(0.0), @(checkmarkBounceDuration), @(checkmarkEndDuration + checkmarkBounceDuration)]; 193 | } 194 | 195 | CAKeyframeAnimation *checkmarkStrokeStart = [CAKeyframeAnimation new]; //(keyPath: "strokeStart") 196 | checkmarkStrokeStart.keyPath = @"strokeStart"; 197 | checkmarkStrokeStart.duration = checkmarkStartDuration + checkmarkBounceDuration; 198 | checkmarkStrokeStart.removedOnCompletion = NO; 199 | checkmarkStrokeStart.fillMode = kCAFillModeForwards; 200 | checkmarkStrokeStart.calculationMode = kCAAnimationPaced; 201 | 202 | if (selection) { 203 | checkmarkStrokeStart.values = @[@(0.0), @(finalStrokeStartForCheckmark + checkmarkBounceAmount), @(finalStrokeStartForCheckmark)]; 204 | checkmarkStrokeStart.keyTimes = @[@(0.0), @(checkmarkStartDuration), @(checkmarkStartDuration + checkmarkBounceDuration)]; 205 | } else { 206 | checkmarkStrokeStart.values = @[@(finalStrokeStartForCheckmark), @(finalStrokeStartForCheckmark + checkmarkBounceAmount), @(0.0)]; 207 | checkmarkStrokeStart.keyTimes = @[@(0.0), @(checkmarkBounceDuration), @(checkmarkStartDuration + checkmarkBounceDuration)]; 208 | } 209 | 210 | if (selection) { 211 | checkmarkStrokeStart.beginTime = circleAnimationDuration; 212 | } 213 | 214 | checkmarkAnimationGroup.animations = @[checkmarkStrokeEnd, checkmarkStrokeStart]; 215 | [_checkmark addAnimation:checkmarkAnimationGroup forKey:@"checkmarkAnimation"]; 216 | 217 | CAAnimationGroup *circleAnimationGroup = [CAAnimationGroup new]; 218 | circleAnimationGroup.duration = animationDuration; 219 | circleAnimationGroup.removedOnCompletion = NO; 220 | circleAnimationGroup.fillMode = kCAFillModeForwards; 221 | circleAnimationGroup.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; 222 | 223 | CABasicAnimation *circleStrokeEnd = [CABasicAnimation new]; 224 | circleStrokeEnd.keyPath = @"strokeEnd"; 225 | circleStrokeEnd.duration = circleAnimationDuration; 226 | if (selection) { 227 | circleStrokeEnd.beginTime = 0.0; 228 | 229 | circleStrokeEnd.fromValue = @(1.0); 230 | circleStrokeEnd.toValue = @(-0.1); 231 | } else { 232 | circleStrokeEnd.beginTime = animationDuration - circleAnimationDuration; 233 | 234 | circleStrokeEnd.fromValue = @(0.0); 235 | circleStrokeEnd.toValue = @(1.0); 236 | } 237 | circleStrokeEnd.removedOnCompletion = NO; 238 | circleStrokeEnd.fillMode = kCAFillModeForwards; 239 | 240 | circleAnimationGroup.animations = @[circleStrokeEnd]; 241 | [self.circle addAnimation:circleAnimationGroup forKey:@"circleStrokeEnd"]; 242 | 243 | CABasicAnimation *trailCircleColor = [CABasicAnimation new]; //CABasicAnimation(keyPath: "opacity") 244 | trailCircleColor.keyPath = @"opacity"; 245 | trailCircleColor.duration = animationDuration; 246 | if (selection) { 247 | trailCircleColor.fromValue = @(0.0); 248 | trailCircleColor.toValue = @(1.0); 249 | } else { 250 | trailCircleColor.fromValue = @(1.0); 251 | trailCircleColor.toValue = @(0.0); 252 | } 253 | trailCircleColor.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; 254 | 255 | trailCircleColor.fillMode = kCAFillModeForwards; 256 | trailCircleColor.removedOnCompletion = NO; 257 | [_trailCircle addAnimation:trailCircleColor forKey:@"trailCircleColor"]; 258 | } 259 | 260 | 261 | - (void)setLineWidth:(CGFloat)lineWidth{ 262 | _lineWidth = lineWidth; 263 | self.circle.lineWidth = lineWidth; 264 | self.checkmark.lineWidth = lineWidth; 265 | self.trailCircle.lineWidth = lineWidth; 266 | } 267 | 268 | - (void)setStrokeColor:(UIColor *)strokeColor{ 269 | _strokeColor = strokeColor; 270 | self.circle.strokeColor = strokeColor.CGColor; 271 | self.checkmark.strokeColor = strokeColor.CGColor; 272 | } 273 | 274 | - (void)setTrailStrokeColor:(UIColor *)trailStrokeColor{ 275 | _trailStrokeColor = trailStrokeColor; 276 | self.trailCircle.strokeColor = trailStrokeColor.CGColor; 277 | } 278 | 279 | - (void)setSelect:(BOOL)select{ 280 | super.selected = select; 281 | _select = select; 282 | } 283 | - (BOOL)selected{ 284 | return _selected_internal; 285 | } 286 | 287 | - (CAShapeLayer *)trailCircle{ 288 | if (_trailCircle == nil) { 289 | _trailCircle = [CAShapeLayer new]; 290 | } 291 | return _trailCircle; 292 | } 293 | - (CAShapeLayer *)circle{ 294 | if (_circle == nil) { 295 | _circle = [CAShapeLayer new]; 296 | } 297 | return _circle; 298 | } 299 | - (CAShapeLayer *)checkmark{ 300 | if (_checkmark == nil) { 301 | _checkmark = [CAShapeLayer new]; 302 | } 303 | return _checkmark; 304 | } 305 | 306 | 307 | @end 308 | -------------------------------------------------------------------------------- /AVFlatSwitch/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // AVFlatSwitch 4 | // 5 | // Created by Alexcai on 15/6/12. 6 | // Copyright (c) 2015年 zhidier. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AVFlatSwitchTests/AVFlatSwitchTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // AVFlatSwitchTests.m 3 | // AVFlatSwitchTests 4 | // 5 | // Created by Alexcai on 15/6/12. 6 | // Copyright (c) 2015年 zhidier. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface AVFlatSwitchTests : XCTestCase 13 | 14 | @end 15 | 16 | @implementation AVFlatSwitchTests 17 | 18 | - (void)setUp { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown { 24 | // Put teardown code here. This method is called after the invocation of each test method in the class. 25 | [super tearDown]; 26 | } 27 | 28 | - (void)testExample { 29 | // This is an example of a functional test case. 30 | XCTAssert(YES, @"Pass"); 31 | } 32 | 33 | - (void)testPerformanceExample { 34 | // This is an example of a performance test case. 35 | [self measureBlock:^{ 36 | // Put the code you want to measure the time of here. 37 | }]; 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /AVFlatSwitchTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.zhidier.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 leiocai 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ZDFlatSwitch 2 | 3 | 根据Swift(AIFlatSwitch)版本修改的一个OC实现. 4 | 创意设计来源自Dribble 5 | 6 |

7 |






8 | 9 | ##系统平台 10 | - iOS 7.1+ 11 | - Xcode 6.1 12 | 13 | ## 集成步骤 14 | 15 | > **手动安装** 16 | > 17 | > 拖动`ZDFlatSwitch.h` 和 `ZDFlatSwitch.m` 文件到你的项目中即可. 18 | > 19 | 20 | ## 使用方法: 21 | 22 | ### 创建ZDFlatSwitch 对象 23 | 24 | - 25 | 26 | ```objc 27 | // 创建对象 28 | ZDFlatSwitch *flatSwitch = [ZDFlatSwitch new] 29 | // 设置frame 30 | flatSwitch.frame =CGRectMake(0, 0, 50, 50); 31 | ``` 32 | 33 | ### 方法 34 | 35 | > 改变颜色属性 36 | 37 | ```objc 38 | 39 | // 设置线宽 40 | flatSwitch.lineWidth = 10; 41 | // 设置√的颜色 42 | flatSwitch.strokeColor = [UIColor whiteColor]; 43 | // 设置圆环的颜色 44 | flatSwitch.trailStrokeColor = [UIColor greenColor]; 45 | 46 | ``` 47 | - [x] IBInspectable 特性供在Storyboard使用. 48 | 49 | 50 | ## License 51 | 52 | ZDFlatSwitch is released under the MIT license. See LICENSE for details. 53 | -------------------------------------------------------------------------------- /ZDFlatSwitch/ZDFlatSwitch.h: -------------------------------------------------------------------------------- 1 | // 2 | // ZDFlatSwitch.h 3 | // AVFlatSwitch 4 | // 5 | // Created by Alexcai on 15/6/12. 6 | // Copyright (c) 2015年 zhidier. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | static CGFloat finalStrokeEndForCheckmark = 0.85; 13 | static CGFloat finalStrokeStartForCheckmark = 0.3; 14 | static CGFloat checkmarkBounceAmount = 0.1; 15 | static CFTimeInterval animationDuration = 0.3; 16 | 17 | 18 | IB_DESIGNABLE 19 | @interface ZDFlatSwitch : UIControl 20 | 21 | /** 22 | * 线的宽度:默认为 23 | */ 24 | @property (nonatomic, assign)IBInspectable CGFloat lineWidth; 25 | /** 26 | * 设置符号颜色 27 | */ 28 | @property (nonatomic, strong) IBInspectable UIColor *strokeColor; 29 | /** 30 | * 设置外环颜色 31 | */ 32 | @property (nonatomic, strong) IBInspectable UIColor *trailStrokeColor; 33 | @property (nonatomic, assign) BOOL select; 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /ZDFlatSwitch/ZDFlatSwitch.m: -------------------------------------------------------------------------------- 1 | // 2 | // ZDFlatSwitch.m 3 | // AVFlatSwitch 4 | // 5 | // Created by Alexcai on 15/6/12. 6 | // Copyright (c) 2015年 zhidier. All rights reserved. 7 | // 8 | 9 | #import "ZDFlatSwitch.h" 10 | 11 | 12 | @interface ZDFlatSwitch () 13 | 14 | @property (nonatomic, strong) CAShapeLayer *trailCircle; 15 | @property (nonatomic, strong) CAShapeLayer *circle; 16 | @property (nonatomic, strong) CAShapeLayer *checkmark; 17 | @property (nonatomic, assign) CGPoint checkmarkMidPoint; 18 | @property (nonatomic, assign) BOOL selected_internal; 19 | 20 | @end 21 | 22 | @implementation ZDFlatSwitch 23 | 24 | - (instancetype)initWithCoder:(NSCoder *)aDecoder{ 25 | if (self = [super initWithCoder:aDecoder]) { 26 | [self configure]; 27 | } 28 | return self; 29 | } 30 | 31 | - (instancetype)initWithFrame:(CGRect)frame{ 32 | if (self = [super initWithFrame:frame]) { 33 | [self configure]; 34 | } 35 | return self; 36 | } 37 | 38 | - (void)awakeFromNib{ 39 | [super awakeFromNib]; 40 | [self configure]; 41 | } 42 | -(instancetype)init{ 43 | self = [super init]; 44 | if (!self) { 45 | return nil; 46 | } 47 | 48 | [self configure]; 49 | 50 | return self; 51 | } 52 | 53 | - (void)layoutSublayersOfLayer:(CALayer *)layer{ 54 | [super layoutSublayersOfLayer:layer]; 55 | if (layer == self.layer) { 56 | CGPoint offset = CGPointZero; 57 | CGFloat radius = fmin(self.bounds.size.width, self.bounds.size.height) / 2; 58 | offset.x = (self.bounds.size.width - radius * 2) / 2.0; 59 | offset.y = (self.bounds.size.height - radius * 2) / 2.0; 60 | 61 | [CATransaction begin]; 62 | [CATransaction setDisableActions:YES]; 63 | CGRect ovalRect = CGRectMake(offset.x, offset.y, radius * 2, radius * 2); 64 | UIBezierPath *circlePath = [UIBezierPath bezierPathWithOvalInRect:ovalRect]; 65 | _trailCircle.path = circlePath.CGPath; 66 | 67 | _circle.transform = CATransform3DIdentity; 68 | _circle.frame = self.bounds; 69 | _circle.path = [UIBezierPath bezierPathWithOvalInRect:ovalRect].CGPath; 70 | _circle.transform = CATransform3DMakeRotation((212 * M_PI / 180), 0, 0, 1); 71 | CGPoint origin = CGPointMake(offset.x + radius, offset.y + radius); 72 | CGPoint checkStartPoint = CGPointZero; 73 | checkStartPoint.x = origin.x + radius * (cos(212 * M_PI / 180)); 74 | checkStartPoint.y = origin.y + radius * (sin(212 * M_PI / 180)); 75 | UIBezierPath *checkmarkPath = [UIBezierPath new]; 76 | [checkmarkPath moveToPoint:checkStartPoint]; 77 | self.checkmarkMidPoint = CGPointMake(offset.x + radius * 0.9, offset.y + radius * 1.4); 78 | [checkmarkPath addLineToPoint:self.checkmarkMidPoint]; 79 | CGPoint checkEndPoint = CGPointZero; 80 | checkEndPoint.x = origin.x + radius * (cos(320 * M_PI / 180)); 81 | checkEndPoint.y = origin.y + radius * (sin(320 * M_PI / 180)); 82 | 83 | [checkmarkPath addLineToPoint:checkEndPoint]; 84 | 85 | _checkmark.frame = self.bounds; 86 | _checkmark.path = checkmarkPath.CGPath; 87 | [CATransaction commit]; 88 | } 89 | 90 | } 91 | 92 | - (void)configure{ 93 | self.lineWidth = 4.0; 94 | self.strokeColor = [UIColor redColor]; 95 | self.trailStrokeColor = [UIColor greenColor]; 96 | 97 | self.backgroundColor = [UIColor clearColor]; 98 | [self configureShapeLayer:self.trailCircle]; 99 | self.trailCircle.strokeColor = self.trailStrokeColor.CGColor; 100 | 101 | [self configureShapeLayer:self.circle]; 102 | self.circle.strokeColor = self.strokeColor.CGColor; 103 | 104 | [self configureShapeLayer:self.checkmark]; 105 | self.checkmark.strokeColor = self.strokeColor.CGColor; 106 | [self setSelect:NO Animated:NO]; 107 | 108 | [self addTarget:self action:@selector(onTouchUpInside) forControlEvents:UIControlEventTouchUpInside]; 109 | 110 | } 111 | 112 | - (void)configureShapeLayer:( CAShapeLayer *)shapeLayer { 113 | shapeLayer.lineJoin = kCALineJoinRound; 114 | shapeLayer.lineCap = kCALineCapRound; 115 | shapeLayer.lineWidth = self.lineWidth; 116 | shapeLayer.fillColor = [UIColor clearColor].CGColor; 117 | [self.layer addSublayer:shapeLayer]; 118 | } 119 | 120 | - (void)onTouchUpInside{ 121 | self.select = !self.select; 122 | [self setSelect:self.select Animated:YES]; 123 | [self sendActionsForControlEvents:UIControlEventValueChanged]; 124 | } 125 | 126 | /* 127 | // Only override drawRect: if you perform custom drawing. 128 | // An empty implementation adversely affects performance during animation. 129 | - (void)drawRect:(CGRect)rect { 130 | // Drawing code 131 | } 132 | */ 133 | 134 | - (void)setSelect:(BOOL)select Animated:(BOOL)animation{ 135 | self.selected_internal = select; 136 | [_checkmark removeAllAnimations]; 137 | [_circle removeAllAnimations]; 138 | [_trailCircle removeAllAnimations]; 139 | 140 | [self resetValuesWithAnimation:animation]; 141 | 142 | if (animation) { 143 | [self addAnimationsForSelected:_selected_internal]; 144 | } 145 | } 146 | 147 | - (void)resetValuesWithAnimation:(BOOL)animation{ 148 | [CATransaction begin]; 149 | [CATransaction setDisableActions:YES]; 150 | if ((_selected_internal && animation) || (_selected_internal == NO && animation == NO) ) { 151 | _checkmark.strokeEnd = 0.0; 152 | _checkmark.strokeStart = 0.0; 153 | _trailCircle.opacity = 0.0; 154 | _circle.strokeStart = 0.0; 155 | _circle.strokeEnd = 1.0; 156 | } else { 157 | _checkmark.strokeEnd = finalStrokeEndForCheckmark; 158 | _checkmark.strokeStart = finalStrokeStartForCheckmark; 159 | _trailCircle.opacity = 1.0; 160 | _circle.strokeStart = 0.0; 161 | _circle.strokeEnd = 0.0; 162 | } 163 | [CATransaction commit]; 164 | } 165 | 166 | - (void)addAnimationsForSelected:(BOOL)selection{ 167 | CGFloat circleAnimationDuration = animationDuration * 0.5; 168 | CGFloat checkmarkEndDuration = animationDuration * 0.8; 169 | CGFloat checkmarkStartDuration = checkmarkEndDuration - circleAnimationDuration; 170 | CGFloat checkmarkBounceDuration = animationDuration - checkmarkEndDuration; 171 | 172 | CAAnimationGroup *checkmarkAnimationGroup = [CAAnimationGroup new]; 173 | checkmarkAnimationGroup.removedOnCompletion = NO; 174 | checkmarkAnimationGroup.fillMode = kCAFillModeForwards; 175 | checkmarkAnimationGroup.duration = animationDuration; 176 | checkmarkAnimationGroup.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; 177 | //CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear) 178 | 179 | CAKeyframeAnimation *checkmarkStrokeEnd = [CAKeyframeAnimation new]; 180 | checkmarkStrokeEnd.keyPath = @"strokeEnd"; 181 | checkmarkStrokeEnd.duration = checkmarkEndDuration + checkmarkBounceDuration; 182 | checkmarkStrokeEnd.removedOnCompletion = NO; 183 | checkmarkStrokeEnd.fillMode = kCAFillModeForwards; 184 | checkmarkStrokeEnd.calculationMode = kCAAnimationPaced; 185 | 186 | if (selection) { 187 | checkmarkStrokeEnd.values = @[@(0.0), @((finalStrokeEndForCheckmark + checkmarkBounceAmount)), @((finalStrokeEndForCheckmark))]; 188 | checkmarkStrokeEnd.keyTimes = @[@(0.0), @(checkmarkEndDuration),@(checkmarkEndDuration + checkmarkBounceDuration)]; 189 | 190 | } else { 191 | checkmarkStrokeEnd.values = @[@(finalStrokeEndForCheckmark), @(finalStrokeEndForCheckmark + checkmarkBounceAmount), @(-0.1)]; 192 | checkmarkStrokeEnd.keyTimes = @[@(0.0), @(checkmarkBounceDuration), @(checkmarkEndDuration + checkmarkBounceDuration)]; 193 | } 194 | 195 | CAKeyframeAnimation *checkmarkStrokeStart = [CAKeyframeAnimation new]; //(keyPath: "strokeStart") 196 | checkmarkStrokeStart.keyPath = @"strokeStart"; 197 | checkmarkStrokeStart.duration = checkmarkStartDuration + checkmarkBounceDuration; 198 | checkmarkStrokeStart.removedOnCompletion = NO; 199 | checkmarkStrokeStart.fillMode = kCAFillModeForwards; 200 | checkmarkStrokeStart.calculationMode = kCAAnimationPaced; 201 | 202 | if (selection) { 203 | checkmarkStrokeStart.values = @[@(0.0), @(finalStrokeStartForCheckmark + checkmarkBounceAmount), @(finalStrokeStartForCheckmark)]; 204 | checkmarkStrokeStart.keyTimes = @[@(0.0), @(checkmarkStartDuration), @(checkmarkStartDuration + checkmarkBounceDuration)]; 205 | } else { 206 | checkmarkStrokeStart.values = @[@(finalStrokeStartForCheckmark), @(finalStrokeStartForCheckmark + checkmarkBounceAmount), @(0.0)]; 207 | checkmarkStrokeStart.keyTimes = @[@(0.0), @(checkmarkBounceDuration), @(checkmarkStartDuration + checkmarkBounceDuration)]; 208 | } 209 | 210 | if (selection) { 211 | checkmarkStrokeStart.beginTime = circleAnimationDuration; 212 | } 213 | 214 | checkmarkAnimationGroup.animations = @[checkmarkStrokeEnd, checkmarkStrokeStart]; 215 | [_checkmark addAnimation:checkmarkAnimationGroup forKey:@"checkmarkAnimation"]; 216 | 217 | CAAnimationGroup *circleAnimationGroup = [CAAnimationGroup new]; 218 | circleAnimationGroup.duration = animationDuration; 219 | circleAnimationGroup.removedOnCompletion = NO; 220 | circleAnimationGroup.fillMode = kCAFillModeForwards; 221 | circleAnimationGroup.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; 222 | 223 | CABasicAnimation *circleStrokeEnd = [CABasicAnimation new]; 224 | circleStrokeEnd.keyPath = @"strokeEnd"; 225 | circleStrokeEnd.duration = circleAnimationDuration; 226 | if (selection) { 227 | circleStrokeEnd.beginTime = 0.0; 228 | 229 | circleStrokeEnd.fromValue = @(1.0); 230 | circleStrokeEnd.toValue = @(-0.1); 231 | } else { 232 | circleStrokeEnd.beginTime = animationDuration - circleAnimationDuration; 233 | 234 | circleStrokeEnd.fromValue = @(0.0); 235 | circleStrokeEnd.toValue = @(1.0); 236 | } 237 | circleStrokeEnd.removedOnCompletion = NO; 238 | circleStrokeEnd.fillMode = kCAFillModeForwards; 239 | 240 | circleAnimationGroup.animations = @[circleStrokeEnd]; 241 | [self.circle addAnimation:circleAnimationGroup forKey:@"circleStrokeEnd"]; 242 | 243 | CABasicAnimation *trailCircleColor = [CABasicAnimation new]; //CABasicAnimation(keyPath: "opacity") 244 | trailCircleColor.keyPath = @"opacity"; 245 | trailCircleColor.duration = animationDuration; 246 | if (selection) { 247 | trailCircleColor.fromValue = @(0.0); 248 | trailCircleColor.toValue = @(1.0); 249 | } else { 250 | trailCircleColor.fromValue = @(1.0); 251 | trailCircleColor.toValue = @(0.0); 252 | } 253 | trailCircleColor.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; 254 | 255 | trailCircleColor.fillMode = kCAFillModeForwards; 256 | trailCircleColor.removedOnCompletion = NO; 257 | [_trailCircle addAnimation:trailCircleColor forKey:@"trailCircleColor"]; 258 | } 259 | 260 | 261 | - (void)setLineWidth:(CGFloat)lineWidth{ 262 | _lineWidth = lineWidth; 263 | self.circle.lineWidth = lineWidth; 264 | self.checkmark.lineWidth = lineWidth; 265 | self.trailCircle.lineWidth = lineWidth; 266 | } 267 | 268 | - (void)setStrokeColor:(UIColor *)strokeColor{ 269 | _strokeColor = strokeColor; 270 | self.circle.strokeColor = strokeColor.CGColor; 271 | self.checkmark.strokeColor = strokeColor.CGColor; 272 | } 273 | 274 | - (void)setTrailStrokeColor:(UIColor *)trailStrokeColor{ 275 | _trailStrokeColor = trailStrokeColor; 276 | self.trailCircle.strokeColor = trailStrokeColor.CGColor; 277 | } 278 | 279 | - (void)setSelect:(BOOL)select{ 280 | super.selected = select; 281 | _select = select; 282 | } 283 | - (BOOL)selected{ 284 | return _selected_internal; 285 | } 286 | 287 | - (CAShapeLayer *)trailCircle{ 288 | if (_trailCircle == nil) { 289 | _trailCircle = [CAShapeLayer new]; 290 | } 291 | return _trailCircle; 292 | } 293 | - (CAShapeLayer *)circle{ 294 | if (_circle == nil) { 295 | _circle = [CAShapeLayer new]; 296 | } 297 | return _circle; 298 | } 299 | - (CAShapeLayer *)checkmark{ 300 | if (_checkmark == nil) { 301 | _checkmark = [CAShapeLayer new]; 302 | } 303 | return _checkmark; 304 | } 305 | 306 | 307 | @end 308 | --------------------------------------------------------------------------------