Skip to content

Commit

Permalink
Reverse the last commits, gonna work on them in develop branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Mazyod committed Jul 4, 2014
1 parent 6bfe614 commit 790355a
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 123 deletions.
135 changes: 23 additions & 112 deletions TLYShyNavBar/TLYShyNavBarManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,6 @@ static inline CGFloat AACStatusBarHeight()
return MIN(statusBarSize.width, statusBarSize.height);
}

#pragma mark - UINavigationController Category interface

/* CATEGORY DESCRIPTION:
* =====================
* We set the navigation bar to hidden in TLYShyNavBarManager,
* but then we need to restore it in the next view controller. We
* use this category to add a flag if it was us whom hid the navbar.
*/

@interface UINavigationController (TLYShyNavBar)

@property (nonatomic) BOOL didShyNavBarManagerHideNavBar;

@end

#pragma mark - TLYShyNavBarManager class

@interface TLYShyNavBarManager () <UIScrollViewDelegate>
Expand All @@ -51,7 +36,6 @@ @interface TLYShyNavBarManager () <UIScrollViewDelegate>
@property (nonatomic, strong) TLYDelegateProxy *delegateProxy;

@property (nonatomic, strong) UIView *extensionViewContainer;
@property (nonatomic, weak) UIView *statusBarBackgroundView;

@property (nonatomic) UIEdgeInsets previousScrollInsets;
@property (nonatomic) CGFloat previousYOffset;
Expand All @@ -75,12 +59,13 @@ - (instancetype)init
self.delegateProxy = [[TLYDelegateProxy alloc] initWithMiddleMan:self];

self.contracting = NO;
self.previousContractionState = NO;
self.previousContractionState = YES;

self.expansionResistance = 200.f;
self.contractionResistance = 0.f;

[self _resetCacheVariables];
self.previousScrollInsets = UIEdgeInsetsZero;
self.previousYOffset = NAN;

self.navBarController = [[TLYShyViewController alloc] init];
self.navBarController.hidesSubviews = YES;
Expand Down Expand Up @@ -167,56 +152,6 @@ - (CGRect)extensionViewBounds

#pragma mark - Private methods

- (void)_resetCacheVariables
{
self.previousYOffset = NAN;
self.previousScrollInsets = UIEdgeInsetsZero;
self.resistanceConsumed = 0;
}

- (void)_viewWillAppear
{
[self _resetCacheVariables];
self.viewControllerVisible = YES;

UINavigationController *navController = self.viewController.navigationController;
if (navController.isNavigationBarHidden)
{
[navController setNavigationBarHidden:NO animated:NO];
}
}

- (void)_viewWillDisappear
{
if (self.isContracting)
{
UINavigationController *navController = self.viewController.navigationController;
[navController setNavigationBarHidden:YES animated:YES];
navController.didShyNavBarManagerHideNavBar = YES;

UIView *snapshotView = [self.viewController.view.window snapshotViewAfterScreenUpdates:NO];

CGRect clippingFrame = snapshotView.frame;
clippingFrame.size.height = AACStatusBarHeight();

UIView *clippingView = [[UIView alloc] initWithFrame:clippingFrame];
clippingView.backgroundColor = [UIColor clearColor];
clippingView.clipsToBounds = YES;

[clippingView addSubview:snapshotView];
[self.viewController.view addSubview:clippingView];

self.statusBarBackgroundView = clippingView;
}

self.viewControllerVisible = NO;
}

- (void)_viewDidDisappear
{
[self.statusBarBackgroundView removeFromSuperview];
}

- (void)_handleScrolling
{
if (!self.isViewControllerVisible)
Expand All @@ -237,8 +172,7 @@ - (void)_handleScrolling
}

