Tag: uicollectionviewlayout

插入到包含页脚的UICollectionView部分的问题

我有一个典型的UICollectionView,它以垂直方式使用UICollectionViewFlowLayout。 我正在使用分页API来填充集合视图。 为了触发下一个页面的下载,我在使用委托时要求页脚布局: – (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{ RDLoadMoreReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"RDLoadMoreReusableView" forIndexPath:indexPath]; view.delegate = self; [view start]; [self loadNextPageOfAssets]; return view; } 这里是我的loadNextPageOfAssets背后的代码: -(void)loadNextPageOfAssets{ __weak RDRadiusGridViewController *weakSelf = self; // Increment page and request assets. They are added to cluster.assets before the completion block is called. self.cluster.pagination.page++; [self.cluster requestAssetsWithCompletionBlock:^(NSArray […]

Swift,以编程方式更改UICollectionViewCell和UILabel(在单元格内)的宽度

我已经设置了一个单元格(UICollectionViewCell)的宽度等于UICollectionView的宽度,我正在尝试与该单元格内包含的UILabel完全相同的事情。 我认为下面的代码正是我想要达到的目标。 所以我在这里读了一些问题,还有几个教程,但我仍然不知道我怎么能做到这一点。 在几个问题中,它是关于使用collectionViewLayout说法,但我真的在如何在我的代码中使用它挣扎。 有任何想法吗? 谢谢! func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { var cell = collectionView.dequeueReusableCellWithReuseIdentifier("myCell", forIndexPath: indexPath) as LocationViewCell cell.locationLabel.text = "Hello there!" // Set cell & label width to 100% let collectionViewWidth = self.collectionView.bounds.size.width cell.frame.size.width = collectionViewWidth // Works cell.locationLabel.frame.size.width = collectionViewWidth // Does NOT 更新1 所以我添加了以下内容: func collectionView(collectionView: UICollectionView, […]

根据UICollectionView中的图像dynamic更改单元大小

我在水平集合视图中显示从服务器接收的dynamic图像。 当我设置collectionview时,我设置了这个: -(void)setupCollectionView{ [self setupPageControlView]; self.screensCollectionView.delegate=self; self.screensCollectionView.dataSource=self; [self.screensCollectionView registerNib:[UINib nibWithNibName:@"FGAppScreensCollectionViewItemCell" bundle:nil] forCellWithReuseIdentifier:@"screenCell"]; UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; [flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal]; [flowLayout setMinimumInteritemSpacing:0.0f]; [flowLayout setMinimumLineSpacing:0.0f]; [flowLayout setItemSize:CGSizeMake(165, 255)]; //[self.screensCollectionView setPagingEnabled:YES]; [self.screensCollectionView setCollectionViewLayout:flowLayout]; } 对于cellForRowAtIndexPath我下载像这样的图像: -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ static NSString *cellIdentifier = @"screenCell"; FGAppScreensCollectionViewItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath]; NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:[self.imageURLArray […]

如何在iOS7上的UICollectionView粘贴标题?

我使用这个解决scheme在集合视图中生成粘滞标题,它在iOS6上运行良好。 但是,在iOS7中,如果选中“在顶栏下方延伸边缘”选项,则标题将粘贴到位于导航栏后面的视图的原点。 所以现在我禁用了这个选项,但是我真的想调整这个解决scheme,使其在边缘扩展的时候能够工作(为了在内容在导航栏后面滚动时具有很好的模糊效果)。 有人可以帮我吗? 还是有人有任何其他的build议来实现相同的目标?

我怎样才能将整个标题视图设置为UICollectionView?

我想将标题设置为集合视图,就像UITableViewController的setTableHeader一样。 我find了在集合视图中设置每个部分头部的方法,但是我找不到如何设置整个头部的头部视图。 苹果对UICollectionViewLayout的说法是:“补充视图呈现数据,但不同于单元格,不同于单元格,用户不能select补充视图,而是使用补充视图来实现给定部分或整个页面的页眉和页脚视图集合视图。补充视图是可选的,它们的使用和布局是由布局对象定义的“,但我不知道如何为整个集合视图实现标题视图。 我试图通过制作一个节标题视图矩形只对第一部分,但它不同于tableHeader的。 在表格视图中,如果我将内容偏移量设置为低于标题,则内容大小会自动扩展,以使标题隐藏,尽pipe存在less量元素。 但在集合视图中,修改内容偏移量只有在存在足够多的滚动元素时才能正常工作。 我试图dynamic扩大内容的大小,当存在一些元素,但它似乎不能正常工作…

UICollectionView contentOffset随自定义布局而变化

我有一个UICollectionView与自定义UICollectionViewLayout(实际上,我使用这个不错的布局 )。 我在viewDidLoad中设置了contentOffset = CGPointZero 。 然而,在viewDidLoad之后,偏移量是-20,内容被按下来,如下所示: (它应该与线路齐平)。 我在界面构build器中加载集合视图布局。 看来我的问题与这个问题非常相似,但是那里的解决scheme并不适合我。 我尝试修改我的布局实现中的collectionViewContentSize ,以确保它始终大于collectionView的大小。 虽然这意味着我可以滚动我的内容(它比collectionView的高度短)并隐藏额外的空间,我也可以向上滚动查看它。 没有什么似乎工作!

UICollectionViewFlowLayout子类在滚动和重新加载时崩溃访问数组

我有一个UICollectionView使用UICollectionViewFlowLayout的自定义子类,使节标题粘贴到屏幕的顶部,而滚动就像UITableView的普通风格。 我的代码是基于这种方法: http://blog.radi.ws/post/32905838158/sticky-headers-for-uicollectionview-using 此外,收集视图设置为当用户滚动到底部时加载更多结果。 也就是说,当用户到达集合视图的底部,一个Web请求加载更多的数据,然后重新加载集合视图,即调用reloadData。 这似乎工作得很好,除了我已经通过testing运行iOS 7和7.1的TestFlight从testing版testing人员那里得到了一些崩溃报告,他们说,当他们向下滚动到底部(即触发更多的结果加载)时偶尔会发生以下情况: *** -[__NSArrayM objectAtIndex:]: index 28 beyond bounds [0 .. 16] PRIMARY THREAD THREAD 0 __exceptionPreprocess objc_exception_throw -[__NSArrayM objectAtIndex:] -[UICollectionViewFlowLayout(Internal) _frameForItemAtSection:andRow:usingData:] -[UICollectionViewFlowLayout layoutAttributesForItemAtIndexPath:usingData:] -[UICollectionViewFlowLayout layoutAttributesForItemAtIndexPath:] -[MyCustomCollectionViewFlowLayout layoutAttributesForItemAtIndexPath:] -[MyCustomCollectionViewFlowLayout layoutAttributesForSupplementaryViewOfKind:atIndexPath:] -[MyCustomCollectionViewFlowLayout layoutAttributesForElementsInRect:] -[UICollectionViewData validateLayoutInRect:]_block_invoke -[UICollectionViewData validateLayoutInRect:] -[UICollectionView layoutSubviews] -[UIView(CALayerDelegate) layoutSublayersOfLayer:] -[CALayer layoutSublayers] 看起来好像当我的自定义stream布局代码调用[self.collectionView numberOfItemsInSection:someSection]来获取节的最后一项的布局属性时,该调用基于新加载的数据返回(例如,在这种情况下, 29项),但默认stream布局的内部仍然使用某种caching的数据(例如,在这种情况下,该部分只有17项)。 不幸的是,我不能自己再现崩溃,甚至有经验的testing者也不能一致地重现崩溃。 任何想法发生了什么?

如何使用UICollectionViewTransitionLayout插入自定义的UICollectionViewLayoutAttributes属性

我有两个使用自定义UICollectionViewLayoutAttributes子类的自定义UICollectionViewLayout对象。 这些自定义属性添加一个属性tintAlpha ,该属性控制附加到每个集合视图单元的色彩叠加视图的不透明度。 我现在想使用UICollectionViewTransitionLayout子类在这两个布局之间转换。 如何configuration转换布局子类以在自定义布局属性上插入自定义tintAlpha属性? 我可以做这样的事情: – (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath { CustomLayoutAttributes *attr = [super layoutAttributesForItemAtIndexPath:indexPath]; CustomLayoutAttributes *fromAttr = (CustomLayoutAttributes *)[self.currentLayout layoutAttributesForItemAtIndexPath:indexPath]; CustomLayoutAttributes *toAttr = (CustomLayoutAttributes *)[self.nextLayout layoutAttributesForItemAtIndexPath:indexPath]; CGFloat t = self.transitionProgress; attr.tintAlpha = (1.0f – t) * fromAttr.tintAlpha + t * toAttr.tintAlpha; return attr; } 但是,这将忽略对当前布局或下一个布局中的initialLayoutAttributesForAppearingItemAtIndexPath: & finalLayoutAttributesForDisappearingItemAtIndexPath:中的属性应用的所有更改,因此实际上并不正确。 据我所知, UICollectionViewTransitionLayout的默认实现确定适当的from / to属性并将它们caching在prepareLayout或layoutAttributesForItemAtIndexPath: 。 在UICollectionViewTransitionLayout上使用一些公共的API将是非常有用的,这样我们就可以从属性对象访问这些对象,就好像我尝试和实现自己的逻辑关于是否使用初始/最终属性vs标准属性与默认实现有一些差异。 […]

UICollectionView和补充视图(标题)

试图添加一个补充视图到我的UICollectionView作为标题。 我有问题得到它的工作。 我使用自定义的UICollectionViewFlowLayout来返回一个contentSize总是至less1像素大于框架(我正在使用UIFreshControl这将只工作,如果UICollectionView滚动,并设置collectionView.contentSize直接什么都不做),并invalidateLayout上sectionInsert和itemSize更改: -(void)setSectionInset:(UIEdgeInsets)sectionInset { if (UIEdgeInsetsEqualToEdgeInsets(super.sectionInset, sectionInset)) { return; } super.sectionInset = sectionInset; [self invalidateLayout]; } -(void) setItemSize:(CGSize)itemSize { if (CGSizeEqualToSize(super.itemSize, itemSize)) { return; } super.itemSize = itemSize; [self invalidateLayout]; } – (CGSize)collectionViewContentSize { CGFloat height = [super collectionViewContentSize].height; // Always returns a contentSize larger then frame so it can scroll and UIRefreshControl will […]

UICollectionVIew:我如何删除顶部第一个单元格的行上的空间

我在Interface Builder中有这样的安排,所有的属性都设置为零。 但是,当我在设备和模拟器上运行它时,它就像这样 细胞上方的空间来自哪里? 所以我尝试在这样的代码中设置UICollectionViewFlowLayout的这些属性 UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; layout.headerReferenceSize = CGSizeZero; layout.footerReferenceSize = CGSizeZero; layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0); layout.minimumInteritemSpacing = 0; layout.minimumLineSpacing = 0; layout.itemSize = CGSizeMake(103, 119); self.calendarView.collectionViewLayout = layout; 但我没有运气。 我怎样才能摆脱这个空间? 谢谢。