Tag: collectionview

将一个静态单元添加到UICollectionView

我有一个UICollectionView显示数组中的单元格。 我想要第一个单元格是一个静态单元格,作为一个提示,以进入创buildstream程(最终添加一个新的单元格)。 我的做法是将两个部分添加到我的collectionView中,但是我目前无法弄清楚如何在cellForItemAtIndexPath中返回一个单元格。 这是我的尝试: func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { if indexPath.section == 0 { let firstCell = collectionView.dequeueReusableCellWithReuseIdentifier("createCell", forIndexPath: indexPath) as! CreateCollectionViewCell firstCell.imageView.backgroundColor = UIColor(white: 0, alpha: 1) return firstCell } else if indexPath.section == 1 { let cell = collectionView.dequeueReusableCellWithReuseIdentifier("mainCell", forIndexPath: indexPath) as! MainCollectionViewCell cell.imageView?.image = self.imageArray[indexPath.row] return cell } […]

使用CollectionView隐藏单元格

我有一个导航控制器推送到集合视图控制器。 这个collectionView有一个NSArray的图像,我敢肯定,使用方法visibleCells的collectionView中有一些元素。 但是当我启动它时,没有显示单元。 这是我的代码: – (void)viewDidLoad { [super viewDidLoad]; images = [NSArray arrayWithObjects:@"angry_birds_cake.jpg", @"creme_brelee.jpg", @"egg_benedict.jpg", @"full_breakfast.jpg", @"green_tea.jpg", @"ham_and_cheese_panini.jpg", @"ham_and_egg_sandwich.jpg", @"hamburger.jpg", @"instant_noodle_with_egg.jpg", @"japanese_noodle_with_pork.jpg", @"mushroom_risotto.jpg", @"noodle_with_bbq_pork.jpg", @"starbucks_coffee.jpg", @"thai_shrimp_cake.jpg", @"vegetable_curry.jpg", @"white_chocolate_donut.jpg", nil]; } – (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return images.count; } – (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ static NSString *identifier = @"Cell"; UICollectionViewCell *cell; [collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"Cell"]; […]

如何从iOS中的UICollectionViewCell初始化popup视图

我一直在跟着一个使用故事板的iPad应用程序跟踪,而且我一直坚持这个好几天。 如何通过在集合视图中select单元格来启动popup窗口? 主要的问题是越过必须锚定到视图的错误。 该方法似乎是在视图中放置一个虚拟popoverAnchorButton (隐藏,禁用),从它创build一个segue到故事板中的popup视图,将其放置在didSelectItemAtIndexPath ,然后[self performSegue] 。 代码如下所示: – (IBAction)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath [self.collectionView deselectItemAtIndexPath:indexPath animated:NO]; UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath]; CGRect anchorRect = CGRectMake(cell.center.x, cell.center.y, 1.0f, 1.0f); self.popoverAnchorButton.frame = anchorRect; [self performSegueWithIdentifier:@"popoverSegue" sender:self]; } 这可以在应用程序中的其他位置在表格视图中工作,因为故事板让我在视图中放置一个button,以用作定位点。 但是Xcode不允许我在故事板的集合视图中放置一个button或任何其他合适的视图,所以我不能创buildsegue。 以编程方式创buildbutton没有任何帮助,因为我无法从中创buildUIStoryboardSegue,并且从控制器的任何手动延续都会给出关于缺less定位点的相同错误。 有任何想法吗? 我认为另一个path可能是跳过segues并以编程方式实例化popover视图控制器,但这里的障碍是由于我创build的popover视图(因为我使用的是故事板)没有xib而导致的错误。 我是否必须为这个popup视图创build一个单独的xib文件? 这是唯一的select吗?

swift iOS – 在快速滚动后混合了UICollectionView图像

