diff --git a/Pod/Classes/MWGridViewController.h b/Pod/Classes/MWGridViewController.h index c11088be1..d4bfa5341 100644 --- a/Pod/Classes/MWGridViewController.h +++ b/Pod/Classes/MWGridViewController.h @@ -13,7 +13,7 @@ @property (nonatomic, assign) MWPhotoBrowser *browser; @property (nonatomic) BOOL selectionMode; -@property (nonatomic) CGPoint initialContentOffset; +@property (nonatomic) CGPoint initialContentOffset; // ignored since iOS 11.0 - (void)adjustOffsetsAsRequired; diff --git a/Pod/Classes/MWGridViewController.m b/Pod/Classes/MWGridViewController.m index a41d0b8d5..a1129f916 100644 --- a/Pod/Classes/MWGridViewController.m +++ b/Pod/Classes/MWGridViewController.m @@ -48,7 +48,10 @@ - (id)init { _marginL = 0, _gutterL = 2; } - _initialContentOffset = CGPointMake(0, CGFLOAT_MAX); + if (@available(iOS 11.0, *)) { + } else { + _initialContentOffset = CGPointMake(0, CGFLOAT_MAX); + } } return self; @@ -86,11 +89,14 @@ - (void)viewDidLayoutSubviews { - (void)adjustOffsetsAsRequired { // Move to previous content offset - if (_initialContentOffset.y != CGFLOAT_MAX) { - self.collectionView.contentOffset = _initialContentOffset; - [self.collectionView layoutIfNeeded]; // Layout after content offset change - } - + if (@available(iOS 11.0, *)) { + } else { + if (_initialContentOffset.y != CGFLOAT_MAX) { + self.collectionView.contentOffset = _initialContentOffset; + [self.collectionView layoutIfNeeded]; // Layout after content offset change + } + } + // Check if current item is visible and if not, make it so! if (_browser.numberOfPhotos > 0) { NSIndexPath *currentPhotoIndexPath = [NSIndexPath indexPathForItem:_browser.currentIndex inSection:0]; @@ -111,7 +117,12 @@ - (void)adjustOffsetsAsRequired { - (void)performLayout { UINavigationBar *navBar = self.navigationController.navigationBar; - self.collectionView.contentInset = UIEdgeInsetsMake(navBar.frame.origin.y + navBar.frame.size.height + [self getGutter], 0, 0, 0); + CGFloat navBarBottom = 0; + if (@available(iOS 11.0, *)) { + } else { + navBarBottom = navBar.frame.origin.y + navBar.frame.size.height; + } + self.collectionView.contentInset = UIEdgeInsetsMake(navBarBottom + [self getGutter], 0, 0, 0); } - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { diff --git a/Pod/Classes/MWPhotoBrowser.m b/Pod/Classes/MWPhotoBrowser.m index 0de7faaab..2968f71b5 100644 --- a/Pod/Classes/MWPhotoBrowser.m +++ b/Pod/Classes/MWPhotoBrowser.m @@ -79,7 +79,10 @@ - (void)_initialisation { _recycledPages = [[NSMutableSet alloc] init]; _photos = [[NSMutableArray alloc] init]; _thumbPhotos = [[NSMutableArray alloc] init]; - _currentGridContentOffset = CGPointMake(0, CGFLOAT_MAX); + if (@available(iOS 11.0, *)) { + } else { + _currentGridContentOffset = CGPointMake(0, CGFLOAT_MAX); + } _didSavePreviousStateOfNavBar = NO; self.automaticallyAdjustsScrollViewInsets = NO; @@ -1006,7 +1009,11 @@ - (CGRect)frameForToolbarAtOrientation:(UIInterfaceOrientation)orientation { CGFloat height = 44; if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && UIInterfaceOrientationIsLandscape(orientation)) height = 32; - return CGRectIntegral(CGRectMake(0, self.view.bounds.size.height - height, self.view.bounds.size.width, height)); + CGFloat y = self.view.bounds.size.height - height; + if (@available(iOS 11.0, *)) { + y -= self.view.safeAreaInsets.bottom; + } + return CGRectIntegral(CGRectMake(0, y, self.view.bounds.size.width, height)); } - (CGRect)frameForCaptionView:(MWCaptionView *)captionView atIndex:(NSUInteger)index { @@ -1314,7 +1321,10 @@ - (void)showGrid:(BOOL)animated { // Init grid controller _gridController = [[MWGridViewController alloc] init]; - _gridController.initialContentOffset = _currentGridContentOffset; + if (@available(iOS 11.0, *)) { + } else { + _gridController.initialContentOffset = _currentGridContentOffset; + } _gridController.browser = self; _gridController.selectionMode = _displaySelectionButtons; _gridController.view.frame = self.view.bounds; @@ -1360,9 +1370,12 @@ - (void)hideGrid { if (!_gridController) return; - // Remember previous content offset - _currentGridContentOffset = _gridController.collectionView.contentOffset; - + if (@available(iOS 11.0, *)) { + } else { + // Remember previous content offset + _currentGridContentOffset = _gridController.collectionView.contentOffset; + } + // Restore action button if it was removed if (_gridPreviousRightNavItem == _actionButton && _actionButton) { [self.navigationItem setRightBarButtonItem:_gridPreviousRightNavItem animated:YES]; diff --git a/Pod/Classes/MWPhotoBrowserPrivate.h b/Pod/Classes/MWPhotoBrowserPrivate.h index 5770d6787..03b0dd093 100644 --- a/Pod/Classes/MWPhotoBrowserPrivate.h +++ b/Pod/Classes/MWPhotoBrowserPrivate.h @@ -70,7 +70,7 @@ BOOL _didSavePreviousStateOfNavBar; BOOL _skipNextPagingScrollViewPositioning; BOOL _viewHasAppearedInitially; - CGPoint _currentGridContentOffset; + CGPoint _currentGridContentOffset; // ignored since iOS 11 }