[NEW]: import better layout guide calculation

This commit is contained in:
Mazyad Alabduljaleel 2014-06-21 21:54:10 +04:00
parent 19038b707e
commit 81e00bbb4c
5 changed files with 71 additions and 2 deletions

View File

@ -8,6 +8,7 @@
#import "TLYShyNavBarManager.h"
#import "TLYShyViewController.h"
#import "UIViewController+BetterLayoutGuides.h"
#import <objc/runtime.h>
// 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;

View File

@ -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 <UIKit/UIKit.h>
/* 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<UILayoutSupport> tly_topLayoutGuide;
@property (nonatomic, readonly) id<UILayoutSupport> tly_bottomLayoutGuide;
@end

View File

@ -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<UILayoutSupport>)tly_topLayoutGuide
{
if (self.parentViewController &&
![self.parentViewController isKindOfClass:UINavigationController.class])
{
return self.parentViewController.tly_topLayoutGuide;
}
else {
return self.topLayoutGuide;
}
}
- (id<UILayoutSupport>)tly_bottomLayoutGuide
{
if (self.parentViewController &&
![self.parentViewController isKindOfClass:UINavigationController.class])
{
return self.parentViewController.tly_bottomLayoutGuide;
}
else {
return self.bottomLayoutGuide;
}
}
@end

View File

@ -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 = "<group>"; };
828F57481949C37B009EB8DD /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
828F574A1949C37B009EB8DD /* TLYShyNavBarDemoTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TLYShyNavBarDemoTests.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 */
/* 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 */,

View File

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