Wie drehe ich eine UICollectionView ähnlich der Foto-App und halte die aktuelle Ansicht zentriert?

Ich habe eine Fotogalerie-Ansicht, die a verwendetUICollectionView mit einerUICollectionViewFlowLayout, es hatpagingEnabled und scrollt horizontal, wobei jeweils nur eine Ansicht angezeigt wird.

Funktioniert super bis ich versuche es zu drehen ...

Wenn ich das Gerät drehe, wird inwillRotateToInterfaceOrientation:duration: Ich aktualisiere diecollectionView.contentOffset So bleibt es auf dem richtigen Element und ich ändere die Größe der aktuellen Zelle, damit sie in den neuen Dimensionen animiert wird.Das Problem liegt in der Animation zwischen den beiden Zuständen, die 'vorherige' Orientierung wird animiertvon der oberen linken Ecke AND wirft andere Zellen in die Ansicht. Was mache ich falsch, wenn die Ansicht, die außerhalb des Bildschirms animiert wird, FUBAR ist?

So sieht es in Aktion aus:

http://www.smugmug.com/gallery/n-3F9kD/i-BwzRzRf/A (Ignoriere das abgehackte Video, das ist die Schuld von Quicktime: p)

Hier ist meinwillAnimateRotationToInterfaceOrientation:duration:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];

// Update the flowLayout's size to the new orientation's size
UICollectionViewFlowLayout *flow = (UICollectionViewFlowLayout *)self.collectionView.collectionViewLayout;
if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
    flow.itemSize = CGSizeMake(self.collectionView.frame.size.width, self.collectionView.frame.size.height);
} else {
    flow.itemSize = CGSizeMake(self.collectionView.frame.size.width, self.collectionView.frame.size.height);
}
self.collectionView.collectionViewLayout = flow;
[self.collectionView.collectionViewLayout invalidateLayout];

// Get the currently visible cell
PreviewCellView *currentCell = (PreviewCellView*)[self.collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForRow:_currentIndex inSection:0]];

// Resize the currently index to the new flow's itemSize
CGRect frame = currentCell.frame;
frame.size = flow.itemSize;
currentCell.frame = frame;

// Keep the collection view centered by updating the content offset
CGPoint newContentOffset = CGPointMake(_currentIndex * frame.size.width, 0);
self.collectionView.contentOffset = newContentOffset;
}

Soweit mir bekannt ist, kann ich nirgendwo einen Beispielcode finden, der veranschaulicht, wie eine Sammlungsansicht im Stil einer "Fotogalerie" erstellt wird, die sich elegant dreht.

Antworten auf die Frage(3)

Ihre Antwort auf die Frage