Tag: uicollectionviewcell

我怎样才能重写Swift中的SuperClass与XCode 6.3 Beta2的setter?

我的SuerClass是UICollectionViewCell它有一个属性: var selected: Bool 我的课是 MyClass : UICollectionViewCell { func setSelected(selected: Bool) { super.selected = selected // do something } } 前者在XCode 6.2中运行良好,但在XCode 6.3Beta2中却引发了一个错误: Method 'setSelected' with Objective-C selector 'setSelected:' conflicts with setter for 'selected' from superclass 'UICollectionViewCell' with the same Objective-C selector 我怎样才能解决这个问题,使用XCode 6.3 beta2? 编辑:我也试过 override func setSelected(selected: Bool) { super.selected = selected […]

collectionview与水平滚动与多个部分

我想开发这样的屏幕(目标C): 在这里有部分名称: 我们爱的新游戏 我们爱的新应用程序 两者都有水平滚动和相互独立。 我的问题是我应该用什么方式来实现这个从下面两个选项。 请提供任何参考样本(如果有): 我可以用单个UICollectionView实现相同的行为,并具有不同的部分(dynamic)。 但不同部分的卷轴应该是独立的。 因为有可能第1部分可能具有不同数量的项目(行),第2部分可能具有不同数量的项目(行) 我必须采取多个collectionview以编程方式插入然后在uiscrollview(垂直scrollview)。 abd然后定义水平滚动并通过收集collectionview来添加单元格中的项目。 目前我用下面的代码做了水平滚动的collectionview: – (void)viewDidLoad { [super viewDidLoad]; self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init]; _collectionView=[[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:layout]; [_collectionView setDataSource:self]; [_collectionView setDelegate:self]; [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cellIdentifier"]; [_collectionView setBackgroundColor:[UIColor redColor]]; [self.view addSubview:_collectionView]; // Do any additional setup after loading the view, […]

如何在IOS中以编程方式滚动UICollectionViewCell?

我有一个垂直UICollectionView与每个单元格占用整个self.view.frame我可以轻松地向上滑动页面到下一个单元格,但我想按button做同样的事情。 我试过使用: – (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated 和: – (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated 他们的工作,但他们暂时“消灭”当前细胞呈现下一个细胞,而滑动显示在过渡期间的两个单元格。 理想情况下,我想使用: – (void)scrollToItemAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UICollectionViewScrollPosition)scrollPosition animated:(BOOL)animated 但我不知道如何访问nextCell的indexPath …我试过了: NSIndexPath *nextIndexPath = [_collectionView indexPathForItemAtPoint:CGPointMake(25, (_collectionView.frame.size.height-25)*(_currentIndexRowForCellOnScreen+1))]; 其中_currentIndexRowForCellOnScreen是indexPath.row在屏幕上首次出现的UICollectionView : – (UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 但是当我把它放入: – (NSIndexPath *)indexPathForCell:(UICollectionViewCell *)cell 它在第一个Cell之后返回NULL,并且不animation…. 任何方向将不胜感激。 感谢您的时间。

只有捏住单元格的imageView时,才能放大/缩小UICollectionView的自定义单元格中的UIImageView?

我有一个CollectionView有一个自定义单元格。 我想放大/缩小imageView在单元格中,所以我添加在CollectionView.m捏手势 当我添加手势self.collectionView,像这样: [self.collectionView addGestureRecognizer:pinchGesture]; 有用! 我的cell.imageView可以放大/缩小,但是当我捏别的地方(不是在单元格的imageView,我的cell.imageView仍然放大/缩小手势,我想cell.imageView放大/缩小只是当用户捏cell.imageView,所以我尝试添加手势使用此代码: [cell.imageView addGestureRecognizer:pinchGesture]; 但不幸的是它不工作。 当我捏住单元格的imageView时,什么也没有发生。 所以我的问题是,是有可能放大/缩小单元格的imageView只有当用户捏小区的imageView? 而不是其他地方。

UICollection View调整屏幕大小的单元大小

目前我有一个采集视图占用我的大部分屏幕在3.5英寸的屏幕大小。集合视图是从顶部51像素,从屏幕的底部20像素。 我正在使用UIPageControl的单元UIPageControl来创build分页布局,每页一个单元格。 当切换到4英寸的大小,使用约束我可以得到collections视图扩大到新的空间(保持51像素从顶部和20从底部),但单元格大小保持不变,所以现在有一堆在单元格顶部和底部的空白空间。 我尝试使用约束,但似乎你不能为单元格设置它们。 如何扩大单元尺寸以填充iPhone 5上的空白空间? 集合视图代码是刚刚 – (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { MyCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath]; return cell; } 布局在IB中设置我想在添加更多内容之前先让布局工作

如何用indexpath.row从UICollectionView中删除一个项目

我有一个集合视图,我试图从didSelect方法的集合视图中删除一个单元格。我成功地使用了下面的方法 [colleVIew deleteItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]]; 但现在我需要删除button上的项目单击CollectionView Cell.Here我只得到indexpath.row。 从这我不能删除项目。 我试过这样 -(void)remove:(int)i { NSLog(@"index path%d",i); [array removeObjectAtIndex:i]; NSIndexPath *indexPath =[NSIndexPath indexPathForRow:i inSection:0]; [colleVIew deleteItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]]; [colleVIew reloadData]; } 但是需要重新加载CollectionView,所以删除后的单元格排列animation就不存在了。 请提出一个想法..提前感谢

我如何定制我的UICollectionViewCell子类的select状态?

我有一个自定义的UICollectionViewCell子类覆盖initWithFrame:和layoutSubviews设置其视图。 但是,我现在正在尝试做两件事情,我遇到了麻烦。 1)我试图在select时自定义UICollectionViewCell的状态。 例如,我想更改UICollectionViewCell中的UIImageView中的一个图像。 2)我想animation( UICollectionViewCell )在UICollectionViewCell的UIImage 。 任何人都可以指向正确的方向吗? – (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { MyCollectionViewCell *cell = (MyCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath]; [cell setSelected:YES]; }

如何在UISollectionViewCell中使用UILongPressGestureRecognizer?

我想弄清楚当我长按一个单元格时,如何打印UICollectionViewCell的indexPath。 我怎么能在Swift中做到这一点? 我已经看遍了所有的例子如何做到这一点; 在Swift中找不到一个。

减lessUICollectionViewCells之间的空间

目的 我试图减less我的UICollectionViewCells之间的空间 我试过了 我试着inheritanceUICollectionViewFlowLayout并覆盖这个方法: – (NSArray *) layoutAttributesForElementsInRect:(CGRect)rect { NSArray *answer = [[super layoutAttributesForElementsInRect:rect] mutableCopy]; for(int i = 1; i < [answer count]; ++i) { UICollectionViewLayoutAttributes *currentLayoutAttributes = answer[i]; UICollectionViewLayoutAttributes *prevLayoutAttributes = answer[i – 1]; NSInteger maximumSpacing = 4; NSInteger origin = CGRectGetMaxX(prevLayoutAttributes.frame); if(origin + maximumSpacing + currentLayoutAttributes.frame.size.width < self.collectionViewContentSize.width) { CGRect frame = currentLayoutAttributes.frame; […]

设置集合视图单元格的dynamic宽度和高度

其实我想dynamic设置button和button的标题出现dynamic我已经尝试这个,并获得dynamic内容的宽度,但不是设置单元格的宽度和高度。 – (void)viewDidLoad { [super viewDidLoad]; ContentArray = [[NSMutableArray alloc]init]; self.collectionview.delegate = self; self.collectionview.dataSource =self; self.collectionview.backgroundColor = [UIColor clearColor]; [ContentArray addObject:@"Planning"]; [ContentArray addObject:@"Resources"]; [ContentArray addObject:@"Human Resources"]; [ContentArray addObject:@"Agriculture"]; [ContentArray addObject:@"Resources management"]; } – (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return ContentArray.count; } – (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { CollectionViewCell * Cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CollectionViewCell"forIndexPath:indexPath]; [Cell.button setTitle:[ContentArray […]