Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- Fixed issue #6 and incorrectly positioned gooey circle bug when background dots has greater diameter. #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
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