Tag: uicollectionview

在iOS上,您可以使用UICollectionViewFlowLayout来获得垂直列布局吗?

UICollectionViewFlowLayout在一行中从左到右,然后换行到下一行。 我想要一个从上到下的布局,然后回到下一个列。 把它想象成一个UITableView,它包装成多个水平滚动的列。 UICollectionViewFlowLayout是接近我想要的 – 我可以inheritance它,或者我必须inheritanceUICollectionViewLayout并从头开始? ( 这个答案让我相信我不能使用stream布局。) Visible Screen [ 1 6 11 ] 16 [ 2 7 12 ] 17 [ 3 8 13 ] 18 [ 4 9 14 ] [ 5 10 15 ]

Swift 2 – 调用`didDeselectItemAtIndexPath`时发生致命错误

我有一个UICollectionView我使用函数didSelectItemAtIndexPathselect一个单元格,并更改其alpha。 在UICollectionView有12个单元格。 为了将取消选中的单元格返回到alpha = 1.0我使用函数didDeselectItemAtIndexPath 。 到目前为止,代码工作,但是,当我select一个单元格,并滚动UICollectionView应用程序崩溃在线let colorCell : UICollectionViewCell = collectionView.cellForItemAtIndexPath(indexPath)! 里面的错误取消selectfunction: 致命错误:意外地发现零,而解包一个可选的值(lldb) 我想我需要重新加载收集视图,但如何重新加载并保持单元格select? override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) { let colorCell : UICollectionViewCell = collectionView.cellForItemAtIndexPath(indexPath)! colorCell.alpha = 0.4 } override func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath) { let colorCell : UICollectionViewCell = collectionView.cellForItemAtIndexPath(indexPath)! colorCell.alpha = 1.0 }

滚动水平和垂直两个方向

我有要求滚动水平和垂直的图像。 我有segregated vertically部分, in each section itself it will be so many images which will be scrolled horizontally 。 我使用Ray wenderlich教程使用UICollectionView进行垂直滚动,但是如何在每个部分中获得水平滚动? 我应该使用任何其他对象,如UITableView或UIScrollview为此目的? 任何教程可用如何实现这一目标? Is it compulsory to implement Layout subclass or UICollectionviewFlowlayout when using collection view ? 编辑 到目前为止,我已经实现了这个垂直滚动的代码,每个代码有5个部分,但不能够滚动单个部分 – (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section; { NSArray *arrayReturn = [self returnArray:section]; return arrayReturn.count; } – (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView […]

用附加控件注释UICollectionViewselect的devise

使用UICollectionView和在这里给出的StackOverflow的优秀帮助,我已经能够为我的iPhone构build一个“甘特图”风格控制: 除了化妆品(我现在正在做function,我有一个graphicsdevise师可以看看颜色和所有这些)。 除了背景之外,使用自定义UICollectionViewLayout子类的跨度相对比较简单。 每个跨度是一个item 。 但是我需要添加一些function,并且不确定如何继续。 我试图去的地方大致如下: 撇开粗略的化妆品,重点是我想“注释”,无论目前select的跨度与额外的信息(我保证找人帮我看起来很漂亮)。 而且我希望它们是活跃的,我不确定它是否会引起编辑控制或拖动,但是我希望能够识别数字或粗线上的手势,并且使用它们进行操作,与触摸不同驱动select的跨度。 我可以想到(至less)3种方式来尝试和实现这个: 使用补充意见。 导致selectinvalidateLayout ,在我的prepareLayout检测选中的状态,并为两个锚点生成额外的布局属性。 实现绘制UICollectionReusableView的子类,并添加可触摸的子视图(或其自己的手势识别器)。 这感觉…错了。 我认为补充视图更多的是页眉和页脚,而不是随着select状态的变化而出现的控件。 但也许这是该设施的适当扩展? 使用我当前的SpanCell类(它是UICollectionViewCell一个子类)的backgroundView (或selectedBackgroundView ,不知道它的问题)。 只要我禁用clipsToBounds ,我可以绘制围绕bounds的注释。 我将不得不透露一些大局的知识以find终点,但那不是太冒犯。 我只是显示/隐藏这个视图来响应select的改变。 这似乎是最好的办法。 在整个UICollectionView的主backgroundView中进行。 如图所示,我已经有了一个专门的backgroundView ,它显示了当前的时间网格,条forms。 我可以进一步扩展这个视图来绘制注释和pipe理可触摸的子控件来响应select的改变。 这会给我最直接的实现,但感觉就像一个巨大的怪物“为了背景做了太多的工作”。 问题是,对于那些有更多经验的人,你会走哪条路? 会不会是以上3个之一? 或者不同的东西? 为什么?

在Scrolling Filmstrip中的每个UICollectionViewCell中调用UIButton

这是对我以前的一个后续问题,这次我在每个UICollectionViewCell中添加了UIButton的问题。 在深入研究这个问题之前,让我把目前所有的情况都介绍给大家。 以下是我的UICollectionView在UITableView中的Scrolling Filmstrip样式的工作原理的基本概要: 用一个自定义的UITableViewCell创build一个普通的UITableView 创build一个将被添加到单元格的contentView的自定义UIView 自定义UIView将包含一个UICollectionView 自定义UIView将成为UICollectionView的数据源和委托,并pipe理UICollectionView的stream布局 使用自定义UICollectionViewCell来处理收集视图数据 使用NSNotification通知主控制器的UITableView何时已经select一个集合视图单元并加载详细视图。 到目前为止,我已经能够在每个UICollectionViewCell中添加UIButton,并且当我点击UIButton时,它的图像将变成勾选标记,但是当我向上/向下滚动时会出现问题。 一旦带有选中标记UIButton的单元格离开屏幕并再次在屏幕上滚动,UIButton图像就开始混乱了。 例如,当单元格1中的UIButton图像应该被选中标记但不是。 相反,选中标记会出现在另一个单元格中。 下面是我的相关代码: – (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { PostsCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PostsCollectionViewCell" forIndexPath:indexPath]; NSDictionary *cellData = [self.collectionData objectAtIndex:[indexPath row]]; cell.postTextLabel.text = [cellData objectForKey:@"text"]; cell.locationNameLabel.text = [cellData objectForKey:@"locationName"]; // >>> Select Button <<< UIButton *selectButton = [UIButton buttonWithType:UIButtonTypeCustom]; [selectButton setFrame:CGRectMake(110, 150, […]

带有UICollectionView的NSFetchResultController与索引/单元格有关的更新和删除操作

第一次,我使用UICollectionView,我有一些困难。 特别是更新和删除单元格(将重点放在这里删除,希望NSFetchResultController ),从NSFetchResultController数据。 我在界面生成器中创build了一个自定义单元格,作为这样一个故事板的一部分: 我有一个自定义的UICollectionViewCell子类具有以下属性: @property (strong, nonatomic) IBOutlet UIButton *deleteButton; @property (strong, nonatomic) IBOutlet UITextField *textField; @property (strong, nonatomic) IBOutlet UIView *containerView; @property (strong, nonatomic) IBOutlet UIView *textFieldContainer; 在IB中,我将单元类设置为自定义类,将元素连接到自定义类的属性,并将标识设置为Cell 。 在我的集合视图视图控制器中,我设置了集合视图和fetchResultController以及相关的方法,如下所示: – (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return [[self.fetchedResultsController sections] count]; } – (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { id <NSFetchedResultsSectionInfo> sectionInfo = [self.fetchedResultsController sections][section]; return [sectionInfo numberOfObjects]; […]

UICollectionView水平设置标题时应用程序崩溃

我在UICollectionView中很新。 我真的很难find解决办法。 我正在试图在3水平行中添加标题。 我正在使用集合视图stream布局。 这是我执行的代码: – (void)awakeFromNib { self.collectionView.backgroundColor = [UIColor colorWithRed:204.0/255.0 green:204.0/255.0 blue:204.0/255.0 alpha:1.0]; self.collectionView.backgroundColor = [UIColor clearColor]; self.collectionView.backgroundView = [[UIView alloc] initWithFrame:CGRectZero]; UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal; flowLayout.itemSize = CGSizeMake(130.0, 170.0); [self.collectionView setCollectionViewLayout:flowLayout]; // Register the colleciton cell [_collectionView registerNib:[UINib nibWithNibName:@"ORGArticleCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"ORGArticleCollectionViewCell"]; [self.collectionView registerClass:[_HeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView"]; } […]

当superview有手势时,collectionView没有调用didSelectItemAtIndexPath

当superview有tapGesture.is时,collectionView没有调用didSelectItemAtIndexPath为什么? 为什么根据响应者链打印“doGesture”? initCollectionView然后添加到self.view 在self.view中使用addTapGesture 点击iPhone中的项目。 不要调用didSelectItemAtIndexPath。 – (void)viewDidLoad { [super viewDidLoad]; UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; self.collectionView = [[MyCollectionView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height – 100) collectionViewLayout:flowLayout]; [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"abc"]; self.collectionView.delegate = self; self.collectionView.dataSource = self; [self.view addSubview:self.collectionView]; UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doGesture)]; tapGesture.delegate = self; [self.view addGestureRecognizer:tapGesture]; } […]

在UITableView中的滚动Filmstrip中的每个UICollectionViewCell中添加UIButton

首先,让我描述一下迄今为止的情景。 以下是我的UICollectionView在UITableView中的Scrolling Filmstrip样式的工作原理的基本概要: 用一个自定义的UITableViewCell创build一个普通的UITableView 创build一个将被添加到单元格的contentView的自定义UIView 自定义UIView将包含一个UICollectionView 自定义UIView将成为UICollectionView的数据源和委托,并pipe理UICollectionView的stream布局 使用自定义UICollectionViewCell来处理收集视图数据 使用NSNotification通知主控制器的UITableView何时已经select一个集合视图单元并加载详细视图。 到目前为止,我已经能够创build上面描述的那些,但正如你可以在图片中看到的,我也想在每个UICollectionViewCell中添加一个UIButton,这样当我点击UIButton时,它的图像将会变成标记和数据在这个UICollectionViewCell将被保存到一个数组中。 最后,当我点击右上angular的三angular形button,它会推动到另一个视图与arrays,保存选定的数据传递。 这里是我所有的相关课程: UITableView的 ViewController.h ViewController.m 的UIView ContainerCellView.h ContainerCellView.m UICollectionViewCell CollectionViewCell.h CollectionViewCell.m 的UITableViewCell ContainerCell.h ContainerCell.m 我的问题是,我不能让我的UIButton至less显示(现在)下面的代码: ContainerCellView.m – (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CollectionViewCell" forIndexPath:indexPath]; NSDictionary *cellData = [self.collectionData objectAtIndex:[indexPath row]]; … // >>> Select Button <<< UIButton *button = (UIButton […]

在UICollectionView上animation自动布局约束更改

继上一个问我问,我试图animationUICollectionView (这是在例子中的UICollectionView高度变化。 通过使用以下代码修改集合视图上的自动布局约束来触发高度更改: – (IBAction)expandYellowBox:(id)sender { [UIView animateWithDuration:0.5 animations:^{ self.yellowBoxHeightConstraint.constant += 50; [self.view layoutIfNeeded]; }]; } 但是,当我调用[self.view layoutIfNeeded]这会导致集合视图被重新加载,所以它闪烁显示给用户。 不过,我不希望收集视图重新加载,而只是为了animation的高度变化。 有没有办法避免-layoutIfNeeded重新加载集合视图,或者另一种方法来animation约束高度变化,这不会调用具有重新加载集合视图的副作用的方法?