diff --git a/TLYShyNavBar/TLYShyNavBarManager.h b/TLYShyNavBar/TLYShyNavBarManager.h index 638c096..5e1694e 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.h +++ b/TLYShyNavBar/TLYShyNavBarManager.h @@ -33,10 +33,10 @@ /* The scrollView subclass that will drive the contraction/expansion */ @property (nonatomic, weak) UIScrollView *scrollView; -/* The container to contain the extension view, if any. Exposed to - * allow the developer to adjust content offset as necessary +/* The container contains the extension view, if any. Exposed to + * allow the developer to adjust content offset as necessary. */ -@property (nonatomic, readonly) UIView *extensionViewContainer; +@property (nonatomic, readonly) CGRect extensionViewBounds; /* Control the resistance when scrolling up/down before the navbar * expands/contracts again. @@ -62,9 +62,7 @@ @interface UIViewController (ShyNavBar) +/* Initially, this is nil, but created for you when you access it */ @property (nonatomic, strong) TLYShyNavBarManager *shyNavBarManager; -// Convenience -- (void)addShyNavBarManagerWithScrollView:(UIScrollView *)scrollView; - @end diff --git a/TLYShyNavBar/TLYShyNavBarManager.m b/TLYShyNavBar/TLYShyNavBarManager.m index 7e51639..5f107a5 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.m +++ b/TLYShyNavBar/TLYShyNavBarManager.m @@ -35,7 +35,7 @@ static inline CGFloat AACStatusBarHeight() @property (nonatomic, strong) TLYDelegateProxy *delegateProxy; -@property (nonatomic, readwrite) UIView *extensionViewContainer; +@property (nonatomic, strong) UIView *extensionViewContainer; @property (nonatomic) CGFloat previousYOffset; @property (nonatomic) CGFloat resistanceConsumed; @@ -59,7 +59,7 @@ static inline CGFloat AACStatusBarHeight() self.contracting = NO; self.previousContractionState = YES; - self.expansionResistance = 100.f; + self.expansionResistance = 200.f; self.contractionResistance = 0.f; self.previousYOffset = NAN; @@ -108,6 +108,7 @@ static inline CGFloat AACStatusBarHeight() _viewController = viewController; UIView *navbar = viewController.navigationController.navigationBar; + NSAssert(navbar != nil, @"You are using the component wrong... Please see the README file."); [self.extensionViewContainer removeFromSuperview]; [self.viewController.view addSubview:self.extensionViewContainer]; @@ -125,6 +126,11 @@ static inline CGFloat AACStatusBarHeight() _scrollView.delegate = (id)self.delegateProxy; } +- (CGRect)extensionViewBounds +{ + return self.extensionViewContainer.bounds; +} + #pragma mark - Private methods - (void)_handleScrolling @@ -203,6 +209,9 @@ static inline CGFloat AACStatusBarHeight() - (void)setExtensionView:(UIView *)view { + NSAssert([self.extensionViewContainer.subviews count] <= 1, + @"Please don't tamper with this view! Thanks!"); + UIView *previousExtensionView = [self.extensionViewContainer.subviews firstObject]; if (view != previousExtensionView) { @@ -308,17 +317,14 @@ static char shyNavBarManagerKey; - (TLYShyNavBarManager *)shyNavBarManager { - return objc_getAssociatedObject(self, ­NavBarManagerKey); -} - -#pragma mark - Public methods - -- (void)addShyNavBarManagerWithScrollView:(UIScrollView *)scrollView -{ - TLYShyNavBarManager *shyManager = [TLYShyNavBarManager new]; - shyManager.scrollView = scrollView; + id shyNavBarManager = objc_getAssociatedObject(self, ­NavBarManagerKey); + if (!shyNavBarManager) + { + shyNavBarManager = [[TLYShyNavBarManager alloc] init]; + self.shyNavBarManager = shyNavBarManager; + } - self.shyNavBarManager = shyManager; + return shyNavBarManager; } @end diff --git a/TLYShyNavBarDemo/TLYShyNavBarDemo/TLYViewController.m b/TLYShyNavBarDemo/TLYShyNavBarDemo/TLYViewController.m index 23871b4..cb05e99 100644 --- a/TLYShyNavBarDemo/TLYShyNavBarDemo/TLYViewController.m +++ b/TLYShyNavBarDemo/TLYShyNavBarDemo/TLYViewController.m @@ -34,7 +34,7 @@ view.backgroundColor = [UIColor redColor]; /* Library code */ - [self addShyNavBarManagerWithScrollView:self.scrollView]; + self.shyNavBarManager.scrollView = self.scrollView; /* Can then be remove by setting the ExtensionView to nil */ [self.shyNavBarManager setExtensionView:view]; }