Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DACircularProgress/DACircularProgressView.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@property(nonatomic) CGFloat thicknessRatio UI_APPEARANCE_SELECTOR;
@property(nonatomic) NSInteger clockwiseProgress UI_APPEARANCE_SELECTOR; // Can not use BOOL with UI_APPEARANCE_SELECTOR :-(
@property(nonatomic) CGFloat progress;

@property(nonatomic) CGFloat proStart;//Where to Start the Circle
@property(nonatomic) CGFloat indeterminateDuration UI_APPEARANCE_SELECTOR;
@property(nonatomic) NSInteger indeterminate UI_APPEARANCE_SELECTOR; // Can not use BOOL with UI_APPEARANCE_SELECTOR :-(

Expand All @@ -26,3 +26,4 @@
- (void)setProgress:(CGFloat)progress animated:(BOOL)animated initialDelay:(CFTimeInterval)initialDelay withDuration:(CFTimeInterval)duration;

@end

21 changes: 17 additions & 4 deletions DACircularProgress/DACircularProgressView.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ @interface DACircularProgressLayer : CALayer
@property(nonatomic) CGFloat thicknessRatio;
@property(nonatomic) CGFloat progress;
@property(nonatomic) NSInteger clockwiseProgress;

@property(nonatomic) CGFloat proStart;
@end

@implementation DACircularProgressLayer
Expand All @@ -31,6 +31,7 @@ @implementation DACircularProgressLayer
@dynamic thicknessRatio;
@dynamic progress;
@dynamic clockwiseProgress;
@dynamic proStart;

+ (BOOL)needsDisplayForKey:(NSString *)key
{
Expand All @@ -43,18 +44,21 @@ + (BOOL)needsDisplayForKey:(NSString *)key

- (void)drawInContext:(CGContextRef)context
{

CGRect rect = self.bounds;
CGPoint centerPoint = CGPointMake(rect.size.width / 2.0f, rect.size.height / 2.0f);
CGFloat radius = MIN(rect.size.height, rect.size.width) / 2.0f;

BOOL clockwise = (self.clockwiseProgress != 0);

CGFloat progress = MIN(self.progress, 1.0f - FLT_EPSILON);
CGFloat proStart = self.proStart ? self.proStart : 3.0f *M_PI_2;

CGFloat radians = 0;
if (clockwise) {
radians = (float)((progress * 2.0f * M_PI) - M_PI_2);
radians = (float)((progress * 2.0f * M_PI) - (2.0f*M_PI - self.proStart));
} else {
radians = (float)(3 * M_PI_2 - (progress * 2.0f * M_PI));
radians = (float)(proStart - (progress * 2.0f * M_PI)); //修改的地方 (progress * 2.0f * M_PI 起始位置
}

CGContextSetFillColorWithColor(context, self.trackTintColor.CGColor);
Expand All @@ -70,7 +74,7 @@ - (void)drawInContext:(CGContextRef)context
CGContextSetFillColorWithColor(context, self.progressTintColor.CGColor);
CGMutablePathRef progressPath = CGPathCreateMutable();
CGPathMoveToPoint(progressPath, NULL, centerPoint.x, centerPoint.y);
CGPathAddArc(progressPath, NULL, centerPoint.x, centerPoint.y, radius, (float)(3.0f * M_PI_2), radians, !clockwise);
CGPathAddArc(progressPath, NULL, centerPoint.x, centerPoint.y, radius, (float)proStart, radians, !clockwise); //修改画园的起始位置
CGPathCloseSubpath(progressPath);
CGContextAddPath(context, progressPath);
CGContextFillPath(context);
Expand Down Expand Up @@ -287,6 +291,15 @@ - (void)setThicknessRatio:(CGFloat)thicknessRatio
[self.circularProgressLayer setNeedsDisplay];
}

-(CGFloat)proStart{
return self.circularProgressLayer.proStart;
}

-(void)setProStart:(CGFloat)proStart{
self.circularProgressLayer.proStart = proStart;
[self.circularProgressLayer setNeedsDisplay];
}

- (NSInteger)indeterminate
{
CAAnimation *spinAnimation = [self.layer animationForKey:@"indeterminateAnimation"];
Expand Down