Add ability to stick extension view to the top.

This commit is contained in:
Yukan 2015-06-11 13:28:33 -04:00
parent 0afb58fcdb
commit dd33163301
5 changed files with 27 additions and 2 deletions

View File

@ -42,6 +42,10 @@
*/
@property (nonatomic, readonly) CGRect extensionViewBounds;
/* Sticky extension view
*/
@property (nonatomic) BOOL stickyExtensionView;
/* Control the resistance when scrolling up/down before the navbar
* expands/contracts again.
*/

View File

@ -210,6 +210,15 @@ static inline CGFloat AACStatusBarHeight()
}
}
- (void)setStickyExtensionView:(BOOL)stickyExtensionView
{
_stickyExtensionView = stickyExtensionView;
if (self.navBarController) {
self.navBarController.stickyExtensionView = YES;
}
}
#pragma mark - Private methods
- (BOOL)_shouldHandleScrolling

View File

@ -40,6 +40,10 @@ typedef CGFloat(^TLYShyViewControllerContractionAmountBlock)(UIView *view);
@property (nonatomic, readonly) CGFloat totalHeight;
/* Sticky extension view
*/
@property (nonatomic) BOOL stickyExtensionView;
- (CGFloat)updateYOffset:(CGFloat)deltaY;
- (CGFloat)snap:(BOOL)contract;

View File

@ -89,7 +89,7 @@ const CGFloat contractionVelocity = 300.f;
- (CGFloat)updateYOffset:(CGFloat)deltaY
{
if (self.child && deltaY < 0)
if (self.child && deltaY < 0 && !self.stickyExtensionView)
{
deltaY = [self.child updateYOffset:deltaY];
self.child.view.hidden = (deltaY) < 0;
@ -100,6 +100,12 @@ const CGFloat contractionVelocity = 300.f;
self.view.center = CGPointMake(self.expandedCenterValue.x, newYCenter);
if (self.stickyExtensionView) {
CGFloat newChildYOffset = self.child.view.center.y + deltaY;
CGFloat newChildYCenter = MAX(MIN(self.child.expandedCenterValue.y, newChildYOffset), self.child.contractedCenterValue.y);
self.child.view.center = CGPointMake(self.child.expandedCenterValue.x, newChildYCenter);
}
if (self.hidesSubviews)
{
CGFloat newAlpha = 1.f - (self.expandedCenterValue.y - self.view.center.y) / self.contractionAmountValue;
@ -113,7 +119,7 @@ const CGFloat contractionVelocity = 300.f;
CGFloat residual = newYOffset - newYCenter;
if (self.child && deltaY > 0 && residual > 0)
if (self.child && deltaY > 0 && residual > 0 && !self.stickyExtensionView)
{
residual = [self.child updateYOffset:residual];
self.child.view.hidden = residual - (newYOffset - newYCenter) > FLT_EPSILON;

View File

@ -37,6 +37,8 @@
self.shyNavBarManager.scrollView = self.scrollView;
/* Can then be remove by setting the ExtensionView to nil */
[self.shyNavBarManager setExtensionView:view];
/* Make the extension view stick to the top */
[self.shyNavBarManager setStickyExtensionView:YES];
}
- (void)viewDidLayoutSubviews