Skip to content

Commit

Permalink
- Fixed issue KittenYang#6.
Browse files Browse the repository at this point in the history
- Fixed a bug where gooey circle indicator won't correctly position itself when background dots(from line) has greater diameter than itself.
  • Loading branch information
langyufei committed May 5, 2016
1 parent 79960a4 commit f540821
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
14 changes: 14 additions & 0 deletions KYAnimatedPageControl-Demo/Classes/GooeyCircle.m
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@ - (void)animateIndicatorWithScrollView:(UIScrollView *)scrollView
1, MAX(0, (ABS(scrollView.contentOffset.x - self.lastContentOffset) /
scrollView.frame.size.width)));
}

// get scroll view's position as in percentage
CGFloat position = scrollView.contentOffset.x / (scrollView.contentSize.width * (pgctl.pageCount - 1) / pgctl.pageCount);
CGFloat inset = pgctl.pageControlLine.ballDiameter > self.indicatorSize ? pgctl.pageControlLine.ballDiameter : self.indicatorSize;
CGFloat orginalX = 0; // at or moving towards to the first dot
if (position >= 1.0f) { // at or moving towards to the last dot
orginalX = pgctl.frame.size.width - inset;
} else if (position > 0.0f) { // middle dots
orginalX = (pgctl.frame.size.width - inset) * position;
}
self.currentRect = CGRectMake(orginalX, self.frame.size.height / 2 - self.indicatorSize / 2,
self.indicatorSize, self.indicatorSize);
/*
CGFloat originX = (scrollView.contentOffset.x / scrollView.frame.size.width) *
(pgctl.frame.size.width / (pgctl.pageCount - 1));
if (originX - self.indicatorSize / 2 <= 0) {
Expand All @@ -134,6 +147,7 @@ - (void)animateIndicatorWithScrollView:(UIScrollView *)scrollView
self.frame.size.height / 2 - self.indicatorSize / 2,
self.indicatorSize, self.indicatorSize);
}
*/
[self setNeedsDisplay];
}

Expand Down
12 changes: 9 additions & 3 deletions KYAnimatedPageControl-Demo/Classes/KYAnimatedPageControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ - (void)willMoveToSuperview:(UIView *)newSuperview {
- (Line *)line {
if (!_line) {
_line = [Line layer];
// in case background ball is begger than foreground shape
CGFloat inset = self.line.ballDiameter > self.indicatorSize ? 0 : self.indicatorSize / 2 - self.line.ballDiameter / 2;
_line.frame =
CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
CGRectMake(inset, 0, self.frame.size.width - (inset * 2), self.frame.size.height);
_line.pageCount = self.pageCount;
_line.selectedPage = 1;
_line.shouldShowProgressLine = self.shouldShowProgressLine;
Expand All @@ -69,8 +71,10 @@ - (GooeyCircle *)gooeyCircle {
if (!_gooeyCircle) {
_gooeyCircle = [GooeyCircle layer];
_gooeyCircle.indicatorColor = self.selectedColor;
// in case background ball is begger than foreground ball
CGFloat inset = self.line.ballDiameter > self.indicatorSize ? (self.line.ballDiameter / 2 - self.indicatorSize / 2) : 0;
_gooeyCircle.frame =
CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
CGRectMake(inset, 0, self.frame.size.width - (inset * 2), self.frame.size.height);
_gooeyCircle.indicatorSize = self.indicatorSize;
_gooeyCircle.contentsScale = [UIScreen mainScreen].scale;
}
Expand All @@ -82,8 +86,10 @@ - (RotateRect *)rotateRect {
if (!_rotateRect) {
_rotateRect = [RotateRect layer];
_rotateRect.indicatorColor = self.selectedColor;
// in case background ball is begger than foreground shape
CGFloat inset = self.line.ballDiameter > self.indicatorSize ? (self.line.ballDiameter / 2 - self.indicatorSize / 2) : 0;
_rotateRect.frame =
CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
CGRectMake(inset, 0, self.frame.size.width - (inset * 2), self.frame.size.height);
_rotateRect.indicatorSize = self.indicatorSize;
_rotateRect.contentsScale = [UIScreen mainScreen].scale;
}
Expand Down

0 comments on commit f540821

Please sign in to comment.