From 42e3b01f95059622dda081acfa66aa9b2967f005 Mon Sep 17 00:00:00 2001 From: gia Date: Wed, 19 Nov 2014 10:40:09 +0700 Subject: [PATCH 1/2] fix a bug cause when scrollview with content inset top 0 will cause the refresh control to use the inset after the animation init to set as the original content inset. --- CBStoreHouseRefreshControl/ContentViewController.m | 2 +- Class/CBStoreHouseRefreshControl.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CBStoreHouseRefreshControl/ContentViewController.m b/CBStoreHouseRefreshControl/ContentViewController.m index dced6ad..7394023 100644 --- a/CBStoreHouseRefreshControl/ContentViewController.m +++ b/CBStoreHouseRefreshControl/ContentViewController.m @@ -17,7 +17,7 @@ @implementation ContentViewController - (void)viewDidLoad { [super viewDidLoad]; - +// self.edgesForExtendedLayout = UIRectEdgeNone; self.title = @"Storehouse"; self.navigationController.navigationBar.barStyle = UIBarStyleBlack; self.navigationController.navigationBar.barTintColor = [UIColor colorWithWhite:0.1 alpha:1]; diff --git a/Class/CBStoreHouseRefreshControl.m b/Class/CBStoreHouseRefreshControl.m index f77dcf6..faa1a04 100644 --- a/Class/CBStoreHouseRefreshControl.m +++ b/Class/CBStoreHouseRefreshControl.m @@ -136,9 +136,9 @@ + (CBStoreHouseRefreshControl*)attachToScrollView:(UIScrollView *)scrollView - (void)scrollViewDidScroll { - if (self.originalTopContentInset == 0) self.originalTopContentInset = self.scrollView.contentInset.top; self.center = CGPointMake([UIScreen mainScreen].bounds.size.width/2, self.realContentOffsetY*krelativeHeightFactor); if (self.state == CBStoreHouseRefreshControlStateIdle) + self.originalTopContentInset = self.scrollView.contentInset.top; [self updateBarItemsWithProgress:self.animationProgress]; } From e34f2542589d77c4386b4035aea7107b468d7eb1 Mon Sep 17 00:00:00 2001 From: gia Date: Wed, 19 Nov 2014 13:53:26 +0700 Subject: [PATCH 2/2] respect line width when create bar item by shift the x, y half of line width, to prevent it from clipping --- Class/CBStoreHouseRefreshControl.m | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Class/CBStoreHouseRefreshControl.m b/Class/CBStoreHouseRefreshControl.m index f77dcf6..6101f59 100644 --- a/Class/CBStoreHouseRefreshControl.m +++ b/Class/CBStoreHouseRefreshControl.m @@ -97,10 +97,11 @@ + (CBStoreHouseRefreshControl*)attachToScrollView:(UIScrollView *)scrollView CGPoint startPoint = CGPointFromString(startPoints[i]); CGPoint endPoint = CGPointFromString(endPoints[i]); - if (startPoint.x > width) width = startPoint.x; - if (endPoint.x > width) width = endPoint.x; - if (startPoint.y > height) height = startPoint.y; - if (endPoint.y > height) height = endPoint.y; + // shift it base on line width + if (startPoint.x + lineWidth > width) width = startPoint.x + lineWidth; + if (endPoint.x + lineWidth > width) width = endPoint.x + lineWidth; + if (startPoint.y + lineWidth > height) height = startPoint.y + lineWidth; + if (endPoint.y + lineWidth > height) height = endPoint.y + lineWidth; } refreshControl.frame = CGRectMake(0, 0, width, height); @@ -110,6 +111,9 @@ + (CBStoreHouseRefreshControl*)attachToScrollView:(UIScrollView *)scrollView CGPoint startPoint = CGPointFromString(startPoints[i]); CGPoint endPoint = CGPointFromString(endPoints[i]); + // shift it base on line width + startPoint = CGPointMake(startPoint.x + lineWidth/2, startPoint.y + lineWidth/2); + endPoint = CGPointMake(endPoint.x + lineWidth/2, endPoint.y + lineWidth/2); BarItem *barItem = [[BarItem alloc] initWithFrame:refreshControl.frame startPoint:startPoint endPoint:endPoint color:color lineWidth:lineWidth]; barItem.tag = i;