Reverse the last commits, gonna work on them in develop branch

This commit is contained in:
Mazyad Alabduljaleel 2014-07-04 12:19:12 +04:00
parent 6bfe614a64
commit 790355a6c6
6 changed files with 36 additions and 123 deletions

View File

@ -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>
@ -51,7 +36,6 @@ static inline CGFloat AACStatusBarHeight()
@property (nonatomic, strong) TLYDelegateProxy *delegateProxy;
@property (nonatomic, strong) UIView *extensionViewContainer;
@property (nonatomic, weak) UIView *statusBarBackgroundView;
@property (nonatomic) UIEdgeInsets previousScrollInsets;
@property (nonatomic) CGFloat previousYOffset;
@ -75,12 +59,13 @@ static inline CGFloat AACStatusBarHeight()
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;
@ -167,56 +152,6 @@ static inline CGFloat AACStatusBarHeight()
#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)
@ -237,8 +172,7 @@ static inline CGFloat AACStatusBarHeight()
}
/* 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);
@ -289,10 +223,9 @@ static inline CGFloat AACStatusBarHeight()
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
@ -325,6 +258,12 @@ static inline CGFloat AACStatusBarHeight()
}
}
- (void)prepareForDisplay
{
[self cleanup];
self.viewControllerVisible = YES;
}
- (void)layoutViews
{
UIEdgeInsets scrollInsets = self.scrollView.contentInset;
@ -344,6 +283,15 @@ static inline CGFloat AACStatusBarHeight()
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
@ -381,7 +329,6 @@ static char shyNavBarManagerKey;
[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:)];
});
}
@ -389,19 +336,7 @@ static char shyNavBarManagerKey;
- (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];
}
@ -413,16 +348,10 @@ static char shyNavBarManagerKey;
- (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
@ -453,21 +382,3 @@ static char shyNavBarManagerKey;
@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

View File

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

View File

@ -17,6 +17,9 @@ const CGFloat contractionVelocity = 300.f;
@property (nonatomic) CGPoint contractedCenterValue;
@property (nonatomic, getter = isContracted) BOOL contracted;
@property (nonatomic, getter = isExpanded) BOOL expanded;
@end
@implementation TLYShyViewController

View File

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

View File

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

View File

@ -32,11 +32,17 @@
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