diff --git a/TLYShyNavBar/ShyControllers/TLYShyViewController.h b/TLYShyNavBar/ShyControllers/TLYShyViewController.h index 2c6a2fb..5bde31c 100644 --- a/TLYShyNavBar/ShyControllers/TLYShyViewController.h +++ b/TLYShyNavBar/ShyControllers/TLYShyViewController.h @@ -39,6 +39,11 @@ typedef CGFloat(^TLYShyViewControllerContractionAmountBlock)(UIView *view); @property (nonatomic) TLYShyNavBarFade fadeBehavior; +/* Additional sticky offset for extension view, + * usable to make only part of extension view visible in folded state. + */ +@property (nonatomic) CGFloat stickyOffset; + /* Sticky means it will always stay in expanded state */ @property (nonatomic) BOOL sticky; diff --git a/TLYShyNavBar/ShyControllers/TLYShyViewController.m b/TLYShyNavBar/ShyControllers/TLYShyViewController.m index ad8e54d..2302e3e 100644 --- a/TLYShyNavBar/ShyControllers/TLYShyViewController.m +++ b/TLYShyNavBar/ShyControllers/TLYShyViewController.m @@ -61,7 +61,7 @@ - (CGPoint)expandedCenterValue - (CGFloat)contractionAmountValue { - return self.sticky ? 0.f : CGRectGetHeight(self.view.bounds); + return (self.sticky ? 0.f : CGRectGetHeight(self.view.bounds)) - self.stickyOffset; } - (CGPoint)contractedCenterValue @@ -83,7 +83,7 @@ - (BOOL)expanded - (void)_onAlphaUpdate:(CGFloat)alpha { - if (self.sticky) + if (self.sticky || self.stickyOffset > FLT_EPSILON) { self.view.alpha = 1.f; [self _updateSubviewsAlpha:1.f]; @@ -169,7 +169,7 @@ - (CGFloat)updateYOffset:(CGFloat)deltaY CGFloat newYCenter = MAX(MIN(self.expandedCenterValue.y, newYOffset), self.contractedCenterValue.y); [self _updateCenter:CGPointMake(self.expandedCenterValue.x, newYCenter)]; - + CGFloat newAlpha = 1.f - (self.expandedCenterValue.y - self.view.center.y) / self.contractionAmountValue; newAlpha = MIN(MAX(FLT_EPSILON, newAlpha), 1.f); @@ -178,7 +178,7 @@ - (CGFloat)updateYOffset:(CGFloat)deltaY residual = newYOffset - newYCenter; // QUICK FIX: Only the extensionView is hidden - if (!self.subShyController) + if (!self.subShyController && self.stickyOffset <= FLT_EPSILON) { self.view.hidden = residual < 0; } diff --git a/TLYShyNavBar/TLYShyNavBarManager.h b/TLYShyNavBar/TLYShyNavBarManager.h index 0e507dc..91ddb9d 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.h +++ b/TLYShyNavBar/TLYShyNavBarManager.h @@ -56,6 +56,11 @@ */ @property (nonatomic) BOOL stickyExtensionView; +/* Additional sticky offset for extension view, + * usable to make only part of extension view visible in folded state. + */ +@property (nonatomic) CGFloat stickyOffset; + /* Control the resistance when scrolling up/down before the navbar * expands/contracts again. */ diff --git a/TLYShyNavBar/TLYShyNavBarManager.m b/TLYShyNavBar/TLYShyNavBarManager.m index 63f3267..338d025 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.m +++ b/TLYShyNavBar/TLYShyNavBarManager.m @@ -225,6 +225,16 @@ - (BOOL)stickyExtensionView return self.extensionController.sticky; } +- (CGFloat)stickyOffset +{ + return self.extensionController.stickyOffset; +} + +- (void)setStickyOffset:(CGFloat)stickyOffset +{ + self.extensionController.stickyOffset = stickyOffset; +} + - (void)setStickyExtensionView:(BOOL)stickyExtensionView { self.extensionController.sticky = stickyExtensionView; diff --git a/TLYShyNavBarDemo/TLYShyNavBarDemo/Base.lproj/Main.storyboard b/TLYShyNavBarDemo/TLYShyNavBarDemo/Base.lproj/Main.storyboard index 08a821e..5109620 100644 --- a/TLYShyNavBarDemo/TLYShyNavBarDemo/Base.lproj/Main.storyboard +++ b/TLYShyNavBarDemo/TLYShyNavBarDemo/Base.lproj/Main.storyboard @@ -55,6 +55,11 @@ + + + + + diff --git a/TLYShyNavBarDemo/TLYShyNavBarDemo/TLYViewController.m b/TLYShyNavBarDemo/TLYShyNavBarDemo/TLYViewController.m index 729a203..32300ce 100644 --- a/TLYShyNavBarDemo/TLYShyNavBarDemo/TLYViewController.m +++ b/TLYShyNavBarDemo/TLYShyNavBarDemo/TLYViewController.m @@ -13,6 +13,7 @@ @interface TLYViewController () @property (nonatomic, assign) IBInspectable BOOL disableExtensionView; @property (nonatomic, assign) IBInspectable BOOL stickyNavigationBar; @property (nonatomic, assign) IBInspectable BOOL stickyExtensionView; +@property (nonatomic, assign) IBInspectable CGFloat stickyOffset; @property (nonatomic, assign) IBInspectable NSInteger fadeBehavior; @property (weak, nonatomic) IBOutlet UIScrollView *scrollView; @@ -32,6 +33,7 @@ - (id)initWithCoder:(NSCoder *)aDecoder self.disableExtensionView = NO; self.stickyNavigationBar = NO; self.stickyExtensionView = NO; + self.stickyOffset = 0.f; self.fadeBehavior = TLYShyNavBarFadeSubviews; self.title = @"WTFox Say"; @@ -70,6 +72,8 @@ - (void)viewDidLoad [self.shyNavBarManager setStickyExtensionView:self.stickyExtensionView]; /* Navigation bar fade behavior */ [self.shyNavBarManager setFadeBehavior:self.fadeBehavior]; + /* Show sticky offset */ + [self.shyNavBarManager setStickyOffset:self.stickyOffset]; } - (void)viewDidLayoutSubviews