QBImagePicker icon indicating copy to clipboard operation
QBImagePicker copied to clipboard

Photos not scrolled to bottom on iPad

Open IanHoar opened this issue 8 years ago • 3 comments

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?

img_0255

IanHoar avatar May 16 '16 21:05 IanHoar

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.

chrisga avatar Jul 20 '16 01:07 chrisga

I have this problem too. When can it be fixed?

uxight avatar Sep 09 '16 18:09 uxight

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

vinayakparmar92 avatar Oct 26 '16 09:10 vinayakparmar92