From 81e00bbb4ccccc8d3e1b6344c64ee89ea7473eba Mon Sep 17 00:00:00 2001 From: Mazyad Alabduljaleel Date: Sat, 21 Jun 2014 21:54:10 +0400 Subject: [PATCH] [NEW]: import better layout guide calculation --- TLYShyNavBar/TLYShyNavBarManager.m | 3 +- .../UIViewController+BetterLayoutGuides.h | 25 +++++++++++++ .../UIViewController+BetterLayoutGuides.m | 37 +++++++++++++++++++ .../project.pbxproj | 6 +++ TODO.md | 2 +- 5 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 TLYShyNavBar/UIViewController+BetterLayoutGuides.h create mode 100644 TLYShyNavBar/UIViewController+BetterLayoutGuides.m diff --git a/TLYShyNavBar/TLYShyNavBarManager.m b/TLYShyNavBar/TLYShyNavBarManager.m index e398ab3..3f98fed 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.m +++ b/TLYShyNavBar/TLYShyNavBarManager.m @@ -8,6 +8,7 @@ #import "TLYShyNavBarManager.h" #import "TLYShyViewController.h" +#import "UIViewController+BetterLayoutGuides.h" #import // Thanks to SO user, MattDiPasquale @@ -80,7 +81,7 @@ static inline CGFloat AACStatusBarHeight() self.extensionController.expandedCenter = ^(UIView *view) { return CGPointMake(CGRectGetMidX(view.bounds), - CGRectGetMidY(view.bounds) + weakSelf.viewController.realTopLayoutGuide.length); + CGRectGetMidY(view.bounds) + weakSelf.viewController.tly_topLayoutGuide.length); }; self.navBarController.child = self.extensionController; diff --git a/TLYShyNavBar/UIViewController+BetterLayoutGuides.h b/TLYShyNavBar/UIViewController+BetterLayoutGuides.h new file mode 100644 index 0000000..cbd646c --- /dev/null +++ b/TLYShyNavBar/UIViewController+BetterLayoutGuides.h @@ -0,0 +1,25 @@ +// +// UIViewController+BetterLayoutGuides.h +// TLYShyNavBarDemo +// +// Created by Mazyad Alabduljaleel on 6/21/14. +// Copyright (c) 2014 Telly, Inc. All rights reserved. +// + +#import + +/* CATEGORY DESCRIPTION: + * ===================== + * Apparently, Apple fucked up when they implemented autolayout + * somehow, so when we have child view controllers, they get wrong + * layout guides. This helps accomodate that fuck up. + * + * Courtesy of http://stackoverflow.com/questions/19140530/toplayoutguide-in-child-view-controller + */ + +@interface UIViewController (BetterLayoutGuides) + +@property (nonatomic, readonly) id tly_topLayoutGuide; +@property (nonatomic, readonly) id tly_bottomLayoutGuide; + +@end diff --git a/TLYShyNavBar/UIViewController+BetterLayoutGuides.m b/TLYShyNavBar/UIViewController+BetterLayoutGuides.m new file mode 100644 index 0000000..8ea1159 --- /dev/null +++ b/TLYShyNavBar/UIViewController+BetterLayoutGuides.m @@ -0,0 +1,37 @@ +// +// UIViewController+BetterLayoutGuides.m +// TLYShyNavBarDemo +// +// Created by Mazyad Alabduljaleel on 6/21/14. +// Copyright (c) 2014 Telly, Inc. All rights reserved. +// + +#import "UIViewController+BetterLayoutGuides.h" + +@implementation UIViewController (BetterLayoutGuides) + +- (id)tly_topLayoutGuide +{ + if (self.parentViewController && + ![self.parentViewController isKindOfClass:UINavigationController.class]) + { + return self.parentViewController.tly_topLayoutGuide; + } + else { + return self.topLayoutGuide; + } +} + +- (id)tly_bottomLayoutGuide +{ + if (self.parentViewController && + ![self.parentViewController isKindOfClass:UINavigationController.class]) + { + return self.parentViewController.tly_bottomLayoutGuide; + } + else { + return self.bottomLayoutGuide; + } +} + +@end diff --git a/TLYShyNavBarDemo/TLYShyNavBarDemo.xcodeproj/project.pbxproj b/TLYShyNavBarDemo/TLYShyNavBarDemo.xcodeproj/project.pbxproj index 3950ef5..e2044c5 100644 --- a/TLYShyNavBarDemo/TLYShyNavBarDemo.xcodeproj/project.pbxproj +++ b/TLYShyNavBarDemo/TLYShyNavBarDemo.xcodeproj/project.pbxproj @@ -23,6 +23,7 @@ 828F57411949C37B009EB8DD /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 828F57231949C37B009EB8DD /* UIKit.framework */; }; 828F57491949C37B009EB8DD /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 828F57471949C37B009EB8DD /* InfoPlist.strings */; }; 828F574B1949C37B009EB8DD /* TLYShyNavBarDemoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 828F574A1949C37B009EB8DD /* TLYShyNavBarDemoTests.m */; }; + 82C882091955FDA60046C49D /* UIViewController+BetterLayoutGuides.m in Sources */ = {isa = PBXBuildFile; fileRef = 82C882081955FDA60046C49D /* UIViewController+BetterLayoutGuides.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -59,6 +60,8 @@ 828F57461949C37B009EB8DD /* TLYShyNavBarDemoTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "TLYShyNavBarDemoTests-Info.plist"; sourceTree = ""; }; 828F57481949C37B009EB8DD /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 828F574A1949C37B009EB8DD /* TLYShyNavBarDemoTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TLYShyNavBarDemoTests.m; sourceTree = ""; }; + 82C882071955FDA60046C49D /* UIViewController+BetterLayoutGuides.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIViewController+BetterLayoutGuides.h"; sourceTree = ""; }; + 82C882081955FDA60046C49D /* UIViewController+BetterLayoutGuides.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+BetterLayoutGuides.m"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -166,6 +169,8 @@ 8268FA12194DBA58004EC0E4 /* TLYShyNavBarManager.m */, 8268FA00194C926F004EC0E4 /* TLYShyViewController.h */, 8268FA01194C926F004EC0E4 /* TLYShyViewController.m */, + 82C882071955FDA60046C49D /* UIViewController+BetterLayoutGuides.h */, + 82C882081955FDA60046C49D /* UIViewController+BetterLayoutGuides.m */, ); name = TLYShyNavBar; path = ../TLYShyNavBar; @@ -270,6 +275,7 @@ buildActionMask = 2147483647; files = ( 8268FA13194DBA58004EC0E4 /* TLYShyNavBarManager.m in Sources */, + 82C882091955FDA60046C49D /* UIViewController+BetterLayoutGuides.m in Sources */, 828F57301949C37B009EB8DD /* TLYAppDelegate.m in Sources */, 8268FA02194C926F004EC0E4 /* TLYShyViewController.m in Sources */, 828F57361949C37B009EB8DD /* TLYViewController.m in Sources */, diff --git a/TODO.md b/TODO.md index 27c584b..02d0ae2 100644 --- a/TODO.md +++ b/TODO.md @@ -1,7 +1,7 @@ # TODO -+ **REALLY need to import the `realTopLayoutGuide` categories** ++ ~~**REALLY need to import the `realTopLayoutGuide` categories**~~ + **REALLY need to cleanup scrollView observer properly** + Add ability to remove extension view + Add tolerance customization