From 790355a6c6ce2d8254ea0116feea5ea76e42df93 Mon Sep 17 00:00:00 2001 From: Mazyad Alabduljaleel Date: Fri, 4 Jul 2014 12:19:12 +0400 Subject: [PATCH] Reverse the last commits, gonna work on them in develop branch --- TLYShyNavBar/TLYShyNavBarManager.m | 135 +++--------------- TLYShyNavBar/TLYShyViewController.h | 3 - TLYShyNavBar/TLYShyViewController.m | 3 + .../project.pbxproj | 2 +- .../Base.lproj/Main.storyboard | 8 +- .../TLYShyNavBarDemo/TLYViewController.m | 8 +- 6 files changed, 36 insertions(+), 123 deletions(-) diff --git a/TLYShyNavBar/TLYShyNavBarManager.m b/TLYShyNavBar/TLYShyNavBarManager.m index 04939dd..a06de6a 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.m +++ b/TLYShyNavBar/TLYShyNavBarManager.m @@ -26,21 +26,6 @@ static inline CGFloat AACStatusBarHeight() return MIN(statusBarSize.width, statusBarSize.height); } -#pragma mark - UINavigationController Category interface - -/* CATEGORY DESCRIPTION: - * ===================== - * We set the navigation bar to hidden in TLYShyNavBarManager, - * but then we need to restore it in the next view controller. We - * use this category to add a flag if it was us whom hid the navbar. - */ - -@interface UINavigationController (TLYShyNavBar) - -@property (nonatomic) BOOL didShyNavBarManagerHideNavBar; - -@end - #pragma mark - TLYShyNavBarManager class @interface TLYShyNavBarManager () @@ -51,7 +36,6 @@ static inline CGFloat AACStatusBarHeight() @property (nonatomic, strong) TLYDelegateProxy *delegateProxy; @property (nonatomic, strong) UIView *extensionViewContainer; -@property (nonatomic, weak) UIView *statusBarBackgroundView; @property (nonatomic) UIEdgeInsets previousScrollInsets; @property (nonatomic) CGFloat previousYOffset; @@ -75,12 +59,13 @@ static inline CGFloat AACStatusBarHeight() self.delegateProxy = [[TLYDelegateProxy alloc] initWithMiddleMan:self]; self.contracting = NO; - self.previousContractionState = NO; + self.previousContractionState = YES; self.expansionResistance = 200.f; self.contractionResistance = 0.f; - [self _resetCacheVariables]; + self.previousScrollInsets = UIEdgeInsetsZero; + self.previousYOffset = NAN; self.navBarController = [[TLYShyViewController alloc] init]; self.navBarController.hidesSubviews = YES; @@ -167,56 +152,6 @@ static inline CGFloat AACStatusBarHeight() #pragma mark - Private methods -- (void)_resetCacheVariables -{ - self.previousYOffset = NAN; - self.previousScrollInsets = UIEdgeInsetsZero; - self.resistanceConsumed = 0; -} - -- (void)_viewWillAppear -{ - [self _resetCacheVariables]; - self.viewControllerVisible = YES; - - UINavigationController *navController = self.viewController.navigationController; - if (navController.isNavigationBarHidden) - { - [navController setNavigationBarHidden:NO animated:NO]; - } -} - -- (void)_viewWillDisappear -{ - if (self.isContracting) - { - UINavigationController *navController = self.viewController.navigationController; - [navController setNavigationBarHidden:YES animated:YES]; - navController.didShyNavBarManagerHideNavBar = YES; - - UIView *snapshotView = [self.viewController.view.window snapshotViewAfterScreenUpdates:NO]; - - CGRect clippingFrame = snapshotView.frame; - clippingFrame.size.height = AACStatusBarHeight(); - - UIView *clippingView = [[UIView alloc] initWithFrame:clippingFrame]; - clippingView.backgroundColor = [UIColor clearColor]; - clippingView.clipsToBounds = YES; - - [clippingView addSubview:snapshotView]; - [self.viewController.view addSubview:clippingView]; - - self.statusBarBackgroundView = clippingView; - } - - self.viewControllerVisible = NO; -} - -- (void)_viewDidDisappear -{ - [self.statusBarBackgroundView removeFromSuperview]; -} - - (void)_handleScrolling { if (!self.isViewControllerVisible) @@ -237,8 +172,7 @@ static inline CGFloat AACStatusBarHeight() } /* rounding to resolve a dumb issue with the contentOffset value */ - CGFloat maxContentOffset = self.scrollView.contentSize.height - CGRectGetHeight(self.scrollView.bounds); - CGFloat end = floorf(maxContentOffset + self.scrollView.contentInset.bottom - 0.5f); + CGFloat end = floorf(self.scrollView.contentSize.height - CGRectGetHeight(self.scrollView.bounds) + self.scrollView.contentInset.bottom - 0.5f); if (self.previousYOffset > end) { deltaY = MAX(0, deltaY - self.previousYOffset + end); @@ -289,10 +223,9 @@ static inline CGFloat AACStatusBarHeight() self.resistanceConsumed = 0; - CGFloat deltaY = [self.navBarController snap:self.isContracting]; - self.contracting = self.navBarController.isContracted; - + CGFloat deltaY = deltaY = [self.navBarController snap:self.isContracting]; CGPoint newContentOffset = self.scrollView.contentOffset; + newContentOffset.y -= deltaY; [UIView animateWithDuration:0.2 @@ -325,6 +258,12 @@ static inline CGFloat AACStatusBarHeight() } } +- (void)prepareForDisplay +{ + [self cleanup]; + self.viewControllerVisible = YES; +} + - (void)layoutViews { UIEdgeInsets scrollInsets = self.scrollView.contentInset; @@ -344,6 +283,15 @@ static inline CGFloat AACStatusBarHeight() self.scrollView.scrollIndicatorInsets = scrollInsets; } +- (void)cleanup +{ + [self.navBarController expand]; + + self.viewControllerVisible = NO; + self.previousYOffset = NAN; + self.previousScrollInsets = UIEdgeInsetsZero; +} + #pragma mark - UIScrollViewDelegate methods - (void)scrollViewDidScroll:(UIScrollView *)scrollView @@ -381,7 +329,6 @@ static char shyNavBarManagerKey; [self tly_swizzleInstanceMethod:@selector(viewWillAppear:) withReplacement:@selector(tly_swizzledViewWillAppear:)]; [self tly_swizzleInstanceMethod:@selector(viewWillLayoutSubviews) withReplacement:@selector(tly_swizzledViewDidLayoutSubviews)]; [self tly_swizzleInstanceMethod:@selector(viewWillDisappear:) withReplacement:@selector(tly_swizzledViewWillDisappear:)]; - [self tly_swizzleInstanceMethod:@selector(viewDidDisappear:) withReplacement:@selector(tly_swizzledViewDidDisappear:)]; }); } @@ -389,19 +336,7 @@ static char shyNavBarManagerKey; - (void)tly_swizzledViewWillAppear:(BOOL)animated { - [[self _internalShyNavBarManager] _viewWillAppear]; - - if (self.navigationController.viewControllers.count > 1) - { - NSUInteger index = self.navigationController.viewControllers.count - 2; - UIViewController *previousController = self.navigationController.viewControllers[index]; - - if (self.navigationController.didShyNavBarManagerHideNavBar) - { - [self.navigationController setNavigationBarHidden:NO animated:YES]; - } - } - + [[self _internalShyNavBarManager] prepareForDisplay]; [self tly_swizzledViewWillAppear:animated]; } @@ -413,16 +348,10 @@ static char shyNavBarManagerKey; - (void)tly_swizzledViewWillDisappear:(BOOL)animated { - [[self _internalShyNavBarManager] _viewWillDisappear]; + [[self _internalShyNavBarManager] cleanup]; [self tly_swizzledViewWillDisappear:animated]; } -- (void)tly_swizzledViewDidDisappear:(BOOL)animated -{ - [[self _internalShyNavBarManager] _viewDidDisappear]; - [self tly_swizzledViewDidDisappear:animated]; -} - #pragma mark - Properties - (void)setShyNavBarManager:(TLYShyNavBarManager *)shyNavBarManager @@ -453,21 +382,3 @@ static char shyNavBarManagerKey; @end -#pragma mark - UINavigationController Category implementation - -const void *didShyNavBarManagerHideNavBarKey = &didShyNavBarManagerHideNavBarKey; - -@implementation UINavigationController (TLYShyNavBar) - -- (void)setDidShyNavBarManagerHideNavBar:(BOOL)didShyNavBarManagerHideNavBar -{ - objc_setAssociatedObject(self, didShyNavBarManagerHideNavBarKey, @(didShyNavBarManagerHideNavBar), OBJC_ASSOCIATION_RETAIN_NONATOMIC); -} - -- (BOOL)didShyNavBarManagerHideNavBar -{ - return [objc_getAssociatedObject(self, didShyNavBarManagerHideNavBarKey) boolValue]; -} - -@end - diff --git a/TLYShyNavBar/TLYShyViewController.h b/TLYShyNavBar/TLYShyViewController.h index 8d9e5c8..5d0bc71 100644 --- a/TLYShyNavBar/TLYShyViewController.h +++ b/TLYShyNavBar/TLYShyViewController.h @@ -35,9 +35,6 @@ typedef CGFloat(^TLYShyViewControllerContractionAmountBlock)(UIView *view); @property (nonatomic) BOOL hidesSubviews; @property (nonatomic) BOOL hidesAfterContraction; -@property (nonatomic, readonly, getter = isContracted) BOOL contracted; -@property (nonatomic, readonly, getter = isExpanded) BOOL expanded; - - (CGFloat)updateYOffset:(CGFloat)deltaY; - (CGFloat)snap:(BOOL)contract; diff --git a/TLYShyNavBar/TLYShyViewController.m b/TLYShyNavBar/TLYShyViewController.m index 6c0d483..9616df9 100644 --- a/TLYShyNavBar/TLYShyViewController.m +++ b/TLYShyNavBar/TLYShyViewController.m @@ -17,6 +17,9 @@ const CGFloat contractionVelocity = 300.f; @property (nonatomic) CGPoint contractedCenterValue; +@property (nonatomic, getter = isContracted) BOOL contracted; +@property (nonatomic, getter = isExpanded) BOOL expanded; + @end @implementation TLYShyViewController diff --git a/TLYShyNavBarDemo/TLYShyNavBarDemo.xcodeproj/project.pbxproj b/TLYShyNavBarDemo/TLYShyNavBarDemo.xcodeproj/project.pbxproj index 1db5523..19b05af 100644 --- a/TLYShyNavBarDemo/TLYShyNavBarDemo.xcodeproj/project.pbxproj +++ b/TLYShyNavBarDemo/TLYShyNavBarDemo.xcodeproj/project.pbxproj @@ -65,7 +65,7 @@ 829FEDFE1957DF620017E186 /* NSObject+TLYSwizzlingHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+TLYSwizzlingHelpers.h"; sourceTree = ""; }; 829FEDFF1957DF620017E186 /* NSObject+TLYSwizzlingHelpers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+TLYSwizzlingHelpers.m"; sourceTree = ""; }; 82B01ED1195D449F00C3C10C /* TLYDelegateProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TLYDelegateProxy.h; sourceTree = ""; }; - 82B01ED2195D449F00C3C10C /* TLYDelegateProxy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TLYDelegateProxy.m; sourceTree = ""; usesTabs = 0; }; + 82B01ED2195D449F00C3C10C /* TLYDelegateProxy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TLYDelegateProxy.m; sourceTree = ""; }; 82C882071955FDA60046C49D /* UIViewController+BetterLayoutGuides.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIViewController+BetterLayoutGuides.h"; sourceTree = ""; }; 82C882081955FDA60046C49D /* UIViewController+BetterLayoutGuides.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+BetterLayoutGuides.m"; sourceTree = ""; }; /* End PBXFileReference section */ diff --git a/TLYShyNavBarDemo/TLYShyNavBarDemo/Base.lproj/Main.storyboard b/TLYShyNavBarDemo/TLYShyNavBarDemo/Base.lproj/Main.storyboard index aaa86e0..b8ee658 100644 --- a/TLYShyNavBarDemo/TLYShyNavBarDemo/Base.lproj/Main.storyboard +++ b/TLYShyNavBarDemo/TLYShyNavBarDemo/Base.lproj/Main.storyboard @@ -16,11 +16,11 @@ - + - + @@ -36,10 +36,6 @@ - - - - diff --git a/TLYShyNavBarDemo/TLYShyNavBarDemo/TLYViewController.m b/TLYShyNavBarDemo/TLYShyNavBarDemo/TLYViewController.m index 739e47b..cb05e99 100644 --- a/TLYShyNavBarDemo/TLYShyNavBarDemo/TLYViewController.m +++ b/TLYShyNavBarDemo/TLYShyNavBarDemo/TLYViewController.m @@ -32,11 +32,17 @@ UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), 44.f)]; view.backgroundColor = [UIColor redColor]; - + /* Library code */ self.shyNavBarManager.scrollView = self.scrollView; /* Can then be remove by setting the ExtensionView to nil */ [self.shyNavBarManager setExtensionView:view]; } +- (void)viewDidLayoutSubviews +{ + [super viewDidLayoutSubviews]; + self.scrollView.contentSize = self.imageView.bounds.size; +} + @end