Tag: uicollectionview

UICollectionView单元格与图像,点击更改背景

我有一个UICollectionView Custom CollectionView Cells 。 每个细胞上都有一个图像,与整个细胞一样大。 现在我想在用户触摸单元格时突出显示单元格。 首先,我试着用下面的delegate Methods : – (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell* cell = [self.collectionView cellForItemAtIndexPath:indexPath]; cell.contentView.backgroundColor = [UIColor redColor]; } – (void)collectionView:(UICollectionView *)collectionView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath]; cell.contentView.backgroundColor = [UIColor clearColor]; } 但没有任何happend.After我从单元格中删除图像,它完美的工作。 但与图像没有任何反应! 我还可以做些什么?

UICollectionViewCell在滚动时更改单元格大小

我试图创build一个UICollectionView,其中UICollectionViewCell在“离开”顶部或底部的可见区域时被缩小。 在“进入”可见区域时,按比例放大到正常大小。 我一直在尝试一些缩放/animation代码: scrollViewDidScroll() ,但我似乎无法得到正确的。 我的完整function如下所示: func scrollViewDidScroll(scrollView: UIScrollView) { var arr = colView.indexPathsForVisibleItems() for indexPath in arr{ var cell = colView.cellForItemAtIndexPath(indexPath as! NSIndexPath)! var pos = colView.convertRect(cell.frame, toView: self.view) if pos.origin.y < 50 && pos.origin.y >= 0{ cell.hidden = false UIView.animateWithDuration(0.5, animations: { () -> Void in cell.transform = CGAffineTransformMakeScale(0.02 * pos.origin.y, 0.02 * […]

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

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

UICollectionView布局更改的默认animation持续时间是多less?

说我这样做: [self.collectionView setCollectionViewLayout:myNewLayout animated:YES]; 发生animation的持续时间是多less? 我的这个应用是,当这个改变时,我在单元格内animation了图层属性,而且因为层animation不会被UIView的基于块的animation捕捉到,所以我必须用我自己的animation块单独做。

在UICollectionView滚动select错误单元格 – 斯威夫特

我有以下的UICollectionView它由一个types为NSManagedObject的Array填充 问题是,当一个Cell被选中滚动不能正常工作。 当滚动UICollectionView其他单元格获取选中,并取消select。 奇怪的行为。 我认为这是由于滚动后设置不正确的indexPath? 无论如何,我一直在挣扎几个小时,似乎无法把握。 希望有人能指引我正确的方向! fetchedCategory被比较到类别来检查它是否已被选中,如果它们是相同的颜色被颠倒。 func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { var cell = collectionView.dequeueReusableCellWithReuseIdentifier("CategorySelectionCollectionCell", forIndexPath: indexPath) as CategoryCollectionViewCell if fetchedCategories[indexPath.row] == category { cell.categoryLabel?.text = fetchedCategories[indexPath.row].name cell.categoryLabel?.textColor = UIColor.whiteColor() cell.backgroundColor = fetchedCategories[indexPath.row].iconColor as? UIColor collectionView.selectItemAtIndexPath(indexPath, animated: true, scrollPosition: UICollectionViewScrollPosition.None) } else { cell.categoryLabel?.text = fetchedCategories[indexPath.row].name cell.categoryLabel?.textColor = fetchedCategories[indexPath.row].iconColor […]

使用UICollectionViewCell中的UICollectionView

我有一个自定义的UICollectionViewCell,其内容也是一个集合,我想使用UICollectionView来显示其内容。 这可能吗? 我将如何做到这一点? 我做了自定义UICollectionViewCell也inheritance自UICollectionViewDataSource并定义一个UICollectionView内部属性,但事情不能按预期的方式工作。 任何想法?

我需要调用UICollectionView的dequeueCell:从数据源的cellForPath:?

我真的很想提供'静态'单元格到我的UICollectionView,以前用UITableView。 但是我知道,我们的好男孩和女孩必须使用dequeueReusableCellWithReuseIdentifier:forIndexPath:作为我们细胞的工厂。 所以我提出下面的scheme,并要求对其潜力进行反馈。 到目前为止,它正在为我工​​作,但我害怕一个未知的疑难杂症。 #import "MyCellClass.h" @implementation MyViewController { MyCellClass *_cell0; // etc – many are possible. could store in array } -(void)viewDidLoad { // assume MyCellClass has a +nib and +reuseId. The reader understands. [_collectionView registerNib:[MyCellClass nib] forCellWithReuseIdentifier:[MyCellClass reuseId]]; } -(void)viewDidAppear:animated { // this is where the fun begins. assume proper counts coming from […]

dequeueReusableCellWithIdentifier不重复使用单元格

我有一个UICollectionView与自定义单元格的子类UICollectionViewCell 。 在代码中,我做了以下几件事: [self.collectionView_ registerClass:[AHPinterestCell class] forCellWithReuseIdentifier:@"AHPinterestCell"]; 这是在我的cellForItem AHPinterestCell *cell = (AHPinterestCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"AHPinterestCell" forIndexPath:indexPath]; 不过,它似乎并没有重用这个单元格。 在我的每个屏幕收集视图显示约9-10单元格,但是当我做无限滚动然后我调用insertItemsAtIndexPath它调用我的自定义单元格上的initWithFrame方法,而它应该可能重用我已经有的单元格。 为什么是这样? 编辑: 我添加了一个示例演示项目来说明问题,可以在这里find到xcode项目的链接。 当你到达底部的时候,它本质上是做一个无限的滚动,它只是附加更多的东西。 但是当你这样做,它会再次调用init方法。

添加一个简单的UIView作为UICollectionView的头

我有一个UICollectionView 。 我想添加一个标题。 我的标题只会是一个UILabel 。 我有 : 1)在IB中select“部分标题”作为收集视图附件。 2)在IB中创build了一个集合可重用视图,声明为collectionViewHeader 。 3)添加这些行: – (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { if (kind == UICollectionElementKindSectionHeader) { return collectionViewHeader; } return nil; } 但他们从来没有被称为。 我是否必须为该标签创build一个类才能使用 [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header"]; ? 为什么不像UITableView那样简单,只需拖放任何你想要的标题? 事情是如此复杂的UICollectionView …

UICollectionViewController以非零布局参数错误编程崩溃

我正在编程创build一个UICollectionViewController 。 不,我不想使用IB和Storyboard,比如每个教程。 我只是想用简单的代码。 这是我在我的viewDidLoad有什么: // UICollectionView UICollectionViewFlowLayout *aFlowLayout = [[UICollectionViewFlowLayout alloc] init]; [aFlowLayout setItemSize:CGSizeMake(200, 140)]; [aFlowLayout setScrollDirection:UICollectionViewScrollDirectionVertical]; self.collectionView = [[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:aFlowLayout]; [self.collectionView setDelegate:self]; [self.collectionView setDataSource:self]; self.collectionView.backgroundColor = [UIColor clearColor]; [self.collectionView setAutoresizingMask:UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth]; [self.collectionView registerClass:[PUCImageGridCell class] forCellWithReuseIdentifier:CollectionViewCellIdentifier]; 我已经实现了所需的委托方法,我仍然得到这个错误: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'UICollectionView must […]