Skip to content
This repository has been archived by the owner on Dec 4, 2018. It is now read-only.

Add sticky offset #163

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions TLYShyNavBar/ShyControllers/TLYShyViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions TLYShyNavBar/ShyControllers/TLYShyViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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];
Expand Down Expand Up @@ -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);

Expand All @@ -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;
}
Expand Down
5 changes: 5 additions & 0 deletions TLYShyNavBar/TLYShyNavBarManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
10 changes: 10 additions & 0 deletions TLYShyNavBar/TLYShyNavBarManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions TLYShyNavBarDemo/TLYShyNavBarDemo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
</constraints>
</view>
<navigationItem key="navigationItem" id="vR6-NW-SQ1"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="stickyOffset">
<real key="value" value="10"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
<connections>
<outlet property="imageView" destination="RWp-Z1-nNI" id="6fW-pD-yc1"/>
<outlet property="scrollView" destination="d0u-JZ-WMw" id="BVu-7c-4oX"/>
Expand Down
4 changes: 4 additions & 0 deletions TLYShyNavBarDemo/TLYShyNavBarDemo/TLYViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -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
Expand Down