2013-06-04 56 views
1

我现在有一个集合视图,上面有图像网格,当选择一个图像时,这个图像会嵌入另一个集合视图上,并带有全屏图像。CollectionView方向问题

要做到这一点,我使用:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
    if ([segue.identifier isEqualToString:@"collectionView"]) 

    { 
     QuartzDetailViewController *destViewController = (QuartzDetailViewController *)segue.destinationViewController; 

     NSIndexPath *indexPath = [[self.collectionView indexPathsForSelectedItems] objectAtIndex:0]; 

     destViewController.startingIndexPath = indexPath; 

     [destViewController.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO]; 

     [self.collectionView deselectItemAtIndexPath:indexPath animated:NO]; 
    } 
} 

,然后在我的局部视图:顶部的变化

- (void)scrollViewDidScroll:(UIScrollView *)scrollView { 
if (_startingIndexPath) { 
    NSInteger currentIndex = floor((scrollView.contentOffset.x - scrollView.bounds.size.width/2)/scrollView.bounds.size.width) + 1; 
    if (currentIndex < [self.quartzImages count]) { 
     self.title = self.quartzImages[currentIndex][@"name"]; 
    } 
} 
} 

- (void)viewWillAppear:(BOOL)animated { 
    [super viewWillAppear:animated]; 

    UICollectionViewFlowLayout *layout = (UICollectionViewFlowLayout *)self.collectionView.collectionViewLayout; 
    layout.itemSize = self.view.bounds.size; 

    [self.collectionView scrollToItemAtIndexPath:self.startingIndexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO]; 
} 

当我旋转为横向图像中消失的标题,如果我返回到网格,然后再次选择一个单元,它会再次继续到详细视图,但标题是针对不同的单元格,并且图像显示两个不同图像之间的一半和一半。

我收到以下消息以及对日志的时候我旋转设备:

2013-06-04 17:39:53.869 PhotoApp[6866:907] the behavior of the UICollectionViewFlowLayout is not defined because: 
2013-06-04 17:39:53.877 PhotoApp[6866:907] the item height must be less that the height of the UICollectionView minus the section insets top and bottom values. 

我怎样才能纠正这种因此它会支持的方向。

感谢

+0

请参阅我的答案在这个岗位http://stackoverflow.com/questions/13902469/ios-6-supportedinterfaceorientations-issue/13902779#13902779 –

+0

仍然无法正常工作,尝试了三种方式,并且仍然存在相同的问题。我也收到了这个警告:2013-06-04 17:39:53.869 PhotoApp [6866:907] UICollectionViewFlowLayout的行为没有定义,因为: 2013-06-04 17: 39:53.877 PhotoApp [6866:907]项目高度必须小于UICollectionView的高度减去顶部和底部值的部分。 – David

回答

1

您需要自纵向细胞的尺寸太大横向无效集合视图的布局。

写这样的事情在你的父UIViewController中应该解决您的问题:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    [self.collectionView.collectionViewLayout invalidateLayout]; 
}