From 7e49a0feeeef46907dc8176d077790916fe72e22 Mon Sep 17 00:00:00 2001 From: zer0 Date: Fri, 21 Aug 2015 11:57:35 +0800 Subject: [PATCH] =?UTF-8?q?add=20navigationTranslucent=20property=E2=80=A8?= =?UTF-8?q?fix=20bugs=20when=20navigationbar.translucent=20is=20NO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CBStoreHouseRefreshControl/ContentViewController.m | 3 ++- Class/CBStoreHouseRefreshControl.h | 6 ++++-- Class/CBStoreHouseRefreshControl.m | 11 ++++++++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CBStoreHouseRefreshControl/ContentViewController.m b/CBStoreHouseRefreshControl/ContentViewController.m index dced6ad..2463ad6 100644 --- a/CBStoreHouseRefreshControl/ContentViewController.m +++ b/CBStoreHouseRefreshControl/ContentViewController.m @@ -23,6 +23,7 @@ - (void)viewDidLoad { self.navigationController.navigationBar.barTintColor = [UIColor colorWithWhite:0.1 alpha:1]; self.navigationController.navigationBar.tintColor = [UIColor whiteColor]; self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]}; + self.navigationController.navigationBar.translucent = NO; self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg_pattern"]]; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; @@ -35,7 +36,7 @@ - (void)viewDidLoad { self.tableView.tableFooterView = footer; // Let the show begins - self.storeHouseRefreshControl = [CBStoreHouseRefreshControl attachToScrollView:self.tableView target:self refreshAction:@selector(refreshTriggered:) plist:@"storehouse" color:[UIColor whiteColor] lineWidth:1.5 dropHeight:80 scale:1 horizontalRandomness:150 reverseLoadingAnimation:YES internalAnimationFactor:0.5]; + self.storeHouseRefreshControl = [CBStoreHouseRefreshControl attachToScrollView:self.tableView target:self refreshAction:@selector(refreshTriggered:) plist:@"storehouse" color:[UIColor whiteColor] lineWidth:1.5 dropHeight:80 scale:1 horizontalRandomness:150 reverseLoadingAnimation:YES internalAnimationFactor:0.5 navigationTranslucent:self.navigationController.navigationBar.translucent]; //self.storeHouseRefreshControl = [CBStoreHouseRefreshControl attachToScrollView:self.tableView target:self refreshAction:@selector(refreshTriggered:) plist:@"AKTA" color:[UIColor whiteColor] lineWidth:2 dropHeight:80 scale:0.7 horizontalRandomness:300 reverseLoadingAnimation:NO internalAnimationFactor:0.7]; } diff --git a/Class/CBStoreHouseRefreshControl.h b/Class/CBStoreHouseRefreshControl.h index 01692c9..90c1734 100644 --- a/Class/CBStoreHouseRefreshControl.h +++ b/Class/CBStoreHouseRefreshControl.h @@ -13,7 +13,8 @@ + (CBStoreHouseRefreshControl*)attachToScrollView:(UIScrollView *)scrollView target:(id)target refreshAction:(SEL)refreshAction - plist:(NSString *)plist; + plist:(NSString *)plist + navigationTranslucent:(BOOL)navigationTranslucent; + (CBStoreHouseRefreshControl*)attachToScrollView:(UIScrollView *)scrollView target:(id)target @@ -25,7 +26,8 @@ scale:(CGFloat)scale horizontalRandomness:(CGFloat)horizontalRandomness reverseLoadingAnimation:(BOOL)reverseLoadingAnimation - internalAnimationFactor:(CGFloat)internalAnimationFactor; + internalAnimationFactor:(CGFloat)internalAnimationFactor + navigationTranslucent:(BOOL)navigationTranslucent; - (void)scrollViewDidScroll; diff --git a/Class/CBStoreHouseRefreshControl.m b/Class/CBStoreHouseRefreshControl.m index 9a32d13..ef951a6 100644 --- a/Class/CBStoreHouseRefreshControl.m +++ b/Class/CBStoreHouseRefreshControl.m @@ -41,6 +41,7 @@ @interface CBStoreHouseRefreshControl () @property (nonatomic) CGFloat internalAnimationFactor; @property (nonatomic) int horizontalRandomness; @property (nonatomic) BOOL reverseLoadingAnimation; +@property (nonatomic) BOOL navigationTranslucent; @end @@ -50,6 +51,7 @@ + (CBStoreHouseRefreshControl*)attachToScrollView:(UIScrollView *)scrollView target:(id)target refreshAction:(SEL)refreshAction plist:(NSString *)plist + navigationTranslucent:(BOOL)navigationTranslucent { return [CBStoreHouseRefreshControl attachToScrollView:scrollView target:target @@ -61,7 +63,8 @@ + (CBStoreHouseRefreshControl*)attachToScrollView:(UIScrollView *)scrollView scale:1 horizontalRandomness:150 reverseLoadingAnimation:NO - internalAnimationFactor:0.7]; + internalAnimationFactor:0.7 + navigationTranslucent:navigationTranslucent]; } + (CBStoreHouseRefreshControl*)attachToScrollView:(UIScrollView *)scrollView @@ -75,6 +78,7 @@ + (CBStoreHouseRefreshControl*)attachToScrollView:(UIScrollView *)scrollView horizontalRandomness:(CGFloat)horizontalRandomness reverseLoadingAnimation:(BOOL)reverseLoadingAnimation internalAnimationFactor:(CGFloat)internalAnimationFactor + navigationTranslucent:(BOOL)navigationTranslucent { CBStoreHouseRefreshControl *refreshControl = [[CBStoreHouseRefreshControl alloc] init]; refreshControl.dropHeight = dropHeight; @@ -84,6 +88,7 @@ + (CBStoreHouseRefreshControl*)attachToScrollView:(UIScrollView *)scrollView refreshControl.action = refreshAction; refreshControl.reverseLoadingAnimation = reverseLoadingAnimation; refreshControl.internalAnimationFactor = internalAnimationFactor; + refreshControl.navigationTranslucent = navigationTranslucent; [scrollView addSubview:refreshControl]; // Calculate frame according to points max width and height @@ -136,7 +141,7 @@ + (CBStoreHouseRefreshControl*)attachToScrollView:(UIScrollView *)scrollView - (void)scrollViewDidScroll { - if (self.originalTopContentInset == 0) self.originalTopContentInset = self.scrollView.contentInset.top; + if (self.originalTopContentInset == 0 && _navigationTranslucent) self.originalTopContentInset = self.scrollView.contentInset.top; self.center = CGPointMake([UIScreen mainScreen].bounds.size.width/2, self.realContentOffsetY*krelativeHeightFactor); if (self.state == CBStoreHouseRefreshControlStateIdle) [self updateBarItemsWithProgress:self.animationProgress]; @@ -267,7 +272,7 @@ - (void)finishingLoading { self.state = CBStoreHouseRefreshControlStateDisappearing; UIEdgeInsets newInsets = self.scrollView.contentInset; - newInsets.top = self.originalTopContentInset; + newInsets.top = self.originalTopContentInset * _navigationTranslucent; [UIView animateWithDuration:kdisappearDuration animations:^(void) { self.scrollView.contentInset = newInsets; } completion:^(BOOL finished) {