Skip to content

Attempt to fix #59, status bar height is not hard-coded anymore, but derived from topLayoutGuide.length #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions CSNotificationView/CSNotificationView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand All @@ -392,6 +391,15 @@ - (CGFloat)topLayoutGuideLengthCalculation
return top;
}

- (id<UILayoutSupport>)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;
Expand All @@ -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),
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions Example/CSNotificationViewDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions Example/CSNotificationViewDemo/CSRootViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down