/* rounding to resolve a dumb issue with the contentOffset value */
CGFloat maxContentOffset = self.scrollView.contentSize.height - CGRectGetHeight(self.scrollView.bounds);
CGFloat end = floorf(maxContentOffset + self.scrollView.contentInset.bottom - 0.5f);
CGFloat end = floorf(self.scrollView.contentSize.height - CGRectGetHeight(self.scrollView.bounds) + self.scrollView.contentInset.bottom - 0.5f);
if (self.previousYOffset > end)
{
deltaY = MAX(0, deltaY - self.previousYOffset + end);
Expand Down Expand Up @@ -289,10 +223,9 @@ - (void)_handleScrollingEnded

self.resistanceConsumed = 0;

CGFloat deltaY = [self.navBarController snap:self.isContracting];
self.contracting = self.navBarController.isContracted;

CGFloat deltaY = deltaY = [self.navBarController snap:self.isContracting];
CGPoint newContentOffset = self.scrollView.contentOffset;

newContentOffset.y -= deltaY;

[UIView animateWithDuration:0.2
Expand Down Expand Up @@ -325,6 +258,12 @@ - (void)setExtensionView:(UIView *)view
}
}

- (void)prepareForDisplay
{
[self cleanup];
self.viewControllerVisible = YES;
}

- (void)layoutViews
{
UIEdgeInsets scrollInsets = self.scrollView.contentInset;
Expand All @@ -344,6 +283,15 @@ - (void)layoutViews
self.scrollView.scrollIndicatorInsets = scrollInsets;
}

- (void)cleanup
{
[self.navBarController expand];

self.viewControllerVisible = NO;
self.previousYOffset = NAN;
self.previousScrollInsets = UIEdgeInsetsZero;
}

#pragma mark - UIScrollViewDelegate methods

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
Expand Down Expand Up @@ -381,27 +329,14 @@ + (void)load
[self tly_swizzleInstanceMethod:@selector(viewWillAppear:) withReplacement:@selector(tly_swizzledViewWillAppear:)];
[self tly_swizzleInstanceMethod:@selector(viewWillLayoutSubviews) withReplacement:@selector(tly_swizzledViewDidLayoutSubviews)];
[self tly_swizzleInstanceMethod:@selector(viewWillDisappear:) withReplacement:@selector(tly_swizzledViewWillDisappear:)];
[self tly_swizzleInstanceMethod:@selector(viewDidDisappear:) withReplacement:@selector(tly_swizzledViewDidDisappear:)];
});
}

#pragma mark - Swizzled View Life Cycle

- (void)tly_swizzledViewWillAppear:(BOOL)animated
{
[[self _internalShyNavBarManager] _viewWillAppear];

if (self.navigationController.viewControllers.count > 1)
{
NSUInteger index = self.navigationController.viewControllers.count - 2;
UIViewController *previousController = self.navigationController.viewControllers[index];

if (self.navigationController.didShyNavBarManagerHideNavBar)
{
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
}

[[self _internalShyNavBarManager] prepareForDisplay];
[self tly_swizzledViewWillAppear:animated];
}

Expand All @@ -413,16 +348,10 @@ - (void)tly_swizzledViewDidLayoutSubviews

- (void)tly_swizzledViewWillDisappear:(BOOL)animated
{
[[self _internalShyNavBarManager] _viewWillDisappear];
[[self _internalShyNavBarManager] cleanup];
[self tly_swizzledViewWillDisappear:animated];
}

- (void)tly_swizzledViewDidDisappear:(BOOL)animated
{
[[self _internalShyNavBarManager] _viewDidDisappear];
[self tly_swizzledViewDidDisappear:animated];
}

#pragma mark - Properties

- (void)setShyNavBarManager:(TLYShyNavBarManager *)shyNavBarManager
Expand Down Expand Up @@ -453,21 +382,3 @@ - (TLYShyNavBarManager *)_internalShyNavBarManager

@end

#pragma mark - UINavigationController Category implementation

const void *didShyNavBarManagerHideNavBarKey = &didShyNavBarManagerHideNavBarKey;

@implementation UINavigationController (TLYShyNavBar)

- (void)setDidShyNavBarManagerHideNavBar:(BOOL)didShyNavBarManagerHideNavBar
{
objc_setAssociatedObject(self, didShyNavBarManagerHideNavBarKey, @(didShyNavBarManagerHideNavBar), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (BOOL)didShyNavBarManagerHideNavBar
{
return [objc_getAssociatedObject(self, didShyNavBarManagerHideNavBarKey) boolValue];
}

@end

3 changes: 0 additions & 3 deletions TLYShyNavBar/TLYShyViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ typedef CGFloat(^TLYShyViewControllerContractionAmountBlock)(UIView *view);
@property (nonatomic) BOOL hidesSubviews;
@property (nonatomic) BOOL hidesAfterContraction;

@property (nonatomic, readonly, getter = isContracted) BOOL contracted;
@property (nonatomic, readonly, getter = isExpanded) BOOL expanded;

- (CGFloat)updateYOffset:(CGFloat)deltaY;

- (CGFloat)snap:(BOOL)contract;
Expand Down
3 changes: 3 additions & 0 deletions TLYShyNavBar/TLYShyViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ @interface TLYShyViewController ()

@property (nonatomic) CGPoint contractedCenterValue;

@property (nonatomic, getter = isContracted) BOOL contracted;
@property (nonatomic, getter = isExpanded) BOOL expanded;

@end

@implementation TLYShyViewController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
829FEDFE1957DF620017E186 /* NSObject+TLYSwizzlingHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+TLYSwizzlingHelpers.h"; sourceTree = "<group>"; };
829FEDFF1957DF620017E186 /* NSObject+TLYSwizzlingHelpers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+TLYSwizzlingHelpers.m"; sourceTree = "<group>"; };
82B01ED1195D449F00C3C10C /* TLYDelegateProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TLYDelegateProxy.h; sourceTree = "<group>"; };
82B01ED2195D449F00C3C10C /* TLYDelegateProxy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TLYDelegateProxy.m; sourceTree = "<group>"; usesTabs = 0; };
82B01ED2195D449F00C3C10C /* TLYDelegateProxy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TLYDelegateProxy.m; sourceTree = "<group>"; };
82C882071955FDA60046C49D /* UIViewController+BetterLayoutGuides.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIViewController+BetterLayoutGuides.h"; sourceTree = "<group>"; };
82C882081955FDA60046C49D /* UIViewController+BetterLayoutGuides.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+BetterLayoutGuides.m"; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down
8 changes: 2 additions & 6 deletions TLYShyNavBarDemo/TLYShyNavBarDemo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="d0u-JZ-WMw">
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="d0u-JZ-WMw">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" misplaced="YES" image="sample" translatesAutoresizingMaskIntoConstraints="NO" id="RWp-Z1-nNI">
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" image="sample" translatesAutoresizingMaskIntoConstraints="NO" id="RWp-Z1-nNI">
<rect key="frame" x="0.0" y="0.0" width="320" height="800"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
</imageView>
Expand All @@ -36,10 +36,6 @@
</connections>
</button>
</subviews>
<constraints>
<constraint firstAttribute="bottom" secondItem="RWp-Z1-nNI" secondAttribute="bottom" id="YQw-2c-Jmn"/>
<constraint firstAttribute="centerX" secondItem="RWp-Z1-nNI" secondAttribute="centerX" id="pT1-mG-eEL"/>
</constraints>
<connections>
<outlet property="delegate" destination="vXZ-lx-hvc" id="kxr-NG-k4Q"/>
</connections>
Expand Down
8 changes: 7 additions & 1 deletion TLYShyNavBarDemo/TLYShyNavBarDemo/TLYViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@ - (void)viewDidLoad

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), 44.f)];
view.backgroundColor = [UIColor redColor];

/* Library code */
self.shyNavBarManager.scrollView = self.scrollView;
/* Can then be remove by setting the ExtensionView to nil */
[self.shyNavBarManager setExtensionView:view];
}

- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
self.scrollView.contentSize = self.imageView.bounds.size;
}

@end

0 comments on commit 790355a

Please sign in to comment.