UICollectionView 및 UICollectionViewFlowLayout을 사용하여 포토 갤러리를 만들려고합니다. 아이디어는 세로 스크롤을 사용하여 많은 사진을 그리드에 표시하는 것입니다. 사용자가 하나를 탭하면 페이지가 가로로 전체 화면이됩니다.UICollectionView 포토 갤러리를 전체 화면으로
내 문제는 사용자가 전체 화면 모드에서 장치를 돌릴 때 그리드에서 전체 화면으로 전환 할 때 애니메이션이 매우 못 생기는 것입니다.
두 가지 컬렉션 레이아웃을 사용하여 시도해 보았지만 그 사이를 전환했지만 문제가 남아 있습니다.
누구나이 동작을하는 샘플 응용 프로그램이 있거나이를 수행하는 방법을 알고있는 경우 매우 감사하게 생각합니다.
이것은 내가 가지고있는 것입니다. CollectionView A는 행에있는 사진 3의 격자를 가지고 :
@interface MovieImagesVC() <UICollectionViewDelegateFlowLayout>
@end
@implementation MovieImagesVC {
UICollectionViewFlowLayout *flowLayout;
int currentIndex;
}
- (void)viewDidLoad
{
[super viewDidLoad];
flowLayout = (UICollectionViewFlowLayout *)self.collectionViewLayout;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
if (flowLayout.scrollDirection == UICollectionViewScrollDirectionHorizontal) {
collectionView.pagingEnabled = NO;
flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
[flowLayout setMinimumLineSpacing:10.0f];
if (self.interfaceOrientation == UIInterfaceOrientationPortrait ||
self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
flowLayout.itemSize = CGSizeMake(100.f, 100.f);
}
else {
flowLayout.itemSize = CGSizeMake(105.f, 100.f);
}
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
else {
collectionView.pagingEnabled = YES;
flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
[flowLayout setMinimumLineSpacing:0.0f];
flowLayout.itemSize = CGSizeMake(self.collectionView.frame.size.width, self.collectionView.frame.size.height-20);
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
[self.collectionView.collectionViewLayout invalidateLayout];
[collectionView reloadData];
[self.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionLeft animated:NO];
}
#pragma mark Rotation
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self.collectionView.collectionViewLayout invalidateLayout];
if (flowLayout1.scrollDirection == UICollectionViewScrollDirectionHorizontal) {
if (toInterfaceOrientation == UIInterfaceOrientationPortrait ||
toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
flowLayout1.itemSize = CGSizeMake(self.collectionView.frame.size.height, self.collectionView.frame.size.width-20);
}
else {
flowLayout1.itemSize = CGSizeMake(self.collectionView.frame.size.height, self.collectionView.frame.size.width-20);
}
}
else {
if (toInterfaceOrientation == UIInterfaceOrientationPortrait ||
toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
flowLayout1.itemSize = CGSizeMake(100.f, 100.f);
}
else {
flowLayout1.itemSize = CGSizeMake(105.f, 100.f);
}
}
[self.collectionView reloadData];
CGPoint currentOffset = [self.collectionView contentOffset];
currentIndex = currentOffset.x/(int)self.collectionView.frame.size.width;
}
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:currentIndex inSection:0] atScrollPosition:UICollectionViewScrollPositionLeft animated:NO];
}