From 14aa3e55d172ea4a2acc54406a1a265e04bebfba Mon Sep 17 00:00:00 2001 From: Tobias Hagemann Date: Wed, 20 May 2015 11:44:23 +0200 Subject: [PATCH] Attempt to fix #59, status bar height is not hard-coded anymore, but derived from topLayoutGuide.length --- CSNotificationView/CSNotificationView.m | 18 +++++++++++++----- .../project.pbxproj | 2 ++ .../CSRootViewController.m | 1 + 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/CSNotificationView/CSNotificationView.m b/CSNotificationView/CSNotificationView.m index 4f4fbb0..ad52a81 100644 --- a/CSNotificationView/CSNotificationView.m +++ b/CSNotificationView/CSNotificationView.m @@ -379,10 +379,9 @@ - (void)dismissWithStyle:(CSNotificationViewStyle)style message:(NSString *)mess #pragma mark - frame calculation -//Workaround as there is a bug: sometimes, when accessing topLayoutGuide, it will render contentSize of UITableViewControllers to be {0, 0} -- (CGFloat)topLayoutGuideLengthCalculation +- (CGFloat)topLayoutGuideLengthOfViewController:(UIViewController *)viewController { - CGFloat top = MIN([UIApplication sharedApplication].statusBarFrame.size.height, [UIApplication sharedApplication].statusBarFrame.size.width); + CGFloat top = [self topLayoutGuideOfViewController:viewController].length; if (self.parentNavigationController && !self.parentNavigationController.navigationBarHidden) { @@ -392,6 +391,15 @@ - (CGFloat)topLayoutGuideLengthCalculation return top; } +- (id)topLayoutGuideOfViewController:(UIViewController *)viewController +{ + if (viewController.parentViewController && ![viewController.parentViewController isKindOfClass:UINavigationController.class]) { + return [self topLayoutGuideOfViewController:viewController.parentViewController]; + } else { + return viewController.topLayoutGuide; + } +} + - (CGRect)visibleFrame { UIViewController* viewController = self.parentNavigationController ?: self.parentViewController; @@ -400,7 +408,7 @@ - (CGRect)visibleFrame return CGRectZero; } - CGFloat topLayoutGuideLength = [self topLayoutGuideLengthCalculation]; + CGFloat topLayoutGuideLength = [self topLayoutGuideLengthOfViewController:viewController]; CGSize transformedSize = CGSizeApplyAffineTransform(viewController.view.frame.size, viewController.view.transform); CGRect displayFrame = CGRectMake(0, 0, fabs(transformedSize.width), @@ -417,7 +425,7 @@ - (CGRect)hiddenFrame return CGRectZero; } - CGFloat topLayoutGuideLength = [self topLayoutGuideLengthCalculation]; + CGFloat topLayoutGuideLength = [self topLayoutGuideLengthOfViewController:viewController]; CGSize transformedSize = CGSizeApplyAffineTransform(viewController.view.frame.size, viewController.view.transform); CGRect offscreenFrame = CGRectMake(0, -kCSNotificationViewHeight - topLayoutGuideLength, diff --git a/Example/CSNotificationViewDemo.xcodeproj/project.pbxproj b/Example/CSNotificationViewDemo.xcodeproj/project.pbxproj index dd3b95b..ec98735 100755 --- a/Example/CSNotificationViewDemo.xcodeproj/project.pbxproj +++ b/Example/CSNotificationViewDemo.xcodeproj/project.pbxproj @@ -323,6 +323,7 @@ GCC_PREFIX_HEADER = "CSNotificationViewDemo/CSNotificationViewDemo-Prefix.pch"; INFOPLIST_FILE = "CSNotificationViewDemo/CSNotificationViewDemo-Info.plist"; PRODUCT_NAME = CSNotificationViewDemo; + TARGETED_DEVICE_FAMILY = "1,2"; WRAPPER_EXTENSION = app; }; name = Debug; @@ -337,6 +338,7 @@ GCC_PREFIX_HEADER = "CSNotificationViewDemo/CSNotificationViewDemo-Prefix.pch"; INFOPLIST_FILE = "CSNotificationViewDemo/CSNotificationViewDemo-Info.plist"; PRODUCT_NAME = CSNotificationViewDemo; + TARGETED_DEVICE_FAMILY = "1,2"; WRAPPER_EXTENSION = app; }; name = Release; diff --git a/Example/CSNotificationViewDemo/CSRootViewController.m b/Example/CSNotificationViewDemo/CSRootViewController.m index fdb5517..4c0f4f3 100755 --- a/Example/CSNotificationViewDemo/CSRootViewController.m +++ b/Example/CSNotificationViewDemo/CSRootViewController.m @@ -49,6 +49,7 @@ - (IBAction)showModal:(id)sender modalController.view.backgroundColor = [UIColor whiteColor]; modalController.navigationItem.title = @"Modal"; UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:modalController]; + navController.modalPresentationStyle = UIModalPresentationFormSheet; __weak UIViewController *weakModalController = modalController;