[NEW]: lazy load the shyNavBarManager, much better than the addShyNavBar method

[NEW]: updated demo project
[NEW]: hide the extension view to disallow tampering with it
[NEW]: better docs
[FIX]: fix default resistance amount
This commit is contained in:
Mazyad Alabduljaleel 2014-06-27 18:37:34 +04:00
parent 30a1a066d2
commit 31cdc78869
3 changed files with 23 additions and 19 deletions

View File

@ -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

View File

@ -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, &shyNavBarManagerKey);
}
#pragma mark - Public methods
- (void)addShyNavBarManagerWithScrollView:(UIScrollView *)scrollView
{
TLYShyNavBarManager *shyManager = [TLYShyNavBarManager new];
shyManager.scrollView = scrollView;
id shyNavBarManager = objc_getAssociatedObject(self, &shyNavBarManagerKey);
if (!shyNavBarManager)
{
shyNavBarManager = [[TLYShyNavBarManager alloc] init];
self.shyNavBarManager = shyNavBarManager;
}
self.shyNavBarManager = shyManager;
return shyNavBarManager;
}
@end

View File

@ -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];
}