gpt4 book ai didi

ios - CollectionView 方向问题

转载 作者:行者123 更新时间:2023-11-29 13:12:20 25 4
gpt4 key购买 nike

I currently have a collection view with a grid of images on it, when selecting an image this segues to another collection view with a full screen image on it.

为此,我正在使用:

    - (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];
}
}

然后在我的详细 View 中:

- (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];
}

当我旋转到横向时,图像消失并且顶部的标题发生变化,如果我返回网格然后再次选择一个单元格,它将再次转到详细 View ,但标题是针对不同的单元格和图像显示两个不同图像之间的一半。

当我旋转设备时,我也在日志中收到以下消息:

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.

我怎样才能更正它以支持方向。

谢谢

最佳答案

您需要使 Collection View 的布局无效,因为纵向单元格的大小对于横向方向来说太大了。

在您的父级 UIViewController 中编写类似的内容应该可以解决您的问题:

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

关于ios - CollectionView 方向问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16922591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com