我是swift和iOS编程的新手,但是我已经能够在Xcode中为我的应用程序构build一个基本稳定的启动界面。 CollectionView从我的家庭networking服务器上的csv文件创build的字典数组中抓取图像和文本。 cvs文件包含以下格式的数据(请注意,url已被更改以保护许可的图像): csv文件 csv file is @ url https://myserver.com/csv.txt and contains the following Title";"SeriesImageURL Title1";"https://licensedimage.com/url1 Title2";"https://licensedimage.com/url2 … Title1000";"https://licensedimage.com/url1000 问题是,通过CollectionView快速滚动时,单元格会抓取不正确的图像。 值得注意的是,如果您进行慢速或中速滚动,则在将正确的图像渲染到正确的单元格(单元格的标签文本始终正确,只有图像永远closures)之前,会显示不同的图像。 在发生图像不匹配的情况下,CollectionView中的所有其他单元格也将显示不正确的图像。 例如,单元格1-9将显示Title1-9和正确的Image1-9当滚动缓慢时,单元格19-27将显示Title 19-27,将简要显示Image 10-18,然后显示正确的Image 19-27。 当快速滚动大量的单元格(例如从单元格1-9到单元格90-99)时,单元格90-99将显示标题90-99,将显示图像10-50ish,然后将不正确地保持在图像41-50 (或附近)。 当进一步滚动时,单元格100+将显示正确的标题,但仅显示图像41-50范围内的图像。 我认为这个错误是因为没有正确处理单元重用,图像caching处理不当,或者两者兼而有之。 这也可能是我没有看到作为初学者的iOS /快速程序员的东西。 我试图用完成修饰符实现一个请求,但似乎无法让我的代码设置的方式正常工作。 我将不胜感激任何帮助,以及解释为什么修复程序的工作方式。 谢谢! 相关代码如下。 SeriesCollectionViewController.swift class SeriesCollectionViewController: UICollectionViewController, UISearchBarDelegate { let reuseIdentifier:String = "SeriesCell" // Set Data Source Models & Variables struct seriesModel […]

如何创build具有2个或更多自定义单元格的自定义UICollectionView?

在我的项目中我想使用UICollectionView与自定义单元格,我创build与自定义单元格的集合视图,但我想在我的项目中使用不同大小的自定义单元格我遵循一些教程,但我没有得到它正确的,下面我附上示例我真正在寻找collections视图的屏幕截图。

UICollectionView Objective C中的2个不同的单元大小

我想使用UICollectionView,可以创build以下布局: 正如你所看到的,这个单元有两种不同的尺寸。 一个是行的1/4,另一个是3/4。 有没有可能用UICollectionView创build这种布局? 任何人都可以教我怎么做? 或者是否有任何样品? 我已经学习了很多教程和参考。 但是还是不知道该怎么做 谢谢!

在CollectionView上滑动即可删除

我试图复制滑动删除函数,如在邮件tableview中。 只有这一次,我需要在collectionview上构build它,但是我有点困难。 这是一个水平滚动列表刷卡删除。 我已经得到了刷卡工作,但很难搞清楚我需要如何设置刷卡删除/点击删除或忽略function。 它看起来像下面这样: 所以我使用以下collectionview: func buildCollectionView() { let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout() layout.scrollDirection = .horizontal layout.minimumInteritemSpacing = 0; layout.minimumLineSpacing = 4; collectionView = UICollectionView(frame: CGRect(x: 0, y: screenSize.midY – 120, width: screenSize.width, height: 180), collectionViewLayout: layout) collectionView.dataSource = self collectionView.delegate = self collectionView.register(VideoCell.self, forCellWithReuseIdentifier: "videoCell") collectionView.showsHorizontalScrollIndicator = false collectionView.showsVerticalScrollIndicator = false collectionView.contentInset = […]

你如何设置UICollectionViewanimation的持续时间?

我有一个自定义的stream布局,正在调整单元格的属性,当他们被插入和从以下两个函数从CollectionView中删除,但我无法弄清楚如何调整默认的animation持续时间。 – (UICollectionViewLayoutAttributes *)initialLayoutAttributesForAppearingItemAtIndexPath:(NSIndexPath *)itemIndexPath { UICollectionViewLayoutAttributes* attributes = [self layoutAttributesForItemAtIndexPath:itemIndexPath]; // Assign the new layout attributes attributes.transform3D = CATransform3DMakeScale(0.5, 0.5, 0.5); attributes.alpha = 0; return attributes; } -(UICollectionViewLayoutAttributes *)finalLayoutAttributesForDisappearingItemAtIndexPath:(NSIndexPath *)itemIndexPath{ UICollectionViewLayoutAttributes* attributes = [self layoutAttributesForItemAtIndexPath:itemIndexPath]; // Assign the new layout attributes attributes.transform3D = CATransform3DMakeScale(0.5, 0.5, 0.5); attributes.alpha = 0; return attributes; }

如何以编程方式在UICollectionVIew中插入单元格?

我有一个UICollectionView ,它工作正常,但我想以编程方式添加一些UICollectionViewCells项目到集合视图。 那么我怎么能做到这一点呢? 为了进一步阐明:当我以编程的方式说我的意思是插入一个单元格在运行时,当一个动作被激发,而不是当应用程序被加载(使用viewDidLoad方法)。 我知道模型何时被更新,并且在insertItemsAtIndexPaths:方法中调用了UICollectionView 。 它应该创build一个新的单元格,但不是这样做的,这是抛出一个错误。

强制collectionView只有2行

我必须做一个集合视图,以便不考虑iPhone的大小,我们每行只有2个图像,我们也需要每行和每列之间的边界,如图所示。 我想要这样: