From f5133fb899232772b2e0b149a5d42a3b496b8a23 Mon Sep 17 00:00:00 2001 From: leon Date: Thu, 17 Dec 2015 15:34:08 +0800 Subject: [PATCH 1/5] add type of JBWatchActivityIndicatorTypeRingDevide --- .../JBWatchActivityIndicator.h | 4 +++- .../JBWatchActivityIndicator.m | 20 +++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/JBWatchActivityIndicator/JBWatchActivityIndicator.h b/JBWatchActivityIndicator/JBWatchActivityIndicator.h index ada82c3..1c9d06c 100644 --- a/JBWatchActivityIndicator/JBWatchActivityIndicator.h +++ b/JBWatchActivityIndicator/JBWatchActivityIndicator.h @@ -43,7 +43,8 @@ typedef NS_ENUM(NSInteger, JBWatchActivityIndicatorType) { JBWatchActivityIndicatorTypeRingLarge, JBWatchActivityIndicatorTypeSegments, JBWatchActivityIndicatorTypeSegmentsSmall, - JBWatchActivityIndicatorTypeSegmentsLarge + JBWatchActivityIndicatorTypeSegmentsLarge, + JBWatchActivityIndicatorTypeRingDevide }; typedef NS_ENUM(NSInteger, JBWatchActivityIndicatorSegmentStyle) { @@ -63,6 +64,7 @@ typedef NS_ENUM(NSInteger, JBWatchActivityIndicatorSegmentStyle) { @property (nonatomic, readwrite, assign) CGFloat darkestAlpha; @property (nonatomic, readwrite, assign) CGFloat numberOfFrames; @property (nonatomic, readwrite, assign) CGFloat indicatorScale; +@property (nonatomic, readwrite, assign) BOOL isDevideMode; - (instancetype)initWithType:(JBWatchActivityIndicatorType)type NS_DESIGNATED_INITIALIZER; diff --git a/JBWatchActivityIndicator/JBWatchActivityIndicator.m b/JBWatchActivityIndicator/JBWatchActivityIndicator.m index 2ffd10a..b3f95d8 100644 --- a/JBWatchActivityIndicator/JBWatchActivityIndicator.m +++ b/JBWatchActivityIndicator/JBWatchActivityIndicator.m @@ -55,7 +55,8 @@ - (instancetype)initWithType:(JBWatchActivityIndicatorType)type { _brightestAlpha = (254.0f / 255.0f); _darkestAlpha = (57.0f / 255.0f); _numberOfFrames = 15; - + _isDevideMode = NO; + switch (type) { case JBWatchActivityIndicatorTypeDefault: @@ -78,6 +79,9 @@ - (instancetype)initWithType:(JBWatchActivityIndicatorType)type { (type == JBWatchActivityIndicatorTypeDotsSmall ? 0.5f : 2.0f)); break; } + case JBWatchActivityIndicatorTypeRingDevide: + _isDevideMode = YES; + case JBWatchActivityIndicatorTypeRing: case JBWatchActivityIndicatorTypeRingSmall: case JBWatchActivityIndicatorTypeRingLarge: { @@ -153,8 +157,9 @@ - (UIImage *)imageForFrameAtIndex:(NSUInteger)frameIndex { for (NSUInteger segmentIndex = 0; segmentIndex < self.numberOfSegments; segmentIndex++) { - CGFloat alphaAngle = (((CGFloat)(self.numberOfSegments - segmentIndex) / (CGFloat)self.numberOfSegments) * PI2); + CGFloat alphaAngle = (((CGFloat)(self.numberOfSegments - [self alphaIndex:segmentIndex]) / (CGFloat)self.numberOfSegments) * PI2); CGFloat alpha = alphaAxis + (sinf(frameAngle + alphaAngle) * semiAmplitude); + alpha = 1-alpha; if (self.segmentStyle == JBWatchActivityIndicatorSegmentStyleCircle) { @@ -195,4 +200,15 @@ - (UIImage *)imageForFrameAtIndex:(NSUInteger)frameIndex { return image; } +- (NSUInteger)alphaIndex:(NSUInteger)segmentIndex +{ + NSUInteger alphaIndex = segmentIndex; + if (_isDevideMode){ + if (alphaIndex > self.numberOfSegments/2-1){ + alphaIndex -= self.numberOfSegments/2-1; + } + } + return alphaIndex; +} + @end From b8dc89080a61a53be954a7bc0c7a6a1c4d381ef3 Mon Sep 17 00:00:00 2001 From: leonnard Date: Fri, 18 Dec 2015 16:30:49 +0800 Subject: [PATCH 2/5] add a devide ring activity indicator --- .gitignore | 2 +- .../project.pbxproj | 6 ++ JBWatchActivityIndicator/DoubleIndicator.h | 29 ++++++ JBWatchActivityIndicator/DoubleIndicator.m | 96 +++++++++++++++++++ .../JBWatchActivityIndicator.m | 4 +- JBWatchActivityIndicator/ViewController.m | 15 ++- 6 files changed, 146 insertions(+), 6 deletions(-) create mode 100644 JBWatchActivityIndicator/DoubleIndicator.h create mode 100644 JBWatchActivityIndicator/DoubleIndicator.m diff --git a/.gitignore b/.gitignore index d0526e8..3e34740 100644 --- a/.gitignore +++ b/.gitignore @@ -16,7 +16,7 @@ DerivedData *.hmap *.ipa *.xcuserstate - +.DS_Store # CocoaPods # # We recommend against adding the Pods directory to your .gitignore. However diff --git a/JBWatchActivityIndicator.xcodeproj/project.pbxproj b/JBWatchActivityIndicator.xcodeproj/project.pbxproj index 4502f3f..4197cdd 100644 --- a/JBWatchActivityIndicator.xcodeproj/project.pbxproj +++ b/JBWatchActivityIndicator.xcodeproj/project.pbxproj @@ -14,6 +14,7 @@ 090AF1DB1AF666F2008C4028 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 090AF1DA1AF666F2008C4028 /* Images.xcassets */; }; 090AF1EA1AF666F2008C4028 /* JBWatchActivityIndicatorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 090AF1E91AF666F2008C4028 /* JBWatchActivityIndicatorTests.m */; }; 090AF1F51AF6671E008C4028 /* JBWatchActivityIndicator.m in Sources */ = {isa = PBXBuildFile; fileRef = 090AF1F41AF6671E008C4028 /* JBWatchActivityIndicator.m */; }; + 35D3930B1C229DE200E90D80 /* DoubleIndicator.m in Sources */ = {isa = PBXBuildFile; fileRef = 35D3930A1C229DE200E90D80 /* DoubleIndicator.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -42,6 +43,8 @@ 090AF1F31AF6671E008C4028 /* JBWatchActivityIndicator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JBWatchActivityIndicator.h; sourceTree = ""; }; 090AF1F41AF6671E008C4028 /* JBWatchActivityIndicator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JBWatchActivityIndicator.m; sourceTree = ""; }; 09E51B551AF6CC8900CD646E /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; + 35D393091C229DE200E90D80 /* DoubleIndicator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DoubleIndicator.h; sourceTree = ""; }; + 35D3930A1C229DE200E90D80 /* DoubleIndicator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DoubleIndicator.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -90,6 +93,8 @@ 090AF1D51AF666F2008C4028 /* ViewController.m */, 090AF1F31AF6671E008C4028 /* JBWatchActivityIndicator.h */, 090AF1F41AF6671E008C4028 /* JBWatchActivityIndicator.m */, + 35D393091C229DE200E90D80 /* DoubleIndicator.h */, + 35D3930A1C229DE200E90D80 /* DoubleIndicator.m */, 090AF1D71AF666F2008C4028 /* Main.storyboard */, 090AF1DA1AF666F2008C4028 /* Images.xcassets */, 090AF1CD1AF666F2008C4028 /* Supporting Files */, @@ -222,6 +227,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 35D3930B1C229DE200E90D80 /* DoubleIndicator.m in Sources */, 090AF1D61AF666F2008C4028 /* ViewController.m in Sources */, 090AF1D31AF666F2008C4028 /* AppDelegate.m in Sources */, 090AF1F51AF6671E008C4028 /* JBWatchActivityIndicator.m in Sources */, diff --git a/JBWatchActivityIndicator/DoubleIndicator.h b/JBWatchActivityIndicator/DoubleIndicator.h new file mode 100644 index 0000000..d2ec8aa --- /dev/null +++ b/JBWatchActivityIndicator/DoubleIndicator.h @@ -0,0 +1,29 @@ +// +// DoubleIndicator.h +// Wolaidai +// +// Created by leon on 15/12/17. +// Copyright © 2015年 Michael Swanson. All rights reserved. +// + +#import +#import + + +@interface DoubleIndicator : NSObject + +@property (nonatomic, readwrite, assign) NSUInteger numberOfSegments; +@property (nonatomic, readwrite, assign) CGFloat segmentRadius; +@property (nonatomic, readwrite, assign) CGFloat strokeSpacingDegrees; +@property (nonatomic, readwrite, assign) CGFloat indicatorRadius; +@property (nonatomic, readwrite, assign) CGFloat brightestAlpha; +@property (nonatomic, readwrite, assign) CGFloat darkestAlpha; +@property (nonatomic, readwrite, assign) CGFloat numberOfFrames; +@property (nonatomic, readwrite, assign) CGFloat indicatorScale; +@property (nonatomic, readwrite, assign) BOOL isDevideMode; + +- (instancetype)initWithRadius:(CGFloat)radius NS_DESIGNATED_INITIALIZER; + +- (UIImage *)animatedImageWithDuration:(NSTimeInterval)duration; + +@end diff --git a/JBWatchActivityIndicator/DoubleIndicator.m b/JBWatchActivityIndicator/DoubleIndicator.m new file mode 100644 index 0000000..a30a826 --- /dev/null +++ b/JBWatchActivityIndicator/DoubleIndicator.m @@ -0,0 +1,96 @@ +// +// DoubleIndicator.m +// Wolaidai +// +// Created by leon on 15/12/17. +// Copyright © 2015年 Michael Swanson. All rights reserved. +// + +#import "DoubleIndicator.h" +static const double PI2 = M_PI * 2.0; + +@implementation DoubleIndicator + +- (instancetype)init { + return [self initWithRadius:10.f]; +} + +- (instancetype)initWithRadius:(CGFloat)radius { + self = [super init]; + if (self) { + _indicatorRadius = radius; + _brightestAlpha = (254.0f / 255.0f); + _darkestAlpha = (57.0f / 255.0f); + _numberOfFrames = 15; + _isDevideMode = YES; + _numberOfSegments = 120; + _segmentRadius = 1.0f; + _indicatorScale = 2.0f;//1.0f ;//0.5f + + } + return self; +} + +#pragma mark - Methods + +- (UIImage *)animatedImageWithDuration:(NSTimeInterval)duration { + + return [UIImage animatedImageWithImages:[self allImages] duration:duration]; +} + +- (NSArray *)allImages { + + NSMutableArray *images = [NSMutableArray array]; + + for (NSUInteger frameIndex = 0; frameIndex < self.numberOfFrames; frameIndex++) { + + [images addObject:[self imageForFrameAtIndex:frameIndex]]; + } + + return [NSArray arrayWithArray:images]; +} + +- (UIImage *)imageForFrameAtIndex:(NSUInteger)frameIndex { + + // Sizing + CGFloat imageSize = ceilf(((self.indicatorRadius * 2.0f) + (self.segmentRadius * 2.0f)) * self.indicatorScale); + + // Shading + CGFloat semiAmplitude = ((self.brightestAlpha - self.darkestAlpha) * 0.5f); + CGFloat alphaAxis = (self.darkestAlpha + semiAmplitude); + CGFloat frameAngle = (((CGFloat)frameIndex / (CGFloat)self.numberOfFrames) * PI2); + + UIGraphicsBeginImageContextWithOptions(CGSizeMake(imageSize, imageSize), NO, 2.0f); + CGContextRef context = UIGraphicsGetCurrentContext(); + CGContextTranslateCTM(context, (imageSize * 0.5f), (imageSize * 0.5f)); + CGContextScaleCTM(context, self.indicatorScale, self.indicatorScale); + + // Offset by half of a segment + CGFloat angleOffset = (0.5f / (CGFloat)self.numberOfSegments) * PI2; + for (NSUInteger segmentIndex = 0; segmentIndex < self.numberOfSegments; segmentIndex++) { + + NSUInteger alphaIndex = (segmentIndex > self.numberOfSegments/2-1)?(segmentIndex - self.numberOfSegments/2-1):segmentIndex; + CGFloat alphaAngle = (((CGFloat)(self.numberOfSegments - alphaIndex) / (CGFloat)self.numberOfSegments) * PI2); + CGFloat alpha = alphaAxis + (sinf(frameAngle + alphaAngle) * semiAmplitude); + alpha = 1-alpha; + + CGFloat segmentAngle = angleOffset + (((CGFloat)segmentIndex / (CGFloat)self.numberOfSegments) * PI2); + + CGPoint segmentCenter = CGPointMake((self.indicatorRadius * cosf(segmentAngle)), + (self.indicatorRadius * sinf(segmentAngle))); + + UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(segmentCenter.x - self.segmentRadius, + segmentCenter.y - self.segmentRadius, + self.segmentRadius * 2.0f, + self.segmentRadius * 2.0f)]; + + [[UIColor colorWithWhite:1.0f alpha:alpha] setFill]; + [path fill]; + } + + UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + + return image; +} +@end diff --git a/JBWatchActivityIndicator/JBWatchActivityIndicator.m b/JBWatchActivityIndicator/JBWatchActivityIndicator.m index b3f95d8..2e74b43 100644 --- a/JBWatchActivityIndicator/JBWatchActivityIndicator.m +++ b/JBWatchActivityIndicator/JBWatchActivityIndicator.m @@ -55,7 +55,7 @@ - (instancetype)initWithType:(JBWatchActivityIndicatorType)type { _brightestAlpha = (254.0f / 255.0f); _darkestAlpha = (57.0f / 255.0f); _numberOfFrames = 15; - _isDevideMode = NO; + _isDevideMode = YES; switch (type) { @@ -86,7 +86,7 @@ - (instancetype)initWithType:(JBWatchActivityIndicatorType)type { case JBWatchActivityIndicatorTypeRingSmall: case JBWatchActivityIndicatorTypeRingLarge: { - _numberOfSegments = 60; + _numberOfSegments = 160; _segmentRadius = 1.0f; _indicatorScale = (type == JBWatchActivityIndicatorTypeRing ? 1.0f : (type == JBWatchActivityIndicatorTypeRingSmall ? 0.5f : 2.0f)); diff --git a/JBWatchActivityIndicator/ViewController.m b/JBWatchActivityIndicator/ViewController.m index 7a81f90..ffe5a10 100644 --- a/JBWatchActivityIndicator/ViewController.m +++ b/JBWatchActivityIndicator/ViewController.m @@ -8,7 +8,7 @@ #import "ViewController.h" #import "JBWatchActivityIndicator.h" - +#import "DoubleIndicator.h" static NSString * const kDefaultImagePrefix = @"Activity"; @interface ViewController () @@ -37,7 +37,7 @@ @interface ViewController () @property (nonatomic, readwrite, weak) IBOutlet UITextField *imagePrefixTextField; @property (nonatomic, readwrite, weak) IBOutlet UILabel *totalImageBytesLabel; @property (nonatomic, readwrite, strong) JBWatchActivityIndicator *watchActivityIndicator; - +@property (nonatomic, readwrite, strong) DoubleIndicator *doubleIndicator; @end @implementation ViewController @@ -48,7 +48,16 @@ - (void)viewDidLoad { self.totalImageBytesLabel.text = @""; - [self applyType:JBWatchActivityIndicatorTypeDefault]; + //[self applyType:JBWatchActivityIndicatorTypeRingDevide]; + [self testdoubleRing]; +} + +- (void)testdoubleRing +{ + //self.doubleIndicator = [[DoubleIndicator alloc] init]; + //[self update]; + + self.imageView.image = [[[DoubleIndicator alloc] init] animatedImageWithDuration:1.0f]; } - (void)applyType:(JBWatchActivityIndicatorType)type { From ad5311185e5cfad0b3c0de2369dff611658e60de Mon Sep 17 00:00:00 2001 From: leonnard Date: Fri, 18 Dec 2015 16:39:46 +0800 Subject: [PATCH 3/5] add JBWatchActivityIndicatorTypeRingDevide --- .../project.pbxproj | 6 -- JBWatchActivityIndicator/DoubleIndicator.h | 29 ------ JBWatchActivityIndicator/DoubleIndicator.m | 96 ------------------- JBWatchActivityIndicator/ViewController.m | 11 --- 4 files changed, 142 deletions(-) delete mode 100644 JBWatchActivityIndicator/DoubleIndicator.h delete mode 100644 JBWatchActivityIndicator/DoubleIndicator.m diff --git a/JBWatchActivityIndicator.xcodeproj/project.pbxproj b/JBWatchActivityIndicator.xcodeproj/project.pbxproj index 4197cdd..4502f3f 100644 --- a/JBWatchActivityIndicator.xcodeproj/project.pbxproj +++ b/JBWatchActivityIndicator.xcodeproj/project.pbxproj @@ -14,7 +14,6 @@ 090AF1DB1AF666F2008C4028 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 090AF1DA1AF666F2008C4028 /* Images.xcassets */; }; 090AF1EA1AF666F2008C4028 /* JBWatchActivityIndicatorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 090AF1E91AF666F2008C4028 /* JBWatchActivityIndicatorTests.m */; }; 090AF1F51AF6671E008C4028 /* JBWatchActivityIndicator.m in Sources */ = {isa = PBXBuildFile; fileRef = 090AF1F41AF6671E008C4028 /* JBWatchActivityIndicator.m */; }; - 35D3930B1C229DE200E90D80 /* DoubleIndicator.m in Sources */ = {isa = PBXBuildFile; fileRef = 35D3930A1C229DE200E90D80 /* DoubleIndicator.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -43,8 +42,6 @@ 090AF1F31AF6671E008C4028 /* JBWatchActivityIndicator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JBWatchActivityIndicator.h; sourceTree = ""; }; 090AF1F41AF6671E008C4028 /* JBWatchActivityIndicator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JBWatchActivityIndicator.m; sourceTree = ""; }; 09E51B551AF6CC8900CD646E /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; - 35D393091C229DE200E90D80 /* DoubleIndicator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DoubleIndicator.h; sourceTree = ""; }; - 35D3930A1C229DE200E90D80 /* DoubleIndicator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DoubleIndicator.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -93,8 +90,6 @@ 090AF1D51AF666F2008C4028 /* ViewController.m */, 090AF1F31AF6671E008C4028 /* JBWatchActivityIndicator.h */, 090AF1F41AF6671E008C4028 /* JBWatchActivityIndicator.m */, - 35D393091C229DE200E90D80 /* DoubleIndicator.h */, - 35D3930A1C229DE200E90D80 /* DoubleIndicator.m */, 090AF1D71AF666F2008C4028 /* Main.storyboard */, 090AF1DA1AF666F2008C4028 /* Images.xcassets */, 090AF1CD1AF666F2008C4028 /* Supporting Files */, @@ -227,7 +222,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 35D3930B1C229DE200E90D80 /* DoubleIndicator.m in Sources */, 090AF1D61AF666F2008C4028 /* ViewController.m in Sources */, 090AF1D31AF666F2008C4028 /* AppDelegate.m in Sources */, 090AF1F51AF6671E008C4028 /* JBWatchActivityIndicator.m in Sources */, diff --git a/JBWatchActivityIndicator/DoubleIndicator.h b/JBWatchActivityIndicator/DoubleIndicator.h deleted file mode 100644 index d2ec8aa..0000000 --- a/JBWatchActivityIndicator/DoubleIndicator.h +++ /dev/null @@ -1,29 +0,0 @@ -// -// DoubleIndicator.h -// Wolaidai -// -// Created by leon on 15/12/17. -// Copyright © 2015年 Michael Swanson. All rights reserved. -// - -#import -#import - - -@interface DoubleIndicator : NSObject - -@property (nonatomic, readwrite, assign) NSUInteger numberOfSegments; -@property (nonatomic, readwrite, assign) CGFloat segmentRadius; -@property (nonatomic, readwrite, assign) CGFloat strokeSpacingDegrees; -@property (nonatomic, readwrite, assign) CGFloat indicatorRadius; -@property (nonatomic, readwrite, assign) CGFloat brightestAlpha; -@property (nonatomic, readwrite, assign) CGFloat darkestAlpha; -@property (nonatomic, readwrite, assign) CGFloat numberOfFrames; -@property (nonatomic, readwrite, assign) CGFloat indicatorScale; -@property (nonatomic, readwrite, assign) BOOL isDevideMode; - -- (instancetype)initWithRadius:(CGFloat)radius NS_DESIGNATED_INITIALIZER; - -- (UIImage *)animatedImageWithDuration:(NSTimeInterval)duration; - -@end diff --git a/JBWatchActivityIndicator/DoubleIndicator.m b/JBWatchActivityIndicator/DoubleIndicator.m deleted file mode 100644 index a30a826..0000000 --- a/JBWatchActivityIndicator/DoubleIndicator.m +++ /dev/null @@ -1,96 +0,0 @@ -// -// DoubleIndicator.m -// Wolaidai -// -// Created by leon on 15/12/17. -// Copyright © 2015年 Michael Swanson. All rights reserved. -// - -#import "DoubleIndicator.h" -static const double PI2 = M_PI * 2.0; - -@implementation DoubleIndicator - -- (instancetype)init { - return [self initWithRadius:10.f]; -} - -- (instancetype)initWithRadius:(CGFloat)radius { - self = [super init]; - if (self) { - _indicatorRadius = radius; - _brightestAlpha = (254.0f / 255.0f); - _darkestAlpha = (57.0f / 255.0f); - _numberOfFrames = 15; - _isDevideMode = YES; - _numberOfSegments = 120; - _segmentRadius = 1.0f; - _indicatorScale = 2.0f;//1.0f ;//0.5f - - } - return self; -} - -#pragma mark - Methods - -- (UIImage *)animatedImageWithDuration:(NSTimeInterval)duration { - - return [UIImage animatedImageWithImages:[self allImages] duration:duration]; -} - -- (NSArray *)allImages { - - NSMutableArray *images = [NSMutableArray array]; - - for (NSUInteger frameIndex = 0; frameIndex < self.numberOfFrames; frameIndex++) { - - [images addObject:[self imageForFrameAtIndex:frameIndex]]; - } - - return [NSArray arrayWithArray:images]; -} - -- (UIImage *)imageForFrameAtIndex:(NSUInteger)frameIndex { - - // Sizing - CGFloat imageSize = ceilf(((self.indicatorRadius * 2.0f) + (self.segmentRadius * 2.0f)) * self.indicatorScale); - - // Shading - CGFloat semiAmplitude = ((self.brightestAlpha - self.darkestAlpha) * 0.5f); - CGFloat alphaAxis = (self.darkestAlpha + semiAmplitude); - CGFloat frameAngle = (((CGFloat)frameIndex / (CGFloat)self.numberOfFrames) * PI2); - - UIGraphicsBeginImageContextWithOptions(CGSizeMake(imageSize, imageSize), NO, 2.0f); - CGContextRef context = UIGraphicsGetCurrentContext(); - CGContextTranslateCTM(context, (imageSize * 0.5f), (imageSize * 0.5f)); - CGContextScaleCTM(context, self.indicatorScale, self.indicatorScale); - - // Offset by half of a segment - CGFloat angleOffset = (0.5f / (CGFloat)self.numberOfSegments) * PI2; - for (NSUInteger segmentIndex = 0; segmentIndex < self.numberOfSegments; segmentIndex++) { - - NSUInteger alphaIndex = (segmentIndex > self.numberOfSegments/2-1)?(segmentIndex - self.numberOfSegments/2-1):segmentIndex; - CGFloat alphaAngle = (((CGFloat)(self.numberOfSegments - alphaIndex) / (CGFloat)self.numberOfSegments) * PI2); - CGFloat alpha = alphaAxis + (sinf(frameAngle + alphaAngle) * semiAmplitude); - alpha = 1-alpha; - - CGFloat segmentAngle = angleOffset + (((CGFloat)segmentIndex / (CGFloat)self.numberOfSegments) * PI2); - - CGPoint segmentCenter = CGPointMake((self.indicatorRadius * cosf(segmentAngle)), - (self.indicatorRadius * sinf(segmentAngle))); - - UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(segmentCenter.x - self.segmentRadius, - segmentCenter.y - self.segmentRadius, - self.segmentRadius * 2.0f, - self.segmentRadius * 2.0f)]; - - [[UIColor colorWithWhite:1.0f alpha:alpha] setFill]; - [path fill]; - } - - UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); - UIGraphicsEndImageContext(); - - return image; -} -@end diff --git a/JBWatchActivityIndicator/ViewController.m b/JBWatchActivityIndicator/ViewController.m index ffe5a10..78c1bfa 100644 --- a/JBWatchActivityIndicator/ViewController.m +++ b/JBWatchActivityIndicator/ViewController.m @@ -8,7 +8,6 @@ #import "ViewController.h" #import "JBWatchActivityIndicator.h" -#import "DoubleIndicator.h" static NSString * const kDefaultImagePrefix = @"Activity"; @interface ViewController () @@ -37,7 +36,6 @@ @interface ViewController () @property (nonatomic, readwrite, weak) IBOutlet UITextField *imagePrefixTextField; @property (nonatomic, readwrite, weak) IBOutlet UILabel *totalImageBytesLabel; @property (nonatomic, readwrite, strong) JBWatchActivityIndicator *watchActivityIndicator; -@property (nonatomic, readwrite, strong) DoubleIndicator *doubleIndicator; @end @implementation ViewController @@ -49,15 +47,6 @@ - (void)viewDidLoad { self.totalImageBytesLabel.text = @""; //[self applyType:JBWatchActivityIndicatorTypeRingDevide]; - [self testdoubleRing]; -} - -- (void)testdoubleRing -{ - //self.doubleIndicator = [[DoubleIndicator alloc] init]; - //[self update]; - - self.imageView.image = [[[DoubleIndicator alloc] init] animatedImageWithDuration:1.0f]; } - (void)applyType:(JBWatchActivityIndicatorType)type { From d596964fa4736b6d03913cb0cb9a9fdb1cd4c734 Mon Sep 17 00:00:00 2001 From: leonnard Date: Fri, 18 Dec 2015 16:45:02 +0800 Subject: [PATCH 4/5] remove changes --- JBWatchActivityIndicator/JBWatchActivityIndicator.m | 2 +- JBWatchActivityIndicator/ViewController.m | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/JBWatchActivityIndicator/JBWatchActivityIndicator.m b/JBWatchActivityIndicator/JBWatchActivityIndicator.m index 2e74b43..ce35652 100644 --- a/JBWatchActivityIndicator/JBWatchActivityIndicator.m +++ b/JBWatchActivityIndicator/JBWatchActivityIndicator.m @@ -86,7 +86,7 @@ - (instancetype)initWithType:(JBWatchActivityIndicatorType)type { case JBWatchActivityIndicatorTypeRingSmall: case JBWatchActivityIndicatorTypeRingLarge: { - _numberOfSegments = 160; + _numberOfSegments = 60; _segmentRadius = 1.0f; _indicatorScale = (type == JBWatchActivityIndicatorTypeRing ? 1.0f : (type == JBWatchActivityIndicatorTypeRingSmall ? 0.5f : 2.0f)); diff --git a/JBWatchActivityIndicator/ViewController.m b/JBWatchActivityIndicator/ViewController.m index 78c1bfa..34dc44b 100644 --- a/JBWatchActivityIndicator/ViewController.m +++ b/JBWatchActivityIndicator/ViewController.m @@ -8,6 +8,7 @@ #import "ViewController.h" #import "JBWatchActivityIndicator.h" + static NSString * const kDefaultImagePrefix = @"Activity"; @interface ViewController () @@ -36,6 +37,7 @@ @interface ViewController () @property (nonatomic, readwrite, weak) IBOutlet UITextField *imagePrefixTextField; @property (nonatomic, readwrite, weak) IBOutlet UILabel *totalImageBytesLabel; @property (nonatomic, readwrite, strong) JBWatchActivityIndicator *watchActivityIndicator; + @end @implementation ViewController @@ -45,7 +47,8 @@ - (void)viewDidLoad { [super viewDidLoad]; self.totalImageBytesLabel.text = @""; - + + [self applyType:JBWatchActivityIndicatorTypeDefault]; //[self applyType:JBWatchActivityIndicatorTypeRingDevide]; } From 52976d8a472121116bf1ba8dca9feff630802792 Mon Sep 17 00:00:00 2001 From: leonnard Date: Fri, 18 Dec 2015 16:51:09 +0800 Subject: [PATCH 5/5] init DevideMode to NO --- JBWatchActivityIndicator/JBWatchActivityIndicator.m | 2 +- JBWatchActivityIndicator/ViewController.m | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/JBWatchActivityIndicator/JBWatchActivityIndicator.m b/JBWatchActivityIndicator/JBWatchActivityIndicator.m index ce35652..b3f95d8 100644 --- a/JBWatchActivityIndicator/JBWatchActivityIndicator.m +++ b/JBWatchActivityIndicator/JBWatchActivityIndicator.m @@ -55,7 +55,7 @@ - (instancetype)initWithType:(JBWatchActivityIndicatorType)type { _brightestAlpha = (254.0f / 255.0f); _darkestAlpha = (57.0f / 255.0f); _numberOfFrames = 15; - _isDevideMode = YES; + _isDevideMode = NO; switch (type) { diff --git a/JBWatchActivityIndicator/ViewController.m b/JBWatchActivityIndicator/ViewController.m index 34dc44b..255daf9 100644 --- a/JBWatchActivityIndicator/ViewController.m +++ b/JBWatchActivityIndicator/ViewController.m @@ -48,8 +48,8 @@ - (void)viewDidLoad { self.totalImageBytesLabel.text = @""; - [self applyType:JBWatchActivityIndicatorTypeDefault]; - //[self applyType:JBWatchActivityIndicatorTypeRingDevide]; + //[self applyType:JBWatchActivityIndicatorTypeDefault]; + [self applyType:JBWatchActivityIndicatorTypeRingDevide]; } - (void)applyType:(JBWatchActivityIndicatorType)type {