Merge pull request #1531 from vector-im/fix_ios_11

Fix - Room member details: the member's avatar is cropped in the header
This commit is contained in:
giomfo 2017-09-25 17:08:59 +02:00 committed by GitHub
commit 391712e2df
2 changed files with 98 additions and 56 deletions

View file

@ -118,34 +118,17 @@
[super viewDidLoad]; [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib. // Do any additional setup after loading the view, typically from a nib.
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)]; if (@available(iOS 11.0, *))
[tap setNumberOfTouchesRequired:1]; {
[tap setNumberOfTapsRequired:1]; // Define directly the navigation titleView with the custom title view instance. Do not use anymore a container.
[tap setDelegate:self]; memberTitleView = [RoomMemberTitleView roomMemberTitleView];
[self.roomMemberNameLabelMask addGestureRecognizer:tap]; self.navigationItem.titleView = memberTitleView;
self.roomMemberNameLabelMask.userInteractionEnabled = YES; }
else
{
self.navigationItem.titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 600, 40)]; self.navigationItem.titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 600, 40)];
memberTitleView = [RoomMemberTitleView roomMemberTitleView]; memberTitleView = [RoomMemberTitleView roomMemberTitleView];
self.memberThumbnail = memberTitleView.memberAvatar;
// Add tap to show the room member avatar in fullscreen
tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
[tap setNumberOfTouchesRequired:1];
[tap setNumberOfTapsRequired:1];
[tap setDelegate:self];
[self.memberThumbnail addGestureRecognizer:tap];
self.memberThumbnail.userInteractionEnabled = YES;
// Need to listen tap gesture on the area part of the avatar image that is outside
// of the navigation bar, its parent but smaller view.
tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
[tap setNumberOfTouchesRequired:1];
[tap setNumberOfTapsRequired:1];
[tap setDelegate:self];
[self.roomMemberAvatarMask addGestureRecognizer:tap];
self.roomMemberAvatarMask.userInteractionEnabled = YES;
// Add the title view and define edge constraints // Add the title view and define edge constraints
memberTitleView.translatesAutoresizingMaskIntoConstraints = NO; memberTitleView.translatesAutoresizingMaskIntoConstraints = NO;
@ -179,7 +162,37 @@
attribute:NSLayoutAttributeTrailing attribute:NSLayoutAttributeTrailing
multiplier:1.0f multiplier:1.0f
constant:0.0f]; constant:0.0f];
[NSLayoutConstraint activateConstraints:@[topConstraint, bottomConstraint, leadingConstraint, trailingConstraint]]; [NSLayoutConstraint activateConstraints:@[topConstraint, bottomConstraint, leadingConstraint, trailingConstraint]];
}
// Handle the member avatar at the view controller level.
self.memberThumbnail = memberTitleView.memberAvatar;
// Add tap gesture on member's name
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
[tap setNumberOfTouchesRequired:1];
[tap setNumberOfTapsRequired:1];
[tap setDelegate:self];
[self.roomMemberNameLabelMask addGestureRecognizer:tap];
self.roomMemberNameLabelMask.userInteractionEnabled = YES;
// Add tap to show the room member avatar in fullscreen
tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
[tap setNumberOfTouchesRequired:1];
[tap setNumberOfTapsRequired:1];
[tap setDelegate:self];
[self.memberThumbnail addGestureRecognizer:tap];
self.memberThumbnail.userInteractionEnabled = YES;
// Need to listen tap gesture on the area part of the avatar image that is outside
// of the navigation bar, its parent but smaller view.
tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
[tap setNumberOfTouchesRequired:1];
[tap setNumberOfTapsRequired:1];
[tap setDelegate:self];
[self.roomMemberAvatarMask addGestureRecognizer:tap];
self.roomMemberAvatarMask.userInteractionEnabled = YES;
// Register collection view cell class // Register collection view cell class
[self.tableView registerClass:TableViewCellWithButton.class forCellReuseIdentifier:[TableViewCellWithButton defaultReuseIdentifier]]; [self.tableView registerClass:TableViewCellWithButton.class forCellReuseIdentifier:[TableViewCellWithButton defaultReuseIdentifier]];

View file

@ -39,6 +39,34 @@
[super layoutSubviews]; [super layoutSubviews];
if (self.superview) if (self.superview)
{
if (@available(iOS 11.0, *))
{
// Force the title view layout by adding 2 new constraints on the UINavigationBarContentView instance.
if (self.superview.clipsToBounds)
{
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 // Center horizontally the avatar into the navigation bar
CGRect frame = self.superview.frame; CGRect frame = self.superview.frame;
@ -64,5 +92,6 @@
} }
} }
} }
}
@end @end