Fix - Room member details: the member's avatar is cropped in the header

Define directly the navigation titleView with the custom title view instance. Do not use anymore a container.
We had to add some constraints  to keep the custom title at the right position.
This commit is contained in:
Giom Foret
2017-09-25 16:56:18 +02:00
parent 8b84afe33e
commit c834cd3ccd
2 changed files with 98 additions and 56 deletions
+46 -17
View File
@@ -40,27 +40,56 @@
if (self.superview)
{
// Center horizontally the avatar into the navigation bar
CGRect frame = self.superview.frame;
UINavigationBar *navigationBar;
UIView *superView = self;
while (superView.superview)
if (@available(iOS 11.0, *))
{
if ([superView.superview isKindOfClass:[UINavigationBar class]])
// Force the title view layout by adding 2 new constraints on the UINavigationBarContentView instance.
if (self.superview.clipsToBounds)
{
navigationBar = (UINavigationBar*)superView.superview;
break;
NSLayoutConstraint *topConstraint = [NSLayoutConstraint constraintWithItem:self
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:self.superview
attribute:NSLayoutAttributeTop
multiplier:1.0f
constant:0.0f];
NSLayoutConstraint *centerXConstraint = [NSLayoutConstraint constraintWithItem:self
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:self.superview
attribute:NSLayoutAttributeCenterX
multiplier:1.0f
constant:0.0f];
[NSLayoutConstraint activateConstraints:@[topConstraint, centerXConstraint]];
// Do not crop the avatar
self.superview.clipsToBounds = NO;
}
}
else
{
// Center horizontally the avatar into the navigation bar
CGRect frame = self.superview.frame;
UINavigationBar *navigationBar;
UIView *superView = self;
while (superView.superview)
{
if ([superView.superview isKindOfClass:[UINavigationBar class]])
{
navigationBar = (UINavigationBar*)superView.superview;
break;
}
superView = superView.superview;
}
superView = superView.superview;
}
if (navigationBar)
{
CGSize navBarSize = navigationBar.frame.size;
CGFloat superviewCenterX = frame.origin.x + (frame.size.width / 2);
self.memberAvatarCenterXConstraint.constant = (navBarSize.width / 2) - superviewCenterX;
if (navigationBar)
{
CGSize navBarSize = navigationBar.frame.size;
CGFloat superviewCenterX = frame.origin.x + (frame.size.width / 2);
self.memberAvatarCenterXConstraint.constant = (navBarSize.width / 2) - superviewCenterX;
}
}
}
}