├── .gitignore ├── GIF ├── circleIrregularTransform.gif ├── oneLoadingAnimation.gif ├── originLoadingAnimation.gif ├── step1.gif ├── step2.gif ├── step3.gif ├── step4.gif ├── step5.gif ├── step6Fail.gif ├── step6Success.gif └── step7Fail.gif ├── OC ├── CircleIrregularTransform │ ├── CircleIrregularTransform.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ └── CircleIrregularTransform │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ │ ├── Info.plist │ │ ├── Src │ │ └── CircleIrregularTransform │ │ │ ├── CircleIrregularTransformLayer.h │ │ │ └── CircleIrregularTransformLayer.m │ │ ├── ViewController.h │ │ ├── ViewController.m │ │ └── main.m ├── OneLoadingAnimationComplete │ ├── OneLoadingAnimationComplete.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ └── OneLoadingAnimationComplete │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ │ ├── Info.plist │ │ ├── Src │ │ └── OneLoadingAnimation │ │ │ ├── ArcToCircleLayer.h │ │ │ ├── ArcToCircleLayer.m │ │ │ ├── OneLoadingAnimationView.h │ │ │ └── OneLoadingAnimationView.m │ │ ├── ViewController.h │ │ ├── ViewController.m │ │ └── main.m ├── OneLoadingAnimationStep1 │ ├── OneLoadingAnimationStep1.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ └── OneLoadingAnimationStep1 │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ │ ├── Info.plist │ │ ├── Src │ │ └── OneLoadingAnimation │ │ │ ├── ArcToCircleLayer.h │ │ │ ├── ArcToCircleLayer.m │ │ │ ├── OneLoadingAnimationView.h │ │ │ └── OneLoadingAnimationView.m │ │ ├── ViewController.h │ │ ├── ViewController.m │ │ └── main.m ├── OneLoadingAnimationStep1Another │ ├── OneLoadingAnimationStep1Another.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ └── OneLoadingAnimationStep1Another │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ │ ├── Info.plist │ │ ├── Src │ │ └── OneLoadingAnimation │ │ │ ├── ArcToCircleLayer.h │ │ │ ├── ArcToCircleLayer.m │ │ │ ├── OneLoadingAnimationView.h │ │ │ └── OneLoadingAnimationView.m │ │ ├── ViewController.h │ │ ├── ViewController.m │ │ └── main.m ├── OneLoadingAnimationStep2 │ ├── OneLoadingAnimationStep2.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ └── OneLoadingAnimationStep2 │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ │ ├── Info.plist │ │ ├── Src │ │ └── OneLoadingAnimation │ │ │ ├── ArcToCircleLayer.h │ │ │ ├── ArcToCircleLayer.m │ │ │ ├── OneLoadingAnimationView.h │ │ │ └── OneLoadingAnimationView.m │ │ ├── ViewController.h │ │ ├── ViewController.m │ │ └── main.m ├── OneLoadingAnimationStep3 │ ├── OneLoadingAnimationStep3.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ └── OneLoadingAnimationStep3 │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ │ ├── Info.plist │ │ ├── Src │ │ └── OneLoadingAnimation │ │ │ ├── ArcToCircleLayer.h │ │ │ ├── ArcToCircleLayer.m │ │ │ ├── OneLoadingAnimationView.h │ │ │ └── OneLoadingAnimationView.m │ │ ├── ViewController.h │ │ ├── ViewController.m │ │ └── main.m ├── OneLoadingAnimationStep4 │ ├── OneLoadingAnimationStep4.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ └── OneLoadingAnimationStep4 │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ │ ├── Info.plist │ │ ├── Src │ │ └── OneLoadingAnimation │ │ │ ├── ArcToCircleLayer.h │ │ │ ├── ArcToCircleLayer.m │ │ │ ├── OneLoadingAnimationView.h │ │ │ └── OneLoadingAnimationView.m │ │ ├── ViewController.h │ │ ├── ViewController.m │ │ └── main.m └── OneLoadingAnimationStep5 │ ├── OneLoadingAnimationStep5.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── OneLoadingAnimationStep5 │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ ├── Src │ └── OneLoadingAnimation │ │ ├── ArcToCircleLayer.h │ │ ├── ArcToCircleLayer.m │ │ ├── OneLoadingAnimationView.h │ │ └── OneLoadingAnimationView.m │ ├── ViewController.h │ ├── ViewController.m │ └── main.m ├── README.md └── Swift ├── CircleIrregularTransformSwift ├── CircleIrregularTransformSwift.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata └── CircleIrregularTransformSwift │ ├── AppDelegate.swift │ ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ ├── Source │ └── CircleIrregularTransform │ │ └── CircleIrregularTransformLayer.swift │ └── ViewController.swift └── OneLoadingAnimationCompleteSwift ├── OneLoadingAnimationCompleteSwift.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata └── OneLoadingAnimationCompleteSwift ├── AppDelegate.swift ├── Assets.xcassets └── AppIcon.appiconset │ └── Contents.json ├── Base.lproj ├── LaunchScreen.storyboard └── Main.storyboard ├── Info.plist ├── Src └── OneLoadingAnimation │ ├── ArcToCircleLayer.swift │ └── OneLoadingAnimationView.swift └── ViewController.swift /.gitignore: -------------------------------------------------------------------------------- 1 | Skip to content 2 | This repository 3 | Search 4 | Pull requests 5 | Issues 6 | Gist 7 | @iamim2 8 | Unwatch 1,374 9 | Unstar 30,404 10 | Fork 11,398 github/gitignore 11 | Code Pull requests 155 Pulse Graphs 12 | Branch: master Find file Copy pathgitignore/Swift.gitignore 13 | 611c239 9 days ago 14 | @natestedman natestedman Add Swift Package Manager to Swift.gitignore 15 | 7 contributors @KrauseFx @martinblech @natestedman @nrbrook @nwest @modocache @bbodenmiller 16 | RawBlameHistory 60 lines (49 sloc) 1.29 KB 17 | # Xcode 18 | # 19 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 20 | 21 | ## Build generated 22 | build/ 23 | DerivedData 24 | 25 | ## Various settings 26 | *.pbxuser 27 | !default.pbxuser 28 | *.mode1v3 29 | !default.mode1v3 30 | *.mode2v3 31 | !default.mode2v3 32 | *.perspectivev3 33 | !default.perspectivev3 34 | xcuserdata 35 | 36 | ## Other 37 | *.xccheckout 38 | *.moved-aside 39 | *.xcuserstate 40 | *.xcscmblueprint 41 | 42 | ## Obj-C/Swift specific 43 | *.hmap 44 | *.ipa 45 | 46 | # Swift Package Manager 47 | # 48 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 49 | # Packages/ 50 | .build/ 51 | 52 | # CocoaPods 53 | # 54 | # We recommend against adding the Pods directory to your .gitignore. However 55 | # you should judge for yourself, the pros and cons are mentioned at: 56 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 57 | # 58 | # Pods/ 59 | 60 | # Carthage 61 | # 62 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 63 | # Carthage/Checkouts 64 | 65 | Carthage/Build 66 | 67 | # fastlane 68 | # 69 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 70 | # screenshots whenever they are needed. 71 | # For more information about the recommended setup visit: 72 | # https://github.com/fastlane/fastlane/blob/master/docs/Gitignore.md 73 | 74 | fastlane/report.xml 75 | fastlane/screenshots 76 | Status API Training Shop Blog About Pricing 77 | © 2015 GitHub, Inc. Terms Privacy Security Contact Help -------------------------------------------------------------------------------- /GIF/circleIrregularTransform.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellochenms/OneLoadingAnimation/f82117a8152288c1fbf991f5fbc7f5b75c1ae65b/GIF/circleIrregularTransform.gif -------------------------------------------------------------------------------- /GIF/oneLoadingAnimation.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellochenms/OneLoadingAnimation/f82117a8152288c1fbf991f5fbc7f5b75c1ae65b/GIF/oneLoadingAnimation.gif -------------------------------------------------------------------------------- /GIF/originLoadingAnimation.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellochenms/OneLoadingAnimation/f82117a8152288c1fbf991f5fbc7f5b75c1ae65b/GIF/originLoadingAnimation.gif -------------------------------------------------------------------------------- /GIF/step1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellochenms/OneLoadingAnimation/f82117a8152288c1fbf991f5fbc7f5b75c1ae65b/GIF/step1.gif -------------------------------------------------------------------------------- /GIF/step2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellochenms/OneLoadingAnimation/f82117a8152288c1fbf991f5fbc7f5b75c1ae65b/GIF/step2.gif -------------------------------------------------------------------------------- /GIF/step3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellochenms/OneLoadingAnimation/f82117a8152288c1fbf991f5fbc7f5b75c1ae65b/GIF/step3.gif -------------------------------------------------------------------------------- /GIF/step4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellochenms/OneLoadingAnimation/f82117a8152288c1fbf991f5fbc7f5b75c1ae65b/GIF/step4.gif -------------------------------------------------------------------------------- /GIF/step5.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellochenms/OneLoadingAnimation/f82117a8152288c1fbf991f5fbc7f5b75c1ae65b/GIF/step5.gif -------------------------------------------------------------------------------- /GIF/step6Fail.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellochenms/OneLoadingAnimation/f82117a8152288c1fbf991f5fbc7f5b75c1ae65b/GIF/step6Fail.gif -------------------------------------------------------------------------------- /GIF/step6Success.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellochenms/OneLoadingAnimation/f82117a8152288c1fbf991f5fbc7f5b75c1ae65b/GIF/step6Success.gif -------------------------------------------------------------------------------- /GIF/step7Fail.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellochenms/OneLoadingAnimation/f82117a8152288c1fbf991f5fbc7f5b75c1ae65b/GIF/step7Fail.gif -------------------------------------------------------------------------------- /OC/CircleIrregularTransform/CircleIrregularTransform.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /OC/CircleIrregularTransform/CircleIrregularTransform/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // CircleIrregularTransform 4 | // 5 | // Created by thatsoul on 15/12/13. 6 | // Copyright © 2015年 chenms.m2. 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 | -------------------------------------------------------------------------------- /OC/CircleIrregularTransform/CircleIrregularTransform/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // CircleIrregularTransform 4 | // 5 | // Created by thatsoul on 15/12/13. 6 | // Copyright © 2015年 chenms.m2. 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 | -------------------------------------------------------------------------------- /OC/CircleIrregularTransform/CircleIrregularTransform/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /OC/CircleIrregularTransform/CircleIrregularTransform/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /OC/CircleIrregularTransform/CircleIrregularTransform/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /OC/CircleIrregularTransform/CircleIrregularTransform/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /OC/CircleIrregularTransform/CircleIrregularTransform/Src/CircleIrregularTransform/CircleIrregularTransformLayer.h: -------------------------------------------------------------------------------- 1 | // 2 | // CircleIrregularTransformLayer.h 3 | // CircleIrregularTransform 4 | // 5 | // Created by thatsoul on 15/12/6. 6 | // Copyright © 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CircleIrregularTransformLayer : CALayer 12 | @property (nonatomic) CGFloat progress; 13 | @end 14 | -------------------------------------------------------------------------------- /OC/CircleIrregularTransform/CircleIrregularTransform/Src/CircleIrregularTransform/CircleIrregularTransformLayer.m: -------------------------------------------------------------------------------- 1 | // 2 | // CircleIrregularTransformLayer.m 3 | // CircleIrregularTransform 4 | // 5 | // Created by thatsoul on 15/12/6. 6 | // Copyright © 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import "CircleIrregularTransformLayer.h" 10 | #import 11 | 12 | static CGFloat const kLineWidth = 6; 13 | static CGFloat const kXScale = 1.2; 14 | static CGFloat const kYScale = 0.8; 15 | static CGFloat const kControlPointFactor = 1.8; 16 | static CGFloat const kRadius = 80; 17 | static CGFloat const pointRadius = 3; 18 | 19 | @implementation CircleIrregularTransformLayer 20 | 21 | @dynamic progress; 22 | 23 | + (BOOL)needsDisplayForKey:(NSString *)key { 24 | if ([key isEqualToString:@"progress"]) { 25 | return YES; 26 | } 27 | 28 | return [super needsDisplayForKey:key]; 29 | } 30 | 31 | - (void)drawInContext:(CGContextRef)ctx { 32 | UIBezierPath *path = [UIBezierPath bezierPath]; 33 | 34 | // 以底点为原点 35 | CGPoint bottom = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds) + kRadius); 36 | // 控制点偏移距离 37 | CGFloat controlOffsetDistance = kRadius / kControlPointFactor; 38 | 39 | // 各点变化系数 40 | CGFloat xFactor = 1 + (kXScale - 1) * self.progress; 41 | CGFloat yFactor = 1 - (1 - kYScale) * self.progress; 42 | // 顶点特殊的变化系数(破坏规则变形) 43 | CGFloat topYFactor = 1 - (1 - kYScale) * self.progress * 1.5; 44 | 45 | // 右上弧 46 | CGPoint origin0 = CGPointMake(bottom.x + kRadius * xFactor, bottom.y - kRadius * yFactor); 47 | CGPoint dest0 = CGPointMake(bottom.x, bottom.y - kRadius * 2 * topYFactor); 48 | CGPoint control0A = CGPointMake(origin0.x, origin0.y - controlOffsetDistance); 49 | CGPoint control0B = CGPointMake(dest0.x + controlOffsetDistance, bottom.y - kRadius * 2 * yFactor); 50 | [path moveToPoint:origin0]; 51 | [path addCurveToPoint:dest0 controlPoint1:control0A controlPoint2:control0B]; 52 | 53 | // 左上弧 54 | CGPoint origin1 = dest0; 55 | CGPoint dest1 = CGPointMake(bottom.x - kRadius * xFactor, bottom.y - kRadius * yFactor); 56 | CGPoint control1A = CGPointMake(origin1.x - controlOffsetDistance, bottom.y - kRadius * 2 * yFactor); 57 | CGPoint control1B = CGPointMake(dest1.x, dest1.y - controlOffsetDistance); 58 | [path addCurveToPoint:dest1 controlPoint1:control1A controlPoint2:control1B]; 59 | 60 | // 左下弧 61 | CGPoint origin2 = dest1; 62 | CGPoint dest2 = bottom; 63 | CGPoint control2A = CGPointMake(origin2.x, origin2.y + controlOffsetDistance); 64 | CGPoint control2B = CGPointMake(dest2.x - controlOffsetDistance, dest2.y); 65 | [path addCurveToPoint:dest2 controlPoint1:control2A controlPoint2:control2B]; 66 | 67 | // 右下弧 68 | CGPoint origin3 = dest2; 69 | CGPoint dest3 = origin0; 70 | CGPoint control3A = CGPointMake(origin3.x + controlOffsetDistance, origin3.y); 71 | CGPoint control3B = CGPointMake(dest3.x, dest3.y + controlOffsetDistance); 72 | [path addCurveToPoint:dest3 controlPoint1:control3A controlPoint2:control3B]; 73 | 74 | CGContextAddPath(ctx, path.CGPath); 75 | 76 | CGContextSetLineWidth(ctx, kLineWidth); 77 | CGContextSetStrokeColorWithColor(ctx, [UIColor blueColor].CGColor); 78 | CGContextStrokePath(ctx); 79 | 80 | // 辅助点 81 | UIBezierPath *pointsPath = [UIBezierPath bezierPath]; 82 | [self addArcForPath:pointsPath atPoint:origin0]; 83 | [self addArcForPath:pointsPath atPoint:control0A]; 84 | [self addArcForPath:pointsPath atPoint:control0B]; 85 | [self addArcForPath:pointsPath atPoint:dest0]; 86 | 87 | [self addArcForPath:pointsPath atPoint:origin1]; 88 | [self addArcForPath:pointsPath atPoint:control1A]; 89 | [self addArcForPath:pointsPath atPoint:control1B]; 90 | [self addArcForPath:pointsPath atPoint:dest1]; 91 | 92 | [self addArcForPath:pointsPath atPoint:origin2]; 93 | [self addArcForPath:pointsPath atPoint:control2A]; 94 | [self addArcForPath:pointsPath atPoint:control2B]; 95 | [self addArcForPath:pointsPath atPoint:dest2]; 96 | 97 | [self addArcForPath:pointsPath atPoint:origin3]; 98 | [self addArcForPath:pointsPath atPoint:control3A]; 99 | [self addArcForPath:pointsPath atPoint:control3B]; 100 | [self addArcForPath:pointsPath atPoint:dest3]; 101 | 102 | CGContextAddPath(ctx, pointsPath.CGPath); 103 | 104 | CGContextSetFillColorWithColor(ctx, [UIColor redColor].CGColor); 105 | CGContextFillPath(ctx); 106 | 107 | // 辅助线 108 | UIBezierPath *linePath = [UIBezierPath bezierPath]; 109 | 110 | [linePath moveToPoint:origin0]; 111 | [linePath addLineToPoint:control0A]; 112 | [linePath addLineToPoint:control0B]; 113 | [linePath addLineToPoint:dest0]; 114 | 115 | [linePath addLineToPoint:origin1]; 116 | [linePath addLineToPoint:control1A]; 117 | [linePath addLineToPoint:control1B]; 118 | [linePath addLineToPoint:dest1]; 119 | 120 | [linePath addLineToPoint:origin2]; 121 | [linePath addLineToPoint:control2A]; 122 | [linePath addLineToPoint:control2B]; 123 | [linePath addLineToPoint:dest2]; 124 | 125 | [linePath addLineToPoint:origin3]; 126 | [linePath addLineToPoint:control3A]; 127 | [linePath addLineToPoint:control3B]; 128 | [linePath addLineToPoint:dest3]; 129 | 130 | CGContextAddPath(ctx, linePath.CGPath); 131 | 132 | CGContextSetLineWidth(ctx, 2); 133 | CGContextSetStrokeColorWithColor(ctx, [UIColor redColor].CGColor); 134 | CGContextStrokePath(ctx); 135 | } 136 | 137 | #pragma mark - tools 138 | - (void)addArcForPath:(UIBezierPath *)path atPoint:(CGPoint)point { 139 | [path moveToPoint:point]; 140 | [path addArcWithCenter:point radius:pointRadius startAngle:0 endAngle:M_PI * 2 clockwise:YES]; 141 | } 142 | 143 | @end 144 | -------------------------------------------------------------------------------- /OC/CircleIrregularTransform/CircleIrregularTransform/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // CircleIrregularTransform 4 | // 5 | // Created by thatsoul on 15/12/13. 6 | // Copyright © 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /OC/CircleIrregularTransform/CircleIrregularTransform/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // CircleIrregularTransform 4 | // 5 | // Created by thatsoul on 15/12/13. 6 | // Copyright © 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "CircleIrregularTransformLayer.h" 11 | 12 | @interface ViewController () 13 | @property (weak, nonatomic) IBOutlet UIView *animationView; 14 | @property (nonatomic) CircleIrregularTransformLayer *animationLayer; 15 | @end 16 | 17 | @implementation ViewController 18 | 19 | #pragma mark - life cycle 20 | - (void)viewDidLoad { 21 | [super viewDidLoad]; 22 | // Do any additional setup after loading the view, typically from a nib. 23 | 24 | [self addAnimationLayer]; 25 | } 26 | 27 | - (void)addAnimationLayer { 28 | self.animationLayer = [CircleIrregularTransformLayer layer]; 29 | self.animationLayer.contentsScale = [UIScreen mainScreen].scale; 30 | self.animationLayer.frame = self.animationView.bounds; 31 | self.animationLayer.progress = 0; 32 | [self.animationView.layer addSublayer:self.animationLayer]; 33 | } 34 | 35 | 36 | #pragma mark - user event 37 | - (IBAction)onTapStartAnimation:(id)sender { 38 | // reset 39 | [self.animationLayer removeAllAnimations]; 40 | 41 | // end status 42 | self.animationLayer.progress = 1; 43 | 44 | // animation 45 | CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"progress"]; 46 | animation.duration = 2; 47 | animation.fromValue = @(0.0); 48 | animation.toValue = @(1.0); 49 | [self.animationLayer addAnimation:animation forKey:nil]; 50 | } 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /OC/CircleIrregularTransform/CircleIrregularTransform/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // CircleIrregularTransform 4 | // 5 | // Created by thatsoul on 15/12/13. 6 | // Copyright © 2015年 chenms.m2. 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 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationComplete/OneLoadingAnimationComplete.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationComplete/OneLoadingAnimationComplete/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // OneLoadingAnimationComplete 4 | // 5 | // Created by thatsoul on 15/12/13. 6 | // Copyright © 2015年 chenms.m2. 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 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationComplete/OneLoadingAnimationComplete/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // OneLoadingAnimationComplete 4 | // 5 | // Created by thatsoul on 15/12/13. 6 | // Copyright © 2015年 chenms.m2. 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 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationComplete/OneLoadingAnimationComplete/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /OC/OneLoadingAnimationComplete/OneLoadingAnimationComplete/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationComplete/OneLoadingAnimationComplete/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 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationComplete/OneLoadingAnimationComplete/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationComplete/OneLoadingAnimationComplete/Src/OneLoadingAnimation/ArcToCircleLayer.h: -------------------------------------------------------------------------------- 1 | // 2 | // OneLoadingAnimation.h 3 | // OneLoadingAnimationStep1 4 | // 5 | // Created by thatsoul on 15/11/15. 6 | // Copyright (c) 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface ArcToCircleLayer : CALayer 13 | @property (nonatomic) CGFloat progress; 14 | @property (nonatomic) UIColor *color; 15 | @property (nonatomic) CGFloat lineWidth; 16 | @end 17 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationComplete/OneLoadingAnimationComplete/Src/OneLoadingAnimation/ArcToCircleLayer.m: -------------------------------------------------------------------------------- 1 | // 2 | // OneLoadingAnimation.h 3 | // OneLoadingAnimationStep1 4 | // 5 | // Created by thatsoul on 15/11/15. 6 | // Copyright (c) 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import "ArcToCircleLayer.h" 10 | 11 | @implementation ArcToCircleLayer 12 | 13 | @dynamic progress; 14 | @dynamic color; 15 | @dynamic lineWidth; 16 | 17 | + (BOOL)needsDisplayForKey:(NSString *)key { 18 | if ([key isEqualToString:@"progress"]) { 19 | return YES; 20 | } else if ([key isEqualToString:@"color"]) { 21 | return YES; 22 | } else if ([key isEqualToString:@"lineWidth"]) { 23 | return YES; 24 | } 25 | 26 | return [super needsDisplayForKey:key]; 27 | } 28 | 29 | - (void)drawInContext:(CGContextRef)ctx { 30 | UIBezierPath *path = [UIBezierPath bezierPath]; 31 | 32 | CGFloat radius = MIN(CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds)) / 2 - self.lineWidth / 2; 33 | CGPoint center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds)); 34 | 35 | // O 36 | CGFloat originStart = M_PI * 7 / 2; 37 | CGFloat originEnd = M_PI * 2; 38 | CGFloat currentOrigin = originStart - (originStart - originEnd) * self.progress; 39 | 40 | // D 41 | CGFloat destStart = M_PI * 3; 42 | CGFloat destEnd = 0; 43 | CGFloat currentDest = destStart - (destStart - destEnd) * self.progress; 44 | 45 | [path addArcWithCenter:center radius:radius startAngle: currentOrigin endAngle:currentDest clockwise:NO]; 46 | CGContextAddPath(ctx, path.CGPath); 47 | CGContextSetLineWidth(ctx, self.lineWidth); 48 | CGContextSetStrokeColorWithColor(ctx, self.color.CGColor); 49 | CGContextStrokePath(ctx); 50 | } 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationComplete/OneLoadingAnimationComplete/Src/OneLoadingAnimation/OneLoadingAnimationView.h: -------------------------------------------------------------------------------- 1 | // 2 | // OneLoadingAnimation.h 3 | // OneLoadingAnimationStep1 4 | // 5 | // Created by thatsoul on 15/11/15. 6 | // Copyright © 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OneLoadingAnimationView : UIView 12 | - (void)startSuccess; 13 | - (void)startFail; 14 | @end 15 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationComplete/OneLoadingAnimationComplete/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // OneLoadingAnimationStep3 4 | // 5 | // Created by thatsoul on 15/11/29. 6 | // Copyright © 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationComplete/OneLoadingAnimationComplete/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // OneLoadingAnimationStep3 4 | // 5 | // Created by thatsoul on 15/11/29. 6 | // Copyright © 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "OneLoadingAnimationView.h" 11 | 12 | @interface ViewController () 13 | @property (weak, nonatomic) IBOutlet OneLoadingAnimationView *animationView; 14 | 15 | @end 16 | 17 | @implementation ViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | // Do any additional setup after loading the view, typically from a nib. 22 | self.view.backgroundColor = [UIColor colorWithRed:0xf0/255.0 green:0xf4/255.0 blue:0xf5/255.0 alpha:1.0]; 23 | } 24 | 25 | - (void)didReceiveMemoryWarning { 26 | [super didReceiveMemoryWarning]; 27 | // Dispose of any resources that can be recreated. 28 | } 29 | 30 | #pragma mark - user event 31 | - (IBAction)onTapSuccessAnimation:(id)sender { 32 | [self.animationView startSuccess]; 33 | } 34 | 35 | - (IBAction)onTapFailAnimation:(id)sender { 36 | [self.animationView startFail]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationComplete/OneLoadingAnimationComplete/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // OneLoadingAnimationComplete 4 | // 5 | // Created by thatsoul on 15/12/13. 6 | // Copyright © 2015年 chenms.m2. 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 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep1/OneLoadingAnimationStep1.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep1/OneLoadingAnimationStep1/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // OneLoadingAnimationStep1 4 | // 5 | // Created by thatsoul on 15/11/15. 6 | // Copyright © 2015年 chenms.m2. 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 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep1/OneLoadingAnimationStep1/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // OneLoadingAnimationStep1 4 | // 5 | // Created by thatsoul on 15/11/15. 6 | // Copyright © 2015年 chenms.m2. 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 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep1/OneLoadingAnimationStep1/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep1/OneLoadingAnimationStep1/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep1/OneLoadingAnimationStep1/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep1/OneLoadingAnimationStep1/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep1/OneLoadingAnimationStep1/Src/OneLoadingAnimation/ArcToCircleLayer.h: -------------------------------------------------------------------------------- 1 | // 2 | // OneLoadingAnimation.h 3 | // OneLoadingAnimationStep1 4 | // 5 | // Created by thatsoul on 15/11/15. 6 | // Copyright (c) 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface ArcToCircleLayer : CALayer 13 | @property (nonatomic) CGFloat progress; 14 | @end 15 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep1/OneLoadingAnimationStep1/Src/OneLoadingAnimation/ArcToCircleLayer.m: -------------------------------------------------------------------------------- 1 | // 2 | // OneLoadingAnimation.h 3 | // OneLoadingAnimationStep1 4 | // 5 | // Created by thatsoul on 15/11/15. 6 | // Copyright (c) 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import "ArcToCircleLayer.h" 10 | 11 | static CGFloat const kLineWidth = 6; 12 | 13 | @implementation ArcToCircleLayer 14 | 15 | @dynamic progress; 16 | 17 | + (BOOL)needsDisplayForKey:(NSString *)key { 18 | if ([key isEqualToString:@"progress"]) { 19 | return YES; 20 | } 21 | 22 | return [super needsDisplayForKey:key]; 23 | } 24 | 25 | - (void)drawInContext:(CGContextRef)ctx { 26 | UIBezierPath *path = [UIBezierPath bezierPath]; 27 | 28 | CGFloat radius = MIN(CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds)) / 2 - kLineWidth / 2; 29 | CGPoint center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds)); 30 | 31 | // O 32 | CGFloat originStart = M_PI * 7 / 2; 33 | CGFloat originEnd = M_PI * 2; 34 | CGFloat currentOrigin = originStart - (originStart - originEnd) * self.progress; 35 | 36 | // D 37 | CGFloat destStart = M_PI * 3; 38 | CGFloat destEnd = 0; 39 | CGFloat currentDest = destStart - (destStart - destEnd) * self.progress; 40 | 41 | [path addArcWithCenter:center radius:radius startAngle: currentOrigin endAngle:currentDest clockwise:NO]; 42 | CGContextAddPath(ctx, path.CGPath); 43 | CGContextSetLineWidth(ctx, kLineWidth); 44 | CGContextSetStrokeColorWithColor(ctx, [UIColor blueColor].CGColor); 45 | CGContextStrokePath(ctx); 46 | } 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep1/OneLoadingAnimationStep1/Src/OneLoadingAnimation/OneLoadingAnimationView.h: -------------------------------------------------------------------------------- 1 | // 2 | // OneLoadingAnimation.h 3 | // OneLoadingAnimationStep1 4 | // 5 | // Created by thatsoul on 15/11/15. 6 | // Copyright © 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OneLoadingAnimationView : UIView 12 | - (void)startAnimation; 13 | @end 14 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep1/OneLoadingAnimationStep1/Src/OneLoadingAnimation/OneLoadingAnimationView.m: -------------------------------------------------------------------------------- 1 | // 2 | // OneLoadingAnimation.m 3 | // OneLoadingAnimationStep1 4 | // 5 | // Created by thatsoul on 15/11/15. 6 | // Copyright © 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import "OneLoadingAnimationView.h" 10 | #import "ArcToCircleLayer.h" 11 | 12 | static CGFloat const kRadius = 40; 13 | static CGFloat const kLineWidth = 6; 14 | static CGFloat const kStep1Duration = 5.0; 15 | 16 | @interface OneLoadingAnimationView () 17 | @property (nonatomic) ArcToCircleLayer *arcToCircleLayer; 18 | @end 19 | 20 | @implementation OneLoadingAnimationView 21 | 22 | - (void)awakeFromNib { 23 | [super awakeFromNib]; 24 | } 25 | 26 | #pragma mark - public 27 | - (void)startAnimation { 28 | [self reset]; 29 | [self doStep1]; 30 | } 31 | 32 | #pragma mark - animation 33 | - (void)reset { 34 | [self.arcToCircleLayer removeFromSuperlayer]; 35 | } 36 | 37 | - (void)doStep1 { 38 | self.arcToCircleLayer = [ArcToCircleLayer layer]; 39 | self.arcToCircleLayer.contentsScale = [UIScreen mainScreen].scale; 40 | [self.layer addSublayer:self.arcToCircleLayer]; 41 | 42 | self.arcToCircleLayer.bounds = CGRectMake(0, 0, kRadius * 2 + kLineWidth, kRadius * 2 + kLineWidth); 43 | self.arcToCircleLayer.position = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds)); 44 | 45 | // animation 46 | self.arcToCircleLayer.progress = 1; // end status 47 | 48 | CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"progress"]; 49 | animation.duration = kStep1Duration; 50 | animation.fromValue = @0.0; 51 | animation.toValue = @1.0; 52 | [self.arcToCircleLayer addAnimation:animation forKey:nil]; 53 | } 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep1/OneLoadingAnimationStep1/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // OneLoadingAnimationStep1 4 | // 5 | // Created by thatsoul on 15/11/15. 6 | // Copyright © 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep1/OneLoadingAnimationStep1/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // OneLoadingAnimationStep1 4 | // 5 | // Created by thatsoul on 15/11/15. 6 | // Copyright © 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "OneLoadingAnimationView.h" 11 | 12 | @interface ViewController () 13 | @property (weak, nonatomic) IBOutlet OneLoadingAnimationView *animationView; 14 | @end 15 | 16 | @implementation ViewController 17 | 18 | - (void)viewDidLoad { 19 | [super viewDidLoad]; 20 | // Do any additional setup after loading the view, typically from a nib. 21 | } 22 | 23 | - (void)didReceiveMemoryWarning { 24 | [super didReceiveMemoryWarning]; 25 | // Dispose of any resources that can be recreated. 26 | } 27 | 28 | #pragma mark - user event 29 | - (IBAction)onTapStartAnimation:(id)sender { 30 | [self.animationView startAnimation]; 31 | } 32 | 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep1/OneLoadingAnimationStep1/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // OneLoadingAnimationStep1 4 | // 5 | // Created by thatsoul on 15/11/15. 6 | // Copyright © 2015年 chenms.m2. 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 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep1Another/OneLoadingAnimationStep1Another.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep1Another/OneLoadingAnimationStep1Another/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // OneLoadingAnimationStep1Another 4 | // 5 | // Created by thatsoul on 15/12/13. 6 | // Copyright © 2015年 chenms.m2. 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 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep1Another/OneLoadingAnimationStep1Another/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // OneLoadingAnimationStep1Another 4 | // 5 | // Created by thatsoul on 15/12/13. 6 | // Copyright © 2015年 chenms.m2. 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 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep1Another/OneLoadingAnimationStep1Another/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep1Another/OneLoadingAnimationStep1Another/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep1Another/OneLoadingAnimationStep1Another/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep1Another/OneLoadingAnimationStep1Another/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep1Another/OneLoadingAnimationStep1Another/Src/OneLoadingAnimation/ArcToCircleLayer.h: -------------------------------------------------------------------------------- 1 | // 2 | // OneLoadingAnimation.h 3 | // OneLoadingAnimationStep1 4 | // 5 | // Created by thatsoul on 15/11/15. 6 | // Copyright (c) 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface ArcToCircleLayer : CALayer 13 | @property (nonatomic) CGFloat progress; 14 | @end 15 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep1Another/OneLoadingAnimationStep1Another/Src/OneLoadingAnimation/ArcToCircleLayer.m: -------------------------------------------------------------------------------- 1 | // 2 | // OneLoadingAnimation.h 3 | // OneLoadingAnimationStep1 4 | // 5 | // Created by thatsoul on 15/11/15. 6 | // Copyright (c) 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import "ArcToCircleLayer.h" 10 | 11 | static CGFloat const kLineWidth = 6; 12 | 13 | @implementation ArcToCircleLayer 14 | 15 | @dynamic progress; 16 | 17 | + (BOOL)needsDisplayForKey:(NSString *)key { 18 | if ([key isEqualToString:@"progress"]) { 19 | return YES; 20 | } 21 | 22 | return [super needsDisplayForKey:key]; 23 | } 24 | 25 | - (void)drawInContext:(CGContextRef)ctx { 26 | UIBezierPath *path = [UIBezierPath bezierPath]; 27 | 28 | CGFloat radius = MIN(CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds)) / 2 - kLineWidth / 2; 29 | CGPoint center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds)); 30 | 31 | // O 32 | CGFloat originStart = M_PI * 7 / 2; 33 | CGFloat originEnd = M_PI * 2; 34 | CGFloat currentOrigin = originStart - (originStart - originEnd) * self.progress; 35 | 36 | // D 37 | CGFloat destStart = M_PI * 3; 38 | CGFloat destEnd = 0; 39 | CGFloat currentDest = destStart - (destStart - destEnd) * self.progress; 40 | 41 | [path addArcWithCenter:center radius:radius startAngle: currentOrigin endAngle:currentDest clockwise:NO]; 42 | CGContextAddPath(ctx, path.CGPath); 43 | CGContextSetLineWidth(ctx, kLineWidth); 44 | CGContextSetStrokeColorWithColor(ctx, [UIColor blueColor].CGColor); 45 | CGContextStrokePath(ctx); 46 | } 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep1Another/OneLoadingAnimationStep1Another/Src/OneLoadingAnimation/OneLoadingAnimationView.h: -------------------------------------------------------------------------------- 1 | // 2 | // OneLoadingAnimation.h 3 | // OneLoadingAnimationStep1 4 | // 5 | // Created by thatsoul on 15/11/15. 6 | // Copyright © 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OneLoadingAnimationView : UIView 12 | - (void)startAnimation; 13 | @end 14 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep1Another/OneLoadingAnimationStep1Another/Src/OneLoadingAnimation/OneLoadingAnimationView.m: -------------------------------------------------------------------------------- 1 | // 2 | // OneLoadingAnimation.m 3 | // OneLoadingAnimationStep1 4 | // 5 | // Created by thatsoul on 15/11/15. 6 | // Copyright © 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import "OneLoadingAnimationView.h" 10 | #import "ArcToCircleLayer.h" 11 | 12 | static CGFloat const kRadius = 40; 13 | static CGFloat const kLineWidth = 6; 14 | static CGFloat const kStep1Duration = 2; 15 | 16 | @interface OneLoadingAnimationView () 17 | @property (nonatomic) CAShapeLayer *arcToCircleLayer; 18 | @end 19 | 20 | @implementation OneLoadingAnimationView 21 | 22 | - (void)awakeFromNib { 23 | [super awakeFromNib]; 24 | } 25 | 26 | #pragma mark - public 27 | - (void)startAnimation { 28 | [self reset]; 29 | [self doStep1]; 30 | } 31 | 32 | #pragma mark - animation 33 | - (void)reset { 34 | [self.arcToCircleLayer removeFromSuperlayer]; 35 | } 36 | 37 | - (void)doStep1 { 38 | self.arcToCircleLayer = [CAShapeLayer layer]; 39 | self.arcToCircleLayer.bounds = CGRectMake(0, 0, kRadius * 2 + kLineWidth, kRadius * 2 + kLineWidth); 40 | self.arcToCircleLayer.position = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds)); 41 | 42 | UIBezierPath *path = [UIBezierPath bezierPath]; 43 | CGPoint point = CGPointMake(CGRectGetMidX(self.arcToCircleLayer.bounds), CGRectGetMidY(self.arcToCircleLayer.bounds)); 44 | [path addArcWithCenter:point radius:kRadius startAngle:0 endAngle:M_PI * 2 clockwise:NO]; 45 | self.arcToCircleLayer.path = path.CGPath; 46 | self.arcToCircleLayer.lineWidth = kLineWidth; 47 | self.arcToCircleLayer.strokeColor = [UIColor blueColor].CGColor; 48 | self.arcToCircleLayer.fillColor = nil; 49 | 50 | [self.layer addSublayer:self.arcToCircleLayer]; 51 | 52 | // end status 53 | // SS(strokeStart) 54 | CGFloat SSFrom = 0.25; 55 | CGFloat SSTo = 0; 56 | 57 | // SE(strokeEnd) 58 | CGFloat SEFrom = 0.5; 59 | CGFloat SETo = 1.0; 60 | 61 | // transform status 62 | self.arcToCircleLayer.transform = CATransform3DIdentity; 63 | 64 | // animation 65 | CABasicAnimation *ssAnima = [CABasicAnimation animationWithKeyPath:@"strokeStart"]; 66 | ssAnima.fromValue = @(SSFrom); 67 | ssAnima.toValue = @(SSTo); 68 | 69 | CABasicAnimation *seAnima = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; 70 | seAnima.fromValue = @(SEFrom); 71 | seAnima.toValue = @(SETo); 72 | 73 | CABasicAnimation *rotateAnima = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; 74 | rotateAnima.fromValue = @0; 75 | rotateAnima.toValue = @(-M_PI * 2); 76 | 77 | CAAnimationGroup *animation = [CAAnimationGroup animation]; 78 | animation.animations = @[ssAnima, seAnima, rotateAnima]; 79 | animation.duration = kStep1Duration; 80 | [self.arcToCircleLayer addAnimation:animation forKey:nil]; 81 | } 82 | 83 | @end 84 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep1Another/OneLoadingAnimationStep1Another/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // OneLoadingAnimationStep1 4 | // 5 | // Created by thatsoul on 15/11/15. 6 | // Copyright © 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep1Another/OneLoadingAnimationStep1Another/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // OneLoadingAnimationStep1 4 | // 5 | // Created by thatsoul on 15/11/15. 6 | // Copyright © 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "OneLoadingAnimationView.h" 11 | 12 | @interface ViewController () 13 | @property (weak, nonatomic) IBOutlet OneLoadingAnimationView *animationView; 14 | @end 15 | 16 | @implementation ViewController 17 | 18 | - (void)viewDidLoad { 19 | [super viewDidLoad]; 20 | // Do any additional setup after loading the view, typically from a nib. 21 | } 22 | 23 | - (void)didReceiveMemoryWarning { 24 | [super didReceiveMemoryWarning]; 25 | // Dispose of any resources that can be recreated. 26 | } 27 | 28 | #pragma mark - user event 29 | - (IBAction)onTapStartAnimation:(id)sender { 30 | [self.animationView startAnimation]; 31 | } 32 | 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep1Another/OneLoadingAnimationStep1Another/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // OneLoadingAnimationStep1Another 4 | // 5 | // Created by thatsoul on 15/12/13. 6 | // Copyright © 2015年 chenms.m2. 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 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep2/OneLoadingAnimationStep2.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep2/OneLoadingAnimationStep2/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // OneLoadingAnimationStep2 4 | // 5 | // Created by thatsoul on 15/11/21. 6 | // Copyright © 2015年 chenms.m2. 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 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep2/OneLoadingAnimationStep2/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // OneLoadingAnimationStep2 4 | // 5 | // Created by thatsoul on 15/11/21. 6 | // Copyright © 2015年 chenms.m2. 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 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep2/OneLoadingAnimationStep2/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep2/OneLoadingAnimationStep2/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep2/OneLoadingAnimationStep2/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 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep2/OneLoadingAnimationStep2/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep2/OneLoadingAnimationStep2/Src/OneLoadingAnimation/ArcToCircleLayer.h: -------------------------------------------------------------------------------- 1 | // 2 | // OneLoadingAnimation.h 3 | // OneLoadingAnimationStep1 4 | // 5 | // Created by thatsoul on 15/11/15. 6 | // Copyright (c) 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface ArcToCircleLayer : CALayer 13 | @property (nonatomic) CGFloat progress; 14 | @end 15 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep2/OneLoadingAnimationStep2/Src/OneLoadingAnimation/ArcToCircleLayer.m: -------------------------------------------------------------------------------- 1 | // 2 | // OneLoadingAnimation.h 3 | // OneLoadingAnimationStep1 4 | // 5 | // Created by thatsoul on 15/11/15. 6 | // Copyright (c) 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import "ArcToCircleLayer.h" 10 | 11 | static CGFloat const kLineWidth = 6; 12 | 13 | @implementation ArcToCircleLayer 14 | 15 | @dynamic progress; 16 | 17 | + (BOOL)needsDisplayForKey:(NSString *)key { 18 | if ([key isEqualToString:@"progress"]) { 19 | return YES; 20 | } 21 | 22 | return [super needsDisplayForKey:key]; 23 | } 24 | 25 | - (void)drawInContext:(CGContextRef)ctx { 26 | UIBezierPath *path = [UIBezierPath bezierPath]; 27 | 28 | CGFloat radius = MIN(CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds)) / 2 - kLineWidth / 2; 29 | CGPoint center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds)); 30 | 31 | // O 32 | CGFloat originStart = M_PI * 7 / 2; 33 | CGFloat originEnd = M_PI * 2; 34 | CGFloat currentOrigin = originStart - (originStart - originEnd) * self.progress; 35 | 36 | // D 37 | CGFloat destStart = M_PI * 3; 38 | CGFloat destEnd = 0; 39 | CGFloat currentDest = destStart - (destStart - destEnd) * self.progress; 40 | 41 | [path addArcWithCenter:center radius:radius startAngle: currentOrigin endAngle:currentDest clockwise:NO]; 42 | CGContextAddPath(ctx, path.CGPath); 43 | CGContextSetLineWidth(ctx, kLineWidth); 44 | CGContextSetStrokeColorWithColor(ctx, [UIColor lightGrayColor].CGColor); 45 | CGContextStrokePath(ctx); 46 | } 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep2/OneLoadingAnimationStep2/Src/OneLoadingAnimation/OneLoadingAnimationView.h: -------------------------------------------------------------------------------- 1 | // 2 | // OneLoadingAnimation.h 3 | // OneLoadingAnimationStep1 4 | // 5 | // Created by thatsoul on 15/11/15. 6 | // Copyright © 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OneLoadingAnimationView : UIView 12 | - (void)startAnimation; 13 | @end 14 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep2/OneLoadingAnimationStep2/Src/OneLoadingAnimation/OneLoadingAnimationView.m: -------------------------------------------------------------------------------- 1 | // 2 | // OneLoadingAnimation.m 3 | // OneLoadingAnimationStep1 4 | // 5 | // Created by thatsoul on 15/11/15. 6 | // Copyright © 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import "OneLoadingAnimationView.h" 10 | #import "ArcToCircleLayer.h" 11 | 12 | static NSString * const kName = @"name"; 13 | 14 | static CGFloat const kRadius = 40; 15 | static CGFloat const kLineWidth = 6; 16 | static CGFloat const kStep1Duration = 1.0; 17 | static CGFloat const kStep2Duration = 3.0; 18 | 19 | @interface OneLoadingAnimationView () 20 | @property (nonatomic) ArcToCircleLayer *arcToCircleLayer; 21 | @property (nonatomic) CAShapeLayer *moveArcLayer; 22 | @end 23 | 24 | @implementation OneLoadingAnimationView 25 | 26 | - (void)awakeFromNib { 27 | [super awakeFromNib]; 28 | } 29 | 30 | #pragma mark - public 31 | - (void)startAnimation { 32 | [self reset]; 33 | [self doStep1]; 34 | } 35 | 36 | #pragma mark - animation 37 | - (void)reset { 38 | [self.arcToCircleLayer removeFromSuperlayer]; 39 | [self.moveArcLayer removeFromSuperlayer]; 40 | } 41 | 42 | // 第1阶段 43 | - (void)doStep1 { 44 | self.arcToCircleLayer = [ArcToCircleLayer layer]; 45 | self.arcToCircleLayer.contentsScale = [UIScreen mainScreen].scale; 46 | [self.layer addSublayer:self.arcToCircleLayer]; 47 | 48 | self.arcToCircleLayer.bounds = CGRectMake(0, 0, kRadius * 2 + kLineWidth, kRadius * 2 + kLineWidth); 49 | self.arcToCircleLayer.position = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds)); 50 | 51 | // animation 52 | self.arcToCircleLayer.progress = 1; // end status 53 | 54 | CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"progress"]; 55 | animation.duration = kStep1Duration; 56 | animation.fromValue = @0.0; 57 | animation.toValue = @1.0; 58 | animation.delegate = self; 59 | [animation setValue:@"step1" forKey:kName]; 60 | [self.arcToCircleLayer addAnimation:animation forKey:nil]; 61 | } 62 | 63 | // 第2阶段 64 | - (void)doStep2 { 65 | self.moveArcLayer = [CAShapeLayer layer]; 66 | [self.layer addSublayer:self.moveArcLayer]; 67 | self.moveArcLayer.frame = self.layer.bounds; 68 | // 弧的path 69 | UIBezierPath *moveArcPath = [UIBezierPath bezierPath]; 70 | // 小圆圆心 71 | CGPoint center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds)); 72 | // d(x轴上弧圆心与小圆左边缘的距离) 73 | CGFloat d = kRadius / 2; 74 | // 弧圆心 75 | CGPoint arcCenter = CGPointMake(center.x - kRadius - d, center.y); 76 | // 弧半径 77 | CGFloat arcRadius = kRadius * 2 + d; 78 | // O(origin) 79 | CGFloat origin = M_PI * 2; 80 | // D(dest) 81 | CGFloat dest = M_PI * 2 - asin(kRadius * 2 / arcRadius); 82 | [moveArcPath addArcWithCenter:arcCenter radius:arcRadius startAngle:origin endAngle:dest clockwise:NO]; 83 | self.moveArcLayer.path = moveArcPath.CGPath; 84 | self.moveArcLayer.lineWidth = 3; 85 | self.moveArcLayer.strokeColor = [UIColor blueColor].CGColor; 86 | self.moveArcLayer.fillColor = nil; 87 | 88 | // SS(strokeStart) 89 | CGFloat SSFrom = 0; 90 | CGFloat SSTo = 0.9; 91 | 92 | // SE(strokeEnd) 93 | CGFloat SEFrom = 0.1; 94 | CGFloat SETo = 1; 95 | 96 | // end status 97 | self.moveArcLayer.strokeStart = SSTo; 98 | self.moveArcLayer.strokeEnd = SETo; 99 | 100 | // animation 101 | CABasicAnimation *startAnimation = [CABasicAnimation animationWithKeyPath:@"strokeStart"]; 102 | startAnimation.fromValue = @(SSFrom); 103 | startAnimation.toValue = @(SSTo); 104 | 105 | CABasicAnimation *endAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; 106 | endAnimation.fromValue = @(SEFrom); 107 | endAnimation.toValue = @(SETo); 108 | 109 | CAAnimationGroup *step2 = [CAAnimationGroup animation]; 110 | step2.animations = @[startAnimation, endAnimation]; 111 | step2.duration = kStep2Duration; 112 | step2.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]; 113 | 114 | [self.moveArcLayer addAnimation:step2 forKey:nil]; 115 | } 116 | 117 | #pragma mark - animation step stop 118 | - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag { 119 | if ([[anim valueForKey:kName] isEqualToString:@"step1"]) { 120 | [self doStep2]; 121 | } 122 | } 123 | 124 | @end 125 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep2/OneLoadingAnimationStep2/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // OneLoadingAnimationStep2 4 | // 5 | // Created by thatsoul on 15/11/21. 6 | // Copyright © 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep2/OneLoadingAnimationStep2/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // OneLoadingAnimationStep2 4 | // 5 | // Created by thatsoul on 15/11/21. 6 | // Copyright © 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "OneLoadingAnimationView.h" 11 | 12 | @interface ViewController () 13 | @property (weak, nonatomic) IBOutlet OneLoadingAnimationView *animationView; 14 | @end 15 | 16 | @implementation ViewController 17 | 18 | - (void)viewDidLoad { 19 | [super viewDidLoad]; 20 | // Do any additional setup after loading the view, typically from a nib. 21 | } 22 | 23 | - (void)didReceiveMemoryWarning { 24 | [super didReceiveMemoryWarning]; 25 | // Dispose of any resources that can be recreated. 26 | } 27 | 28 | #pragma mark - user event 29 | - (IBAction)onTapStartAnimation:(id)sender { 30 | [self.animationView startAnimation]; 31 | } 32 | @end 33 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep2/OneLoadingAnimationStep2/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // OneLoadingAnimationStep2 4 | // 5 | // Created by thatsoul on 15/11/21. 6 | // Copyright © 2015年 chenms.m2. 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 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep3/OneLoadingAnimationStep3.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep3/OneLoadingAnimationStep3/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // OneLoadingAnimationStep3 4 | // 5 | // Created by thatsoul on 15/11/29. 6 | // Copyright © 2015年 chenms.m2. 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 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep3/OneLoadingAnimationStep3/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // OneLoadingAnimationStep3 4 | // 5 | // Created by thatsoul on 15/11/29. 6 | // Copyright © 2015年 chenms.m2. 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 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep3/OneLoadingAnimationStep3/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep3/OneLoadingAnimationStep3/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep3/OneLoadingAnimationStep3/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 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep3/OneLoadingAnimationStep3/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep3/OneLoadingAnimationStep3/Src/OneLoadingAnimation/ArcToCircleLayer.h: -------------------------------------------------------------------------------- 1 | // 2 | // OneLoadingAnimation.h 3 | // OneLoadingAnimationStep1 4 | // 5 | // Created by thatsoul on 15/11/15. 6 | // Copyright (c) 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface ArcToCircleLayer : CALayer 13 | @property (nonatomic) CGFloat progress; 14 | @end 15 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep3/OneLoadingAnimationStep3/Src/OneLoadingAnimation/ArcToCircleLayer.m: -------------------------------------------------------------------------------- 1 | // 2 | // OneLoadingAnimation.h 3 | // OneLoadingAnimationStep1 4 | // 5 | // Created by thatsoul on 15/11/15. 6 | // Copyright (c) 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import "ArcToCircleLayer.h" 10 | 11 | static CGFloat const kLineWidth = 6; 12 | 13 | @implementation ArcToCircleLayer 14 | 15 | @dynamic progress; 16 | 17 | + (BOOL)needsDisplayForKey:(NSString *)key { 18 | if ([key isEqualToString:@"progress"]) { 19 | return YES; 20 | } 21 | 22 | return [super needsDisplayForKey:key]; 23 | } 24 | 25 | - (void)drawInContext:(CGContextRef)ctx { 26 | UIBezierPath *path = [UIBezierPath bezierPath]; 27 | 28 | CGFloat radius = MIN(CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds)) / 2 - kLineWidth / 2; 29 | CGPoint center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds)); 30 | 31 | // O 32 | CGFloat originStart = M_PI * 7 / 2; 33 | CGFloat originEnd = M_PI * 2; 34 | CGFloat currentOrigin = originStart - (originStart - originEnd) * self.progress; 35 | 36 | // D 37 | CGFloat destStart = M_PI * 3; 38 | CGFloat destEnd = 0; 39 | CGFloat currentDest = destStart - (destStart - destEnd) * self.progress; 40 | 41 | [path addArcWithCenter:center radius:radius startAngle: currentOrigin endAngle:currentDest clockwise:NO]; 42 | CGContextAddPath(ctx, path.CGPath); 43 | CGContextSetLineWidth(ctx, kLineWidth); 44 | CGContextSetStrokeColorWithColor(ctx, [UIColor lightGrayColor].CGColor); 45 | CGContextStrokePath(ctx); 46 | } 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep3/OneLoadingAnimationStep3/Src/OneLoadingAnimation/OneLoadingAnimationView.h: -------------------------------------------------------------------------------- 1 | // 2 | // OneLoadingAnimation.h 3 | // OneLoadingAnimationStep1 4 | // 5 | // Created by thatsoul on 15/11/15. 6 | // Copyright © 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OneLoadingAnimationView : UIView 12 | - (void)startAnimation; 13 | @end 14 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep3/OneLoadingAnimationStep3/Src/OneLoadingAnimation/OneLoadingAnimationView.m: -------------------------------------------------------------------------------- 1 | // 2 | // OneLoadingAnimation.m 3 | // OneLoadingAnimationStep1 4 | // 5 | // Created by thatsoul on 15/11/15. 6 | // Copyright © 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import "OneLoadingAnimationView.h" 10 | #import "ArcToCircleLayer.h" 11 | 12 | static NSString * const kName = @"name"; 13 | 14 | static CGFloat const kRadius = 40; 15 | static CGFloat const kLineWidth = 6; 16 | static CGFloat const kStep1Duration = 1.0; 17 | static CGFloat const kStep2Duration = 0.5; 18 | static CGFloat const kStep3Duration = 2.0; 19 | static CGFloat const kVerticalThinLayerWidth = 3; 20 | static CGFloat const kVerticalMoveLayerLength = 15; 21 | 22 | @interface OneLoadingAnimationView () 23 | @property (nonatomic) ArcToCircleLayer *arcToCircleLayer; 24 | @property (nonatomic) CAShapeLayer *moveArcLayer; 25 | @property (nonatomic) CALayer *verticalMoveLayer; 26 | @end 27 | 28 | @implementation OneLoadingAnimationView 29 | 30 | - (void)awakeFromNib { 31 | [super awakeFromNib]; 32 | } 33 | 34 | #pragma mark - public 35 | - (void)startAnimation { 36 | [self reset]; 37 | [self doStep1]; 38 | } 39 | 40 | #pragma mark - animation 41 | - (void)reset { 42 | [self.arcToCircleLayer removeFromSuperlayer]; 43 | [self.moveArcLayer removeFromSuperlayer]; 44 | [self.verticalMoveLayer removeFromSuperlayer]; 45 | } 46 | 47 | // 第1阶段 48 | - (void)doStep1 { 49 | self.arcToCircleLayer = [ArcToCircleLayer layer]; 50 | self.arcToCircleLayer.contentsScale = [UIScreen mainScreen].scale; 51 | [self.layer addSublayer:self.arcToCircleLayer]; 52 | 53 | self.arcToCircleLayer.bounds = CGRectMake(0, 0, kRadius * 2 + kLineWidth, kRadius * 2 + kLineWidth); 54 | self.arcToCircleLayer.position = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds)); 55 | 56 | // animation 57 | self.arcToCircleLayer.progress = 1; // end status 58 | 59 | CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"progress"]; 60 | animation.duration = kStep1Duration; 61 | animation.fromValue = @0.0; 62 | animation.toValue = @1.0; 63 | animation.delegate = self; 64 | [animation setValue:@"step1" forKey:kName]; 65 | [self.arcToCircleLayer addAnimation:animation forKey:nil]; 66 | } 67 | 68 | // 第2阶段 69 | - (void)doStep2 { 70 | self.moveArcLayer = [CAShapeLayer layer]; 71 | [self.layer addSublayer:self.moveArcLayer]; 72 | self.moveArcLayer.frame = self.layer.bounds; 73 | // 弧的path 74 | UIBezierPath *moveArcPath = [UIBezierPath bezierPath]; 75 | // 小圆圆心 76 | CGPoint center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds)); 77 | // d(x轴上弧圆心与小圆左边缘的距离) 78 | CGFloat d = kRadius / 2; 79 | // 弧圆心 80 | CGPoint arcCenter = CGPointMake(center.x - kRadius - d, center.y); 81 | // 弧半径 82 | CGFloat arcRadius = kRadius * 2 + d; 83 | // O(origin) 84 | CGFloat origin = M_PI * 2; 85 | // D(dest) 86 | CGFloat dest = M_PI * 2 - asin(kRadius * 2 / arcRadius); 87 | [moveArcPath addArcWithCenter:arcCenter radius:arcRadius startAngle:origin endAngle:dest clockwise:NO]; 88 | self.moveArcLayer.path = moveArcPath.CGPath; 89 | self.moveArcLayer.lineWidth = 3; 90 | self.moveArcLayer.strokeColor = [UIColor lightGrayColor].CGColor; 91 | self.moveArcLayer.fillColor = nil; 92 | 93 | // SS(strokeStart) 94 | CGFloat SSFrom = 0; 95 | CGFloat SSTo = 0.9; 96 | 97 | // SE(strokeEnd) 98 | CGFloat SEFrom = 0.1; 99 | CGFloat SETo = 1; 100 | 101 | // end status 102 | self.moveArcLayer.strokeStart = SSTo; 103 | self.moveArcLayer.strokeEnd = SETo; 104 | 105 | // animation 106 | CABasicAnimation *startAnimation = [CABasicAnimation animationWithKeyPath:@"strokeStart"]; 107 | startAnimation.fromValue = @(SSFrom); 108 | startAnimation.toValue = @(SSTo); 109 | 110 | CABasicAnimation *endAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; 111 | endAnimation.fromValue = @(SEFrom); 112 | endAnimation.toValue = @(SETo); 113 | 114 | CAAnimationGroup *step2 = [CAAnimationGroup animation]; 115 | step2.animations = @[startAnimation, endAnimation]; 116 | step2.duration = kStep2Duration; 117 | step2.delegate = self; 118 | [step2 setValue:@"step2" forKey:kName]; 119 | step2.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]; 120 | 121 | [self.moveArcLayer addAnimation:step2 forKey:nil]; 122 | } 123 | 124 | // 第3阶段 125 | - (void)doStep3 { 126 | // remove not useful 127 | [self.moveArcLayer removeFromSuperlayer]; 128 | 129 | // step3 layer 130 | self.verticalMoveLayer = [CALayer layer]; 131 | self.verticalMoveLayer.contentsScale = [UIScreen mainScreen].scale; 132 | [self.layer addSublayer:self.verticalMoveLayer]; 133 | 134 | CGFloat height = kVerticalMoveLayerLength; 135 | self.verticalMoveLayer.bounds = CGRectMake(0, 0, kVerticalThinLayerWidth, height); 136 | self.verticalMoveLayer.position = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds) - kRadius * 2 + height / 2); 137 | self.verticalMoveLayer.backgroundColor = [UIColor blueColor].CGColor; 138 | 139 | // position 140 | CGPoint originPosition = self.verticalMoveLayer.position; 141 | CGPoint destPosition = CGPointMake(originPosition.x, CGRectGetMidY(self.bounds) - kRadius - height / 2); 142 | 143 | // end status 144 | self.verticalMoveLayer.position = destPosition; 145 | 146 | // animation 147 | CABasicAnimation *step3 = [CABasicAnimation animationWithKeyPath:@"position.y"]; 148 | step3.fromValue = @(originPosition.y); 149 | step3.toValue = @(destPosition.y); 150 | step3.duration = kStep3Duration; 151 | [self.verticalMoveLayer addAnimation:step3 forKey:nil]; 152 | } 153 | 154 | #pragma mark - animation step stop 155 | - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag { 156 | if ([[anim valueForKey:kName] isEqualToString:@"step1"]) { 157 | [self doStep2]; 158 | } else if ([[anim valueForKey:kName] isEqualToString:@"step2"]) { 159 | [self doStep3]; 160 | } 161 | } 162 | 163 | @end 164 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep3/OneLoadingAnimationStep3/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // OneLoadingAnimationStep3 4 | // 5 | // Created by thatsoul on 15/11/29. 6 | // Copyright © 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep3/OneLoadingAnimationStep3/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // OneLoadingAnimationStep3 4 | // 5 | // Created by thatsoul on 15/11/29. 6 | // Copyright © 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "OneLoadingAnimationView.h" 11 | 12 | @interface ViewController () 13 | @property (weak, nonatomic) IBOutlet OneLoadingAnimationView *animationView; 14 | 15 | @end 16 | 17 | @implementation ViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | // Do any additional setup after loading the view, typically from a nib. 22 | } 23 | 24 | - (void)didReceiveMemoryWarning { 25 | [super didReceiveMemoryWarning]; 26 | // Dispose of any resources that can be recreated. 27 | } 28 | 29 | #pragma mark - user event 30 | - (IBAction)onTapStartAnimation:(id)sender { 31 | [self.animationView startAnimation]; 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep3/OneLoadingAnimationStep3/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // OneLoadingAnimationStep3 4 | // 5 | // Created by thatsoul on 15/11/29. 6 | // Copyright © 2015年 chenms.m2. 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 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep4/OneLoadingAnimationStep4.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep4/OneLoadingAnimationStep4/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // OneLoadingAnimationStep4 4 | // 5 | // Created by thatsoul on 15/11/29. 6 | // Copyright © 2015年 chenms.m2. 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 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep4/OneLoadingAnimationStep4/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // OneLoadingAnimationStep4 4 | // 5 | // Created by thatsoul on 15/11/29. 6 | // Copyright © 2015年 chenms.m2. 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 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep4/OneLoadingAnimationStep4/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep4/OneLoadingAnimationStep4/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep4/OneLoadingAnimationStep4/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 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep4/OneLoadingAnimationStep4/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep4/OneLoadingAnimationStep4/Src/OneLoadingAnimation/ArcToCircleLayer.h: -------------------------------------------------------------------------------- 1 | // 2 | // OneLoadingAnimation.h 3 | // OneLoadingAnimationStep1 4 | // 5 | // Created by thatsoul on 15/11/15. 6 | // Copyright (c) 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface ArcToCircleLayer : CALayer 13 | @property (nonatomic) CGFloat progress; 14 | @property (nonatomic) UIColor *color; 15 | @property (nonatomic) CGFloat lineWidth; 16 | @end 17 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep4/OneLoadingAnimationStep4/Src/OneLoadingAnimation/ArcToCircleLayer.m: -------------------------------------------------------------------------------- 1 | // 2 | // OneLoadingAnimation.h 3 | // OneLoadingAnimationStep1 4 | // 5 | // Created by thatsoul on 15/11/15. 6 | // Copyright (c) 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import "ArcToCircleLayer.h" 10 | 11 | static CGFloat const kLineWidth = 6; 12 | 13 | @implementation ArcToCircleLayer 14 | 15 | @dynamic progress; 16 | @dynamic color; 17 | @dynamic lineWidth; 18 | 19 | + (BOOL)needsDisplayForKey:(NSString *)key { 20 | if ([key isEqualToString:@"progress"]) { 21 | return YES; 22 | } else if ([key isEqualToString:@"color"]) { 23 | return YES; 24 | } else if ([key isEqualToString:@"lineWidth"]) { 25 | return YES; 26 | } 27 | 28 | return [super needsDisplayForKey:key]; 29 | } 30 | 31 | - (void)drawInContext:(CGContextRef)ctx { 32 | UIBezierPath *path = [UIBezierPath bezierPath]; 33 | 34 | CGFloat radius = MIN(CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds)) / 2 - kLineWidth / 2; 35 | CGPoint center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds)); 36 | 37 | // O 38 | CGFloat originStart = M_PI * 7 / 2; 39 | CGFloat originEnd = M_PI * 2; 40 | CGFloat currentOrigin = originStart - (originStart - originEnd) * self.progress; 41 | 42 | // D 43 | CGFloat destStart = M_PI * 3; 44 | CGFloat destEnd = 0; 45 | CGFloat currentDest = destStart - (destStart - destEnd) * self.progress; 46 | 47 | [path addArcWithCenter:center radius:radius startAngle: currentOrigin endAngle:currentDest clockwise:NO]; 48 | CGContextAddPath(ctx, path.CGPath); 49 | CGContextSetLineWidth(ctx, self.lineWidth); 50 | CGContextSetStrokeColorWithColor(ctx, self.color.CGColor); 51 | CGContextStrokePath(ctx); 52 | } 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep4/OneLoadingAnimationStep4/Src/OneLoadingAnimation/OneLoadingAnimationView.h: -------------------------------------------------------------------------------- 1 | // 2 | // OneLoadingAnimation.h 3 | // OneLoadingAnimationStep1 4 | // 5 | // Created by thatsoul on 15/11/15. 6 | // Copyright © 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OneLoadingAnimationView : UIView 12 | - (void)startAnimation; 13 | @end 14 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep4/OneLoadingAnimationStep4/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // OneLoadingAnimationStep3 4 | // 5 | // Created by thatsoul on 15/11/29. 6 | // Copyright © 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep4/OneLoadingAnimationStep4/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // OneLoadingAnimationStep3 4 | // 5 | // Created by thatsoul on 15/11/29. 6 | // Copyright © 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "OneLoadingAnimationView.h" 11 | 12 | @interface ViewController () 13 | @property (weak, nonatomic) IBOutlet OneLoadingAnimationView *animationView; 14 | 15 | @end 16 | 17 | @implementation ViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | // Do any additional setup after loading the view, typically from a nib. 22 | } 23 | 24 | - (void)didReceiveMemoryWarning { 25 | [super didReceiveMemoryWarning]; 26 | // Dispose of any resources that can be recreated. 27 | } 28 | 29 | #pragma mark - user event 30 | - (IBAction)onTapStartAnimation:(id)sender { 31 | [self.animationView startAnimation]; 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep4/OneLoadingAnimationStep4/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // OneLoadingAnimationStep4 4 | // 5 | // Created by thatsoul on 15/11/29. 6 | // Copyright © 2015年 chenms.m2. 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 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep5/OneLoadingAnimationStep5.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep5/OneLoadingAnimationStep5/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // OneLoadingAnimationStep5 4 | // 5 | // Created by thatsoul on 15/12/1. 6 | // Copyright © 2015年 chenms.m2. 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 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep5/OneLoadingAnimationStep5/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // OneLoadingAnimationStep5 4 | // 5 | // Created by thatsoul on 15/12/1. 6 | // Copyright © 2015年 chenms.m2. 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 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep5/OneLoadingAnimationStep5/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep5/OneLoadingAnimationStep5/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep5/OneLoadingAnimationStep5/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 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep5/OneLoadingAnimationStep5/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep5/OneLoadingAnimationStep5/Src/OneLoadingAnimation/ArcToCircleLayer.h: -------------------------------------------------------------------------------- 1 | // 2 | // OneLoadingAnimation.h 3 | // OneLoadingAnimationStep1 4 | // 5 | // Created by thatsoul on 15/11/15. 6 | // Copyright (c) 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface ArcToCircleLayer : CALayer 13 | @property (nonatomic) CGFloat progress; 14 | @property (nonatomic) UIColor *color; 15 | @property (nonatomic) CGFloat lineWidth; 16 | @end 17 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep5/OneLoadingAnimationStep5/Src/OneLoadingAnimation/ArcToCircleLayer.m: -------------------------------------------------------------------------------- 1 | // 2 | // OneLoadingAnimation.h 3 | // OneLoadingAnimationStep1 4 | // 5 | // Created by thatsoul on 15/11/15. 6 | // Copyright (c) 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import "ArcToCircleLayer.h" 10 | 11 | static CGFloat const kLineWidth = 6; 12 | 13 | @implementation ArcToCircleLayer 14 | 15 | @dynamic progress; 16 | @dynamic color; 17 | @dynamic lineWidth; 18 | 19 | + (BOOL)needsDisplayForKey:(NSString *)key { 20 | if ([key isEqualToString:@"progress"]) { 21 | return YES; 22 | } else if ([key isEqualToString:@"color"]) { 23 | return YES; 24 | } else if ([key isEqualToString:@"lineWidth"]) { 25 | return YES; 26 | } 27 | 28 | return [super needsDisplayForKey:key]; 29 | } 30 | 31 | - (void)drawInContext:(CGContextRef)ctx { 32 | UIBezierPath *path = [UIBezierPath bezierPath]; 33 | 34 | CGFloat radius = MIN(CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds)) / 2 - kLineWidth / 2; 35 | CGPoint center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds)); 36 | 37 | // O 38 | CGFloat originStart = M_PI * 7 / 2; 39 | CGFloat originEnd = M_PI * 2; 40 | CGFloat currentOrigin = originStart - (originStart - originEnd) * self.progress; 41 | 42 | // D 43 | CGFloat destStart = M_PI * 3; 44 | CGFloat destEnd = 0; 45 | CGFloat currentDest = destStart - (destStart - destEnd) * self.progress; 46 | 47 | [path addArcWithCenter:center radius:radius startAngle: currentOrigin endAngle:currentDest clockwise:NO]; 48 | CGContextAddPath(ctx, path.CGPath); 49 | CGContextSetLineWidth(ctx, self.lineWidth); 50 | CGContextSetStrokeColorWithColor(ctx, self.color.CGColor); 51 | CGContextStrokePath(ctx); 52 | } 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep5/OneLoadingAnimationStep5/Src/OneLoadingAnimation/OneLoadingAnimationView.h: -------------------------------------------------------------------------------- 1 | // 2 | // OneLoadingAnimation.h 3 | // OneLoadingAnimationStep1 4 | // 5 | // Created by thatsoul on 15/11/15. 6 | // Copyright © 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OneLoadingAnimationView : UIView 12 | - (void)startAnimation; 13 | @end 14 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep5/OneLoadingAnimationStep5/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // OneLoadingAnimationStep3 4 | // 5 | // Created by thatsoul on 15/11/29. 6 | // Copyright © 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep5/OneLoadingAnimationStep5/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // OneLoadingAnimationStep3 4 | // 5 | // Created by thatsoul on 15/11/29. 6 | // Copyright © 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "OneLoadingAnimationView.h" 11 | 12 | @interface ViewController () 13 | @property (weak, nonatomic) IBOutlet OneLoadingAnimationView *animationView; 14 | 15 | @end 16 | 17 | @implementation ViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | // Do any additional setup after loading the view, typically from a nib. 22 | } 23 | 24 | - (void)didReceiveMemoryWarning { 25 | [super didReceiveMemoryWarning]; 26 | // Dispose of any resources that can be recreated. 27 | } 28 | 29 | #pragma mark - user event 30 | - (IBAction)onTapStartAnimation:(id)sender { 31 | [self.animationView startAnimation]; 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /OC/OneLoadingAnimationStep5/OneLoadingAnimationStep5/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // OneLoadingAnimationStep5 4 | // 5 | // Created by thatsoul on 15/12/1. 6 | // Copyright © 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 一款Loading动画的实现思路 2 | 3 | #### 这是原版动画 4 | ![](http://upload-images.jianshu.io/upload_images/1013170-f4ff25b49b577aee.gif?imageMogr2/auto-orient/strip) 5 | 6 | #### 这是我简化后的实现 7 | ![](http://upload-images.jianshu.io/upload_images/1013170-91389ecfed05069b.gif?imageMogr2/auto-orient/strip) 8 | 9 | #### 实现思路 10 | - [一款Loading动画的实现思路(一)](http://www.jianshu.com/p/1c6a2de68753) 11 | - [一款Loading动画的实现思路(二)](http://www.jianshu.com/p/0dac1208a7ad) 12 | - [一款Loading动画的实现思路(三)](http://www.jianshu.com/p/56448d3d3596) 13 | - [一款Loading动画的实现思路(四·完结篇)](http://www.jianshu.com/p/41f277682c91) 14 | - [Loading动画外篇·圆的不规则变形](http://www.jianshu.com/p/ce4e5f226d34) 15 | -------------------------------------------------------------------------------- /Swift/CircleIrregularTransformSwift/CircleIrregularTransformSwift.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Swift/CircleIrregularTransformSwift/CircleIrregularTransformSwift/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // CircleIrregularTransformSwift 4 | // 5 | // Created by thatsoul on 16/1/2. 6 | // Copyright © 2016年 chenms.m2. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(application: UIApplication) { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Swift/CircleIrregularTransformSwift/CircleIrregularTransformSwift/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /Swift/CircleIrregularTransformSwift/CircleIrregularTransformSwift/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Swift/CircleIrregularTransformSwift/CircleIrregularTransformSwift/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 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /Swift/CircleIrregularTransformSwift/CircleIrregularTransformSwift/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /Swift/CircleIrregularTransformSwift/CircleIrregularTransformSwift/Source/CircleIrregularTransform/CircleIrregularTransformLayer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CircleIrregularTransformLayer.swift 3 | // CircleIrregularTransformSwift 4 | // 5 | // Created by thatsoul on 16/1/2. 6 | // Copyright © 2016年 chenms.m2. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class CircleIrregularTransformLayer: CALayer { 12 | var progress: CGFloat = 0 13 | 14 | let radius: CGFloat = 80 15 | let lineWidth: CGFloat = 6.0 16 | let xScale: CGFloat = 1.2 17 | let yScale: CGFloat = 0.8 18 | let controlPointFactor: CGFloat = 1.8 19 | let pointRadius: CGFloat = 3.0 20 | 21 | // MARK: - init 22 | override init(layer: AnyObject) { 23 | super.init(layer: layer) 24 | 25 | let theLayer = layer as! CircleIrregularTransformLayer 26 | progress = theLayer.progress 27 | } 28 | 29 | required init?(coder aDecoder: NSCoder) { 30 | super.init(coder: aDecoder) 31 | } 32 | 33 | override init() { 34 | super.init() 35 | } 36 | 37 | // MARK: - needsDisplayForKey 38 | override static func needsDisplayForKey(key: String) -> Bool { 39 | switch key { 40 | case "progress": 41 | return true 42 | default: 43 | break 44 | } 45 | 46 | return super.needsDisplayForKey(key) 47 | } 48 | 49 | // MARK: - draw 50 | override func drawInContext(ctx: CGContext) { 51 | let path = UIBezierPath() 52 | 53 | // 以底点为原点 54 | let bottom = CGPoint(x: CGRectGetMidX(bounds), y: CGRectGetMidY(bounds) + radius) 55 | // 控制点偏移距离 56 | let controlOffsetDistance = radius / controlPointFactor 57 | 58 | // 各点变化系数 59 | let xFactor = 1 + (xScale - 1) * progress 60 | let yFactor = 1 - (1 - yScale) * progress 61 | // 顶点特殊的变化系数(破坏规则变形) 62 | let topYFactor = 1 - (1 - yScale) * progress * 1.5 63 | 64 | // 右上弧 65 | let origin0 = CGPointMake(bottom.x + radius * xFactor, bottom.y - radius * yFactor) 66 | let dest0 = CGPointMake(bottom.x, bottom.y - radius * 2 * topYFactor) 67 | let control0A = CGPointMake(origin0.x, origin0.y - controlOffsetDistance) 68 | let control0B = CGPointMake(dest0.x + controlOffsetDistance, bottom.y - radius * 2 * yFactor) 69 | path.moveToPoint(origin0) 70 | path.addCurveToPoint(dest0, controlPoint1: control0A, controlPoint2: control0B) 71 | 72 | // 左上弧 73 | let origin1 = dest0 74 | let dest1 = CGPointMake(bottom.x - radius * xFactor, bottom.y - radius * yFactor) 75 | let control1A = CGPointMake(origin1.x - controlOffsetDistance, bottom.y - radius * 2 * yFactor) 76 | let control1B = CGPointMake(dest1.x, dest1.y - controlOffsetDistance) 77 | path.addCurveToPoint(dest1, controlPoint1: control1A, controlPoint2: control1B) 78 | 79 | // 左下弧 80 | let origin2 = dest1 81 | let dest2 = bottom 82 | let control2A = CGPointMake(origin2.x, origin2.y + controlOffsetDistance) 83 | let control2B = CGPointMake(dest2.x - controlOffsetDistance, dest2.y) 84 | path.addCurveToPoint(dest2, controlPoint1: control2A, controlPoint2: control2B) 85 | 86 | // 右下弧 87 | let origin3 = dest2 88 | let dest3 = origin0 89 | let control3A = CGPointMake(origin3.x + controlOffsetDistance, origin3.y) 90 | let control3B = CGPointMake(dest3.x, dest3.y + controlOffsetDistance) 91 | path.addCurveToPoint(dest3, controlPoint1: control3A, controlPoint2: control3B) 92 | 93 | CGContextAddPath(ctx, path.CGPath) 94 | 95 | CGContextSetLineWidth(ctx, lineWidth) 96 | CGContextSetStrokeColorWithColor(ctx, UIColor.blueColor().CGColor) 97 | CGContextStrokePath(ctx) 98 | 99 | // 辅助点 100 | let pointsPath = UIBezierPath() 101 | 102 | addArcForPath(pointsPath, point: origin0) 103 | addArcForPath(pointsPath, point: control0A) 104 | addArcForPath(pointsPath, point: control0B) 105 | addArcForPath(pointsPath, point: dest0) 106 | 107 | addArcForPath(pointsPath, point: origin1) 108 | addArcForPath(pointsPath, point: control1A) 109 | addArcForPath(pointsPath, point: control1B) 110 | addArcForPath(pointsPath, point: dest1) 111 | 112 | addArcForPath(pointsPath, point: origin2) 113 | addArcForPath(pointsPath, point: control2A) 114 | addArcForPath(pointsPath, point: control2B) 115 | addArcForPath(pointsPath, point: dest2) 116 | 117 | addArcForPath(pointsPath, point: origin3) 118 | addArcForPath(pointsPath, point: control3A) 119 | addArcForPath(pointsPath, point: control3B) 120 | addArcForPath(pointsPath, point: dest3) 121 | 122 | CGContextAddPath(ctx, pointsPath.CGPath) 123 | 124 | CGContextSetFillColorWithColor(ctx, UIColor.redColor().CGColor) 125 | CGContextFillPath(ctx) 126 | 127 | // 辅助线 128 | let linePath = UIBezierPath() 129 | 130 | linePath.moveToPoint(origin0) 131 | linePath.addLineToPoint(control0A) 132 | linePath.addLineToPoint(control0B) 133 | linePath.addLineToPoint(dest0) 134 | 135 | linePath.addLineToPoint(origin1) 136 | linePath.addLineToPoint(control1A) 137 | linePath.addLineToPoint(control1B) 138 | linePath.addLineToPoint(dest1) 139 | 140 | linePath.addLineToPoint(origin2) 141 | linePath.addLineToPoint(control2A) 142 | linePath.addLineToPoint(control2B) 143 | linePath.addLineToPoint(dest2) 144 | 145 | linePath.addLineToPoint(origin3) 146 | linePath.addLineToPoint(control3A) 147 | linePath.addLineToPoint(control3B) 148 | linePath.addLineToPoint(dest3) 149 | 150 | CGContextAddPath(ctx, linePath.CGPath) 151 | 152 | CGContextSetLineWidth(ctx, 2) 153 | CGContextSetStrokeColorWithColor(ctx, UIColor.redColor().CGColor) 154 | CGContextStrokePath(ctx) 155 | } 156 | 157 | // MARK: - tools 158 | private func addArcForPath(path: UIBezierPath, point: CGPoint) { 159 | path.moveToPoint(point) 160 | path.addArcWithCenter(point, radius: pointRadius, startAngle: 0, endAngle: CGFloat(M_PI * 2.0), clockwise: true) 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /Swift/CircleIrregularTransformSwift/CircleIrregularTransformSwift/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // CircleIrregularTransformSwift 4 | // 5 | // Created by thatsoul on 16/1/2. 6 | // Copyright © 2016年 chenms.m2. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | @IBOutlet weak var animationView: UIView! 13 | 14 | var animationLayer: CircleIrregularTransformLayer! 15 | 16 | // MARK: - life cycle 17 | override func viewDidLoad() { 18 | super.viewDidLoad() 19 | // Do any additional setup after loading the view, typically from a nib. 20 | addAnimationLayer() 21 | } 22 | 23 | private func addAnimationLayer() { 24 | animationLayer = CircleIrregularTransformLayer() 25 | animationLayer.contentsScale = UIScreen.mainScreen().scale 26 | animationLayer.frame = animationView.bounds 27 | animationLayer.progress = 0; 28 | animationView.layer.addSublayer(animationLayer) 29 | } 30 | 31 | override func didReceiveMemoryWarning() { 32 | super.didReceiveMemoryWarning() 33 | // Dispose of any resources that can be recreated. 34 | } 35 | 36 | // MARK: - user event 37 | @IBAction func startAnimation(sender: AnyObject) { 38 | // reset 39 | animationLayer.removeAllAnimations() 40 | 41 | // end status 42 | animationLayer.progress = 1; 43 | 44 | // animation 45 | let animation = CABasicAnimation(keyPath: "progress") 46 | animation.duration = 2 47 | animation.fromValue = 0.0 48 | animation.toValue = 1.0 49 | animationLayer.addAnimation(animation, forKey: nil) 50 | } 51 | } 52 | 53 | -------------------------------------------------------------------------------- /Swift/OneLoadingAnimationCompleteSwift/OneLoadingAnimationCompleteSwift.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Swift/OneLoadingAnimationCompleteSwift/OneLoadingAnimationCompleteSwift/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // OneLoadingAnimationCompleteSwift 4 | // 5 | // Created by thatsoul on 15/12/13. 6 | // Copyright © 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(application: UIApplication) { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Swift/OneLoadingAnimationCompleteSwift/OneLoadingAnimationCompleteSwift/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /Swift/OneLoadingAnimationCompleteSwift/OneLoadingAnimationCompleteSwift/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Swift/OneLoadingAnimationCompleteSwift/OneLoadingAnimationCompleteSwift/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 | 41 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /Swift/OneLoadingAnimationCompleteSwift/OneLoadingAnimationCompleteSwift/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /Swift/OneLoadingAnimationCompleteSwift/OneLoadingAnimationCompleteSwift/Src/OneLoadingAnimation/ArcToCircleLayer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ArcToCircleLayer.swift 3 | // OneLoadingAnimationCompleteSwift 4 | // 5 | // Created by thatsoul on 15/12/13. 6 | // Copyright © 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ArcToCircleLayer: CALayer { 12 | // MARK: - property 13 | var lineWidth: NSNumber? 14 | var color: UIColor? 15 | var progress: NSNumber? = 0 16 | 17 | // MARK: - override 18 | override class func needsDisplayForKey(key: String) -> Bool{ 19 | switch key { 20 | case "lineWidth", "color", "progress": 21 | return true 22 | default: 23 | break 24 | } 25 | 26 | return super.needsDisplayForKey(key) 27 | } 28 | 29 | // 这个方法是CA系统调用的,比如创建presentationLayer时,看上去自定义的属性值要手动赋值。 30 | override init(layer: AnyObject) { 31 | super.init(layer: layer) // TODO: 这个位置对吗? 32 | 33 | let theLayer: ArcToCircleLayer = layer as! ArcToCircleLayer 34 | self.progress = theLayer.progress 35 | self.color = theLayer.color 36 | self.lineWidth = theLayer.lineWidth 37 | 38 | // print("layer: \(layer) self: \(self)") // 打开这一句,看看log很有趣 39 | } 40 | 41 | // 看上去,如果override init(layer: AnyObject),必须 override init() 和 init?(coder aDecoder: NSCoder) 42 | override init() { 43 | super.init() // TODO: 这样OK吗? 44 | } 45 | 46 | required init?(coder aDecoder: NSCoder) { 47 | super.init(coder: aDecoder) // TODO: 这样OK吗? 48 | } 49 | 50 | override func drawInContext(ctx: CGContext) { 51 | // print("lineWidth: \(lineWidth) color: \(color)") 52 | if lineWidth == nil || color == nil { 53 | return 54 | } 55 | 56 | let path = UIBezierPath() 57 | 58 | let radius = min(CGRectGetWidth(bounds), CGRectGetHeight(bounds)) / 2 - CGFloat(lineWidth!.doubleValue) / 2 59 | let center = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds)) 60 | 61 | // O 62 | let originStart = M_PI * 7 / 2 63 | let originEnd = M_PI * 2 64 | let currentOrigin = originStart - (originStart - originEnd) * (progress?.doubleValue)! 65 | 66 | // D 67 | let destStart = M_PI * 3 68 | let destEnd = 0.0 69 | let currentDest = destStart - (destStart - destEnd) * (progress?.doubleValue)! 70 | 71 | path.addArcWithCenter(center, radius: radius, startAngle: CGFloat(currentOrigin), endAngle: CGFloat(currentDest), clockwise: false) 72 | 73 | CGContextAddPath(ctx, path.CGPath) 74 | CGContextSetLineWidth(ctx, CGFloat(lineWidth!.doubleValue)) 75 | 76 | CGContextSetStrokeColorWithColor(ctx, color!.CGColor) 77 | CGContextStrokePath(ctx) 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Swift/OneLoadingAnimationCompleteSwift/OneLoadingAnimationCompleteSwift/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // OneLoadingAnimationCompleteSwift 4 | // 5 | // Created by thatsoul on 15/12/13. 6 | // Copyright © 2015年 chenms.m2. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | // MARK: - property 13 | @IBOutlet weak var animationView: OneLoadingAnimationView! 14 | 15 | // MARK: - life cycle 16 | override func viewDidLoad() { 17 | super.viewDidLoad() 18 | // Do any additional setup after loading the view, typically from a nib. 19 | self.view.backgroundColor = UIColor(red: 0xf0/255.0, green: 0xf4/255.0, blue: 0xf5/255.0, alpha: 1.0) 20 | } 21 | 22 | // MARK: - user event 23 | @IBAction func onTapStart(sender: AnyObject) { 24 | self.animationView.startSuccess() 25 | } 26 | @IBAction func onTapFail(sender: AnyObject) { 27 | self.animationView.startFail() 28 | } 29 | 30 | } 31 | 32 | --------------------------------------------------------------------------------