Skip to content
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

Switch to using topLayoutGuide to determine vertical offset #208

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 8 additions & 24 deletions Pod/Classes/TSMessage.m
Expand Up @@ -188,19 +188,7 @@ - (void)fadeInCurrentNotification
notificationActive = YES;

TSMessageView *currentView = [self.messages objectAtIndex:0];

__block CGFloat verticalOffset = 0.0f;

void (^addStatusBarHeightToVerticalOffset)() = ^void() {

if (currentView.messagePosition == TSMessageNotificationPositionNavBarOverlay){
return;
}

CGSize statusBarSize = [UIApplication sharedApplication].statusBarFrame.size;
verticalOffset += MIN(statusBarSize.width, statusBarSize.height);
};


if ([currentView.viewController isKindOfClass:[UINavigationController class]] || [currentView.viewController.parentViewController isKindOfClass:[UINavigationController class]])
{
UINavigationController *currentNavigationController;
Expand All @@ -218,25 +206,15 @@ - (void)fadeInCurrentNotification
{
[currentNavigationController.view insertSubview:currentView
belowSubview:[currentNavigationController navigationBar]];
verticalOffset = [currentNavigationController navigationBar].bounds.size.height;
if ([TSMessage iOS7StyleEnabled] || isViewIsUnderStatusBar) {
addStatusBarHeightToVerticalOffset();
}
}
else
{
[currentView.viewController.view addSubview:currentView];
if ([TSMessage iOS7StyleEnabled] || isViewIsUnderStatusBar) {
addStatusBarHeightToVerticalOffset();
}
}
}
else
{
[currentView.viewController.view addSubview:currentView];
if ([TSMessage iOS7StyleEnabled]) {
addStatusBarHeightToVerticalOffset();
}
}

CGPoint toPoint;
Expand All @@ -248,7 +226,13 @@ - (void)fadeInCurrentNotification
{
navigationbarBottomOfViewController = [self.delegate messageLocationOfMessageView:currentView];
}


CGFloat verticalOffset = [[currentView.viewController topLayoutGuide] length];

if ([currentView.viewController isKindOfClass:[UINavigationController class]]) {
verticalOffset += ((UINavigationController *)currentView.viewController).toolbar.frame.size.height;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this works, it doesn't adapt when the top layout guide changes (such as if the user changes the orientation of their device).

}

toPoint = CGPointMake(currentView.center.x,
navigationbarBottomOfViewController + verticalOffset + CGRectGetHeight(currentView.frame) / 2.0);
}
Expand Down