Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed content inset issues on iOS 11 #622

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Pod/Classes/MWGridViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
25 changes: 18 additions & 7 deletions Pod/Classes/MWGridViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand All @@ -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 {
Expand Down
25 changes: 19 additions & 6 deletions Pod/Classes/MWPhotoBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion Pod/Classes/MWPhotoBrowserPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
BOOL _didSavePreviousStateOfNavBar;
BOOL _skipNextPagingScrollViewPositioning;
BOOL _viewHasAppearedInitially;
CGPoint _currentGridContentOffset;
CGPoint _currentGridContentOffset; // ignored since iOS 11

}

Expand Down