Skip to content

Commit

Permalink
Merge pull request nek023#158 from IanHoar/ipad_form_sheet_bug
Browse files Browse the repository at this point in the history
Delay asset controller layout until frame is correct and layout is complete
  • Loading branch information
nek023 authored Mar 1, 2017
2 parents 49b7c6c + 7f79db0 commit 93ba9d5
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions QBImagePicker/QBAssetsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,12 @@ - (void)viewWillAppear:(BOOL)animated

// Scroll to bottom
if (self.fetchResult.count > 0 && self.isMovingToParentViewController && !self.disableScrollToBottom) {
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:(self.fetchResult.count - 1) inSection:0];
[self.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionTop animated:NO];
// when presenting as a .FormSheet on iPad, the frame is not correct until just after viewWillAppear:
// dispatching to the main thread waits one run loop until the frame is update and the layout is complete
dispatch_async(dispatch_get_main_queue(), ^{
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:(self.fetchResult.count - 1) inSection:0];
[self.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionTop animated:NO];
});
}
}

Expand Down

0 comments on commit 93ba9d5

Please sign in to comment.