Tag: uicollectionviewcell

删除子视图,然后将其添加回来

我有一个渐变子视图的UICollectionViewCell 。 在我的视图控制器,我有buttonsortingCoreData,然后在UICollectionView reloadData() 。 为了避免我的渐变子视图被一次又一次地绘制(就像它发生在过去一样),我在prepareForReuse()实现了removeFromSuperview() prepareForReuse() 。 在那里,我还实现了一个标志,以跟踪渐变的存在,所以当单元格加载时,我仍然添加一个新的渐变。 但是在删除渐变后,我的willMove(toSuperview: )不起作用,并且不显示渐变视图。 我的逻辑有什么问题? class CollectionCell: UICollectionViewCell { @IBOutlet weak var mealImg: UIImageView! @IBOutlet weak var mealTitleLbl: UILabel! @IBOutlet weak var gradientView: UIView! var gradientWasRemoved = false func configureCell(meal: Meal) { mealTitleLbl.text = meal.title let img = meal.getMealImage() mealImg.image = img addGradient() } func addGradient () { […]

在批量更新过程中重复单元格animation

我已经build立了一个collectionView, 通过这里的解决scheme来实现自定义的重新sorting行为 但是,当单元格被快速拖动到新行时,animation会再次显示拖动单元格的原始位置(请参见下文): 我想知道如何才能把拖动的单元格放在被拖动的那一行上,而不是再次显示它的原始单元格的animation。

UICollectionView自定义水平分页布局

[![collectionview example] [1]] [1] 我正在尝试使用集合视图模拟此行为。 我已经开始使用这种方法,并使我更接近。 虽然当我在水平分页CollectionView上进一步向右滑动时,内容会进一步向左移动。 单元之间的间隔也是closures的。 我相信它需要一个自定义的布局,但我不确定。 func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize { return CGSize(width: collectionView.frame.width – 20, height: collectionView.frame.height – 20) }

编程创build一个uicollectionview时使用自定义的init方法

由于故事板的限制,我正在编程创build一个UICollectionView。 这工作都很好,当我想添加一个UICollectionViewCell我做到以下几点: [collectionView registerClass:[Cell class] forCellWithReuseIdentifier:@"ID"]; 我想知道的是如何使用类“Cell”中的自定义init方法,因为我不能做如下的事情: [collectionView registerClass:[[Cell class]init_custom]forCellWithReuseIdentifier:@"ID"]; 问题:如何使用自定义UICollectionViewCell类中的自定义init方法?

有什么办法来知道哪个集合视图单元格在特定点?

我有一个CGPoint,我想知道我的集合视图中的哪个单元格当前包含该点。 有没有简单的方法来做到这一点,或者我必须写我自己的方法?

在单元格使用AutoLayout时设置UICollectionViewCell大小

我有一个dynamic高度的UICollectionViewCell 。 它包含一个UIWebViewasynchronous加载一些内容。 加载后,它需要调整自己的大小以适应其内容。 我通过更改web view的高度约束来进行单元格大小调整。 我也发送一个委托方法到单元格调整的集合view controller ,我需要使布局无效。 但是,我得到有关冲突约束的自动布局错误。 看来收集视图正在尝试调整单元格的大小。 有谁知道如何使这个devise工作?

离开collectionviewcell的奇怪的错误

我有一个由collectionView组成的calendarView 。 这是一个使用math计算导出的自定义calendarView 。 第七行标记星期六,这是假期,所以第七列的所有标签的字体颜色是红色的。 但是,当我滑动或导航到其他日子时,红色标签以无法追踪的随机顺序分散。 截图如下: 这是怎么发生的? 在我的dequeueReusableCell方法中,我将dequeueReusableCell单元格configuration为: cell.isHoliday = (indexPath.row + 1) % 7 == 0 ? true : false 这是我的自定义collectionViewCell假期的逻辑。 @IBOutlet var dateLabel: UILabel! @IBOutlet var englishDateLabel: UILabel! @IBOutlet var tithiLabel: UILabel! var isToday: Bool = false { didSet { self.contentView.backgroundColor = isToday ? Colors.Palette.LightGreen : UIColor.white } } var isHoliday: Bool […]

集合视图单元格多项select错误

我有一个集合视图,我想select多个项目。 为此,我正在使用 – (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { [self.selectedAsset addObject:self.assets[indexPath.row]]; UICollectionViewCell* cell=[self.collectionView cellForItemAtIndexPath:indexPath]; cell.contentView.backgroundColor = [UIColor blackColor]; } 此方法将对象添加到selectedAsset NSMutableArray。 这是cellForItemAtIndexPath方法。 – (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath; { Cell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"MY_CELL" forIndexPath:indexPath]; // load the asset for this cell ALAsset *asset = self.assets[indexPath.row]; CGImageRef thumbnailImageRef = [asset thumbnail]; UIImage *thumbnail = [UIImage imageWithCGImage:thumbnailImageRef]; […]

如何从UIViewController访问UICollectionViewCell的IBOutlets?

我在UIViewController中实现了一个UICollectionView。 标题单元格是在一个单独的.xib文件中创build的,它通过IBOutlets和IBActions在一个单独的.h和.m文件中实现。 其余的单元格在同一个UIVIewController中实现(原因是因为我添加了这个视差效果)。 我想从包含collectionview的视图控制器(RankingViewController)修改标题单元格(CSCellUser.h)中的IBoutlets(标签和button)的信息,我该如何做到这一点? 单元格:CSCellUser.h @interface CSCellUser : UICollectionViewCell @property IBOutlet UILabel *myScoreValueLabel; @property IBOutlet UILabel *myRankingValueLabel; -(IBAction) sendButtonTouchHandler:(id) sender; @end UIViewController:RankingViewController.h @interface RankingViewController : CommonViewController <UICollectionViewDelegate, UICollectionViewDataSource> { } @property IBOutlet UICollectionView *collectionView1; @end 的UIViewController:RankingViewController.m – (void)viewDidLoad { [super viewDidLoad]; //Parallax Effect, UICollectionView // Locate the layout CSStickyHeaderFlowLayout *layout = (id)self.collectionView1.collectionViewLayout; if ([layout isKindOfClass:[CSStickyHeaderFlowLayout […]

如何在didselect上展开collectionview单元以显示更多信息?

我想animation我的collectionview单元格,以便当我触摸它时,一个mapview从它下面滑出,基本上通过将它下面的单元格向下推动,扩展到空间中。 我尝试使用这个: UICollectionView:animation单元大小更改select ,但无法让它正常工作。 在这里,我试过。 – (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { [((FeedCell *)[collectionView cellForItemAtIndexPath:indexPath]) setIsSelected:YES]; [collectionView.collectionViewLayout invalidateLayout]; __weak FeedCell *cell = (FeedCell *)[self.photoCollectionView cellForItemAtIndexPath:indexPath]; // Avoid retain cycles void (^animateChangeWidth)() = ^() { CGRect frame = cell.frame; frame.size = CGSizeMake(frame.size.width, 420); cell.frame = frame; }; // Animate [UIView transitionWithView:[collectionView cellForItemAtIndexPath:indexPath] duration:0.5f options: UIViewAnimationOptionCurveLinear animations:animateChangeWidth completion:nil]; […]