1
#pragma mark Rotation handling methods 

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration: 
(NSTimeInterval)duration { 
NSLog(@"IS ROTATING"); 
// Fade the collectionView out 
[self.collectionView setAlpha:0.0f]; 

// Suppress the layout errors by invalidating the layout 
[self.collectionView.collectionViewLayout invalidateLayout]; 

// Calculate the index of the item that the collectionView is currently displaying 
CGPoint currentOffset = [self.collectionView contentOffset]; 
self.currentIndex = currentOffset.x/self.collectionView.frame.size.width; 
} 

- (void)viewWillLayoutSubviews; 
{ 
[super viewWillLayoutSubviews]; 
UICollectionViewFlowLayout *flowLayout = (id)self.collectionView.collectionViewLayout; 

if (UIDeviceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) { 
    flowLayout.itemSize = CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height); 
} else { 
    flowLayout.itemSize = CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height); 
} 

[flowLayout invalidateLayout]; //force the elements to get laid out again with the new size 
} 


-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 

// Force realignment of cell being displayed 
CGSize currentSize = self.view.bounds.size; 
float offset = self.currentIndex * currentSize.width; 
[self.collectionView setContentOffset:CGPointMake(offset, 0)]; 


NSLog(@"CURRENT bounds: %f",self.view.bounds.size.width); 
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:self.currentIndex inSection:0]; 
[self.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionLeft animated:NO]; 


// Fade the collectionView back in 
[UIView animateWithDuration:0.125f animations:^{ 
    [self.collectionView setAlpha:1.0f]; 
}]; 


} 

이것은 코드입니다. 난 그냥 이미지가 전체 화면을 유지하고 컬렉션보기가 초상화를 준수하고 싶습니다. 셀이 조정하려고하는 것을 볼 수 있지만 콜렉션 뷰 자체의 크기가 조정되지 않습니다. 어떤 제안/수정?회전 중에 UICollectionView가 iPad 화면에 맞지 않습니다.

답변

1

여기서 collectionView에 대해 새 프레임을 설정 했습니까? willAnimateRotationToInterfaceOrientation: duration: 또는 didRotateFromInterfaceOrientation:으로 설정하거나 슈퍼 뷰의 크기와 같으면 크기 조정 마스크를 유연한 너비 또는 높이로 설정하십시오.

viewWillLayoutSubviews에서
_collectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 

같은 위해 가로 및 세로의 itemSize를 설정하는, 그것은 의도?

+0

프레임을'didRotateFromInterfaceOrientation'에 설정했는데 같은 크기가 의도적 인 것이 아니라 작동 시키려고 노력하고있었습니다. – rcpilotp51