QBImagePicker
QBImagePicker copied to clipboard
Photos not scrolled to bottom on iPad
We're experiencing an issue on iPad where the photo picker does not scroll to the last item on viewWillAppear
. The issue seems to be caused by the collectionView not having fully laid out by the time scrollToItem:atScrollPosition:animated
is called. The issue is only reproducible on iPad, and only when presented as a formSheet.
One possible workaround is to dispatch to the main thread to wait a run loop for the layout to complete, but I think this just exposes a deeper timing issue.
in viewWillAppear
in QBAssetsViewController
// Scroll to bottom
if (self.fetchResult.count > 0 && self.isMovingToParentViewController && !self.disableScrollToBottom) {
dispatch_async(dispatch_get_main_queue(), ^{
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:(self.fetchResult.count - 1) inSection:0];
[self.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionTop animated:NO];
});
}
Has anyone else encountered this issue, and if so, what was the solution?
Yes, I hit this problem too. I moved those lines to a new method -(void) viewDidLayoutSubviews
which gets called after ViewDidLoad. There were a couple other small changes. It seems to be a timing problem. I can give you the full changes, if you haven't solved it yet.
I have this problem too. When can it be fixed?
A one line fix to this is initialise sortDescriptor with this code to get the newest one
@[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]];
We can remove the scrollToIndex method from viewWillAppear