From 7bea9fe0021cf0d534fbec8a5d74aa2df059fc8b Mon Sep 17 00:00:00 2001 From: giomfo Date: Mon, 22 Feb 2016 10:36:31 +0100 Subject: [PATCH] BugFix: Chat screen: the room title is missing in landscape mode on iPhone 6+ --- Vector/Views/RoomTitle/RoomAvatarTitleView.m | 25 ++++++++++++++---- Vector/Views/RoomTitle/RoomTitleView.m | 27 +++++++++++++++----- 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/Vector/Views/RoomTitle/RoomAvatarTitleView.m b/Vector/Views/RoomTitle/RoomAvatarTitleView.m index 32bfbbd61..58a08e21b 100644 --- a/Vector/Views/RoomTitle/RoomAvatarTitleView.m +++ b/Vector/Views/RoomTitle/RoomAvatarTitleView.m @@ -39,13 +39,28 @@ if (self.superview) { - // Center horizontally the avatar according to the actual screen center + // Center horizontally the avatar into the navigation bar CGRect frame = self.superview.frame; - CGSize screenSize = [[UIScreen mainScreen] bounds].size; + UINavigationBar *navigationBar; + UIView *superView = self; + while (superView.superview) + { + if ([superView.superview isKindOfClass:[UINavigationBar class]]) + { + navigationBar = (UINavigationBar*)superView.superview; + break; + } + + superView = superView.superview; + } - CGFloat superviewCenterX = frame.origin.x + (frame.size.width / 2); - - self.roomAvatarCenterXConstraint.constant = (screenSize.width / 2) - superviewCenterX; + if (navigationBar) + { + CGSize navBarSize = navigationBar.frame.size; + CGFloat superviewCenterX = frame.origin.x + (frame.size.width / 2); + + self.roomAvatarCenterXConstraint.constant = (navBarSize.width / 2) - superviewCenterX; + } } } diff --git a/Vector/Views/RoomTitle/RoomTitleView.m b/Vector/Views/RoomTitle/RoomTitleView.m index 7436aad39..57ee9daef 100644 --- a/Vector/Views/RoomTitle/RoomTitleView.m +++ b/Vector/Views/RoomTitle/RoomTitleView.m @@ -55,14 +55,29 @@ if (self.superview) { - // Center horizontally the display name according to the actual screen center + // Center horizontally the display name into the navigation bar CGRect frame = self.superview.frame; - CGSize screenSize = [[UIScreen mainScreen] bounds].size; + UINavigationBar *navigationBar; + UIView *superView = self; + while (superView.superview) + { + if ([superView.superview isKindOfClass:[UINavigationBar class]]) + { + navigationBar = (UINavigationBar*)superView.superview; + break; + } + + superView = superView.superview; + } - CGFloat superviewCenterX = frame.origin.x + (frame.size.width / 2); - - // Center the display name - self.displayNameCenterXConstraint.constant = (screenSize.width / 2) - superviewCenterX; + if (navigationBar) + { + CGSize navBarSize = navigationBar.frame.size; + CGFloat superviewCenterX = frame.origin.x + (frame.size.width / 2); + + // Center the display name + self.displayNameCenterXConstraint.constant = (navBarSize.width / 2) - superviewCenterX; + } } }