From 9109a59410b0e8c8488b0c8df6c13bdf10bd0cb8 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Fri, 12 Sep 2014 17:13:33 -0400 Subject: [PATCH] Fixes for better landscape sizing of avatar cells. --- .../ObjC/iOS/MPPasswordsViewController.m | 2 +- .../ObjC/iOS/MPUsersViewController.m | 32 ++++++++++++++----- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/MasterPassword/ObjC/iOS/MPPasswordsViewController.m b/MasterPassword/ObjC/iOS/MPPasswordsViewController.m index 4a85e432..56653bbc 100644 --- a/MasterPassword/ObjC/iOS/MPPasswordsViewController.m +++ b/MasterPassword/ObjC/iOS/MPPasswordsViewController.m @@ -106,7 +106,7 @@ referenceSizeForHeaderInSection:(NSInteger)section { sizeForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewFlowLayout *layout = (UICollectionViewFlowLayout *)collectionViewLayout; - CGFloat itemWidth = UIEdgeInsetsInsetRect( self.passwordCollectionView.bounds, layout.sectionInset ).size.width; + CGFloat itemWidth = UIEdgeInsetsInsetRect( collectionView.bounds, layout.sectionInset ).size.width; return CGSizeMake( itemWidth, 100 ); } diff --git a/MasterPassword/ObjC/iOS/MPUsersViewController.m b/MasterPassword/ObjC/iOS/MPUsersViewController.m index ad93178f..48ad9016 100644 --- a/MasterPassword/ObjC/iOS/MPUsersViewController.m +++ b/MasterPassword/ObjC/iOS/MPUsersViewController.m @@ -108,9 +108,15 @@ typedef NS_ENUM( NSUInteger, MPActiveUserState ) { [self firedMarqueeTimer:nil]; } -- (void)viewDidLayoutSubviews { +- (void)viewWillLayoutSubviews { - [super viewDidLayoutSubviews]; + [self.avatarCollectionView.collectionViewLayout invalidateLayout]; + [super viewWillLayoutSubviews]; +} + +- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { + + [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration]; [self.avatarCollectionView.collectionViewLayout invalidateLayout]; } @@ -262,15 +268,25 @@ typedef NS_ENUM( NSUInteger, MPActiveUserState ) { #pragma mark - UICollectionViewDelegateFlowLayout +- (CGSize) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout +referenceSizeForHeaderInSection:(NSInteger)section { + + CGSize parentSize = self.avatarCollectionView.bounds.size; + return CGSizeMake( parentSize.width / 4, parentSize.height ); +} + +- (CGSize) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout +referenceSizeForFooterInSection:(NSInteger)section { + + CGSize parentSize = self.avatarCollectionView.bounds.size; + return CGSizeMake( parentSize.width / 4, parentSize.height ); +} + - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { - if (collectionView == self.avatarCollectionView) { - CGSize parentSize = self.avatarCollectionView.bounds.size; - return CGSizeMake( parentSize.width / 2, parentSize.height ); - } - - Throw( @"unexpected collection view: %@", collectionView ); + CGSize parentSize = self.avatarCollectionView.bounds.size; + return CGSizeMake( parentSize.width / 2, parentSize.height ); } #pragma mark - UICollectionViewDataSource