Tag: uicollectionviewlayout

将缩放缩放添加到UICollectionView

介绍 我将描述我想实现的效果,然后详细说明我目前正在如何实现这一点,以及它现在的行为有什么问题。 我还会提到另外一个我看过的方法,但根本无法工作。 最相关的代码是在问题的底部内联以便快速访问。 您可以下载源代码的压缩文件或将项目作为BitBucket上的Mercurial Repository进行获取。 该项目现在包含下面答案的修复。 如果您想要最初提供的破损版本,则会标记为“初始错误版本” 该项目是一个概念/秒杀的最低限度的certificate,以评估效果是否可行,所以它是相当轻和简单! 期望的效果 该应用程序将显示形成垂直表的大量离散信息行。 该表格将被用户垂直滚动。 这是UITableView标准行为,也可以使用UICollectionView 。 但是,应用程序还必须支持捏缩放。 当你在桌子上缩放变焦时, 所有的线条都应该挤压在一起。 当你拉伸, 所有的线应该分开。 在我的概念certificate中,单个细胞没有resize,只是将它们重新放置在一起或者进一步分开。 这是故意的:我不相信validation这个想法的可行性是至关重要的。 这里的屏幕截图显示了当前App如何缩小和放大: 目前的实施 我正在使用UICollectionView与自定义UICollectionViewLayout子类。 这个布局将UICollectionViewCells定位在屏幕中间的一个很好的正弦波。 每个UICollectionViewCell只是一个容器,用于存放indexPath行的UILabel 。 UICollectionViewLayout子类有一个参数来设置它描述给UICollectionView每个单元格之间的垂直间距,并且调整这个参数允许表格按需要垂直压扁或拉伸。 我的UICollectionViewController子类有一个UIPinchGestureRecognizer 。 当识别器检测到比例变化时, UICollectionView布局中的垂直单元格间距将UICollectionView更改。 没有进一步考虑,缩放将从内容的顶部发生,而不是在触摸手势的中心。 UICollectionView的contentOffset属性在调整期间进行调整以提供此function。 手势识别器还需要适应夹捏时发生的拖动。 这也是通过更改UICollectionView的contentOffset来处理的。 一些额外的代码允许在手指被添加到手势或从手势移除时触摸手势的中心点改变。 请注意,作为UIScrollView子类的UIPanGestureRecognizer具有自己的UIPanGestureRecognizer ,它与我添加的UIPanGestureRecognizer进行交互。 我不确定这是否导致问题。 我添加了代码来禁用UICollectionView的内置滚动在我的捏手势,但这似乎没有太大的区别。 我试图使用gestureRecognizer:shouldRequireFailureOfGestureRecognizer:使我的UIPinchGestureRecognizer失败的内置UIPanGestureRecognizer ,但这似乎停止了我的掐识别器工作。 我不知道这是我是愚蠢的,还是在iOS中的错误。 如前所述,目前的UICollectionViewCell没有resize。 他们只是重新定位。 这是故意的。 我认为这对于validation这个概念并不重要。 什么工作 工作位工作得很好。 您可以上下拖动表格。 在拖动过程中,您可以添加一个手指并开始捏合,然后释放一个手指并继续拖动,然后添加和捏合等。这一切都非常顺利。 在原始的iPhone 5上,它可以顺利地在屏幕上支持> 200视图的捏和平移。 […]

按单元分页UICollectionView,而不是屏幕

我有UICollectionView水平滚动,并且总是有2个单元并排整个屏幕。 我需要滚动停止在一个单元格的开始。 启用分页后,集合视图会一次滚动整个页面,即2个单元格,然后停止。 我需要启用单个单元格的滚动,或者停止在单元格边缘的多个单元格的滚动。 我试图UICollectionViewFlowLayout并实现方法targetContentOffsetForProposedContentOffset ,但到目前为止,我只能打破我的集合视图,并停止滚动。 有没有更简单的方法来实现这个和如何,或者我真的需要实现UICollectionViewFlowLayout子类的所有方法? 谢谢。

减lessUICollectionViewCells之间的空间

目的 我试图减less我的UICollectionViewCells之间的空间 我试过了 我试着inheritanceUICollectionViewFlowLayout并覆盖这个方法: – (NSArray *) layoutAttributesForElementsInRect:(CGRect)rect { NSArray *answer = [[super layoutAttributesForElementsInRect:rect] mutableCopy]; for(int i = 1; i < [answer count]; ++i) { UICollectionViewLayoutAttributes *currentLayoutAttributes = answer[i]; UICollectionViewLayoutAttributes *prevLayoutAttributes = answer[i – 1]; NSInteger maximumSpacing = 4; NSInteger origin = CGRectGetMaxX(prevLayoutAttributes.frame); if(origin + maximumSpacing + currentLayoutAttributes.frame.size.width < self.collectionViewContentSize.width) { CGRect frame = currentLayoutAttributes.frame; […]

设置集合视图单元格的dynamic宽度和高度

其实我想dynamic设置button和button的标题出现dynamic我已经尝试这个,并获得dynamic内容的宽度,但不是设置单元格的宽度和高度。 – (void)viewDidLoad { [super viewDidLoad]; ContentArray = [[NSMutableArray alloc]init]; self.collectionview.delegate = self; self.collectionview.dataSource =self; self.collectionview.backgroundColor = [UIColor clearColor]; [ContentArray addObject:@"Planning"]; [ContentArray addObject:@"Resources"]; [ContentArray addObject:@"Human Resources"]; [ContentArray addObject:@"Agriculture"]; [ContentArray addObject:@"Resources management"]; } – (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return ContentArray.count; } – (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { CollectionViewCell * Cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CollectionViewCell"forIndexPath:indexPath]; [Cell.button setTitle:[ContentArray […]

由于“UICollectionViewLayoutAttributes”而导致集合查看单元格删除时崩溃

我的数据源是一个二维数组,因为我将emojis分成了多个小节。 eg. [[a,b,c,d],[e,f,g],[h,j,k,l,m]] 我的单元格删除代码 – func deleteEmoji(at indexPath: IndexPath) { // Get the bad emoji let emojiToBeDeleted = emojisArray[indexPath.section][indexPath.row] // Delete the emoji from datasource and collection view emojisArray[indexPath.section].remove(at: indexPath.row) stickerCollectionView.deleteItems(at: [indexPath]) // Delete the section from datasource and collection view as its emoji count is zero if emojisArray[indexPath.section].count == 0 { emojisArray.remove(at: indexPath.section) stickerCollectionView.deleteSections(IndexSet(integer: […]

没有UICollectionViewLayoutAttributes实例为-layoutAttributesForSupplementaryElementOfKind:

标题是我得到的错误,我不知道为什么,但这里有一些信息,所以希望有人在这里可以澄清我。 我已经分类了UICollectionViewFlowLayout因为这节省了我在UICollectionViewFlowLayout为单元格自己计算框架(也许这是一个问题?)。 然后,我使用UICollectionViewLayoutAttributes信息来计算一个补充的视图,放置它,我得到我想要的布局。 我使用performBatchUpdates:completion:添加,删除和更新视图。 插入工作正常,但是删除项目出现在标题中显示的错误。 所以我知道为什么错误发生,但我不知道为什么它应该发生 。 用一个例子来说明导致这个问题的场景 从1个项目开始,1个补充视图1个部分 添加两个项目( prepareLayout看3个项目与3补充意见) 删除项目( prepareLayout看到2个视图和2个补充视图) layoutAttributesForSupplementaryViewOfKind:atIndexPath:被调用时要求索引path的属性与部分:0和项目:2 崩溃,因为它要求第三个补充视图的属性,即使早些时候它叫做准备布局设置2个项目和2个补充视图 举手投降,绝望 所以,我所知道的有问题的function是: – (UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryViewOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath { return self.layoutInfo[elementKind][indexPath]; } 这当然是由UICollectionView的内部networking自动调用,所以我不知道为什么它要求在该索引path的补充视图。 任何人有任何想法? 也许这是我如何使用performBatchUpdates:completion:但删除工作正常,直到添加补充意见。 我可以根据需要提供更多的代码/解释。

UICollectionViewstream布局没有固定的行高

如何修改stream布局,以便在较小和较大的单元格之间具有相同的垂直间距(例如,没有固定的行高度/行高度不固定到最大尺寸)? 我想看这个样子

UICollectionViewFlowLayout minimumInteritemSpacing不起作用

我的UICollectionView有两个问题: minimumInteritemSpacing不起作用 它在iOS 6上水平溢出 我设置了这样的布局: UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; layout.itemSize = CGSizeMake(70.0f, 70.0f); layout.scrollDirection = UICollectionViewScrollDirectionVertical; layout.minimumLineSpacing = 0.0f; layout.minimumInteritemSpacing = 0.0f; _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout]; // I set the size of _collectionView in layoutSubviews: // _collectionView.frame = self.bounds; _collectionView.contentInset = UIEdgeInsetsMake(8.0f, 8.0f, 8.0f, 8.0f); 该图显示了iOS 6上的结果(在iOS 7上没有溢出,但列之间的间距仍然不为零) 我试过这个解决schemehttps://gist.github.com/OliverLetterer/5583087 ,但它不能解决我的情况。

我如何dynamic调整UICollectionView中的标题视图?

我有一个UICollectionView中的头(UICollectionReusableCell),其高度需要是可变的。 我怎么能根据内容的高度来调整自己? 我不需要支持iOS 7,Autolayout解决scheme是可取的(如果存在的话)。

UICollectionViewLayout layoutAttributesForElementsInRect和layoutAttributesForItemAtIndexPath

我正在实现一个自定义stream布局。 它有2个主要的方法来重写确定单元格的位置: layoutAttributesForElementsInRect和layoutAttributesForItemAtIndexPath 。 在我的代码中, layoutAttributesForElementsInRect被调用,但是layoutAttributesForItemAtIndexPath不是。 什么决定哪些被调用? layoutAttributesForItemAtIndexPath在哪里被调用?