我有一个集合视图,当我选择一个项目时,我想要更大的图像并添加一个框架。我这样做,但其余的图像也在移动。这就是我的表现:
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
if ([selectedIndexPath isEqual:indexPath]) {
selectedIndexPath = nil;
[self.player stop];
CollectionViewCell *cellOne = [collectionView cellForItemAtIndexPath:indexPath];
cellOne.inner.hidden=YES;
recipeImageView.frame=CGRectMake(recipeImageView.frame.origin.x, recipeImageView.frame.origin.y, 100, 100);
recipeImageView.layer.borderColor = [[UIColor blackColor] CGColor];
}
else {
// select new cell
celulaSelectata=indexPath;
UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
recipeImageView = (UIImageView *)[cell viewWithTag:100];
CollectionViewCell *cellOne = [collectionView cellForItemAtIndexPath:indexPath];
recipeImageView.frame=CGRectMake(recipeImageView.frame.origin.x, recipeImageView.frame.origin.y, 120, 120);
cellOne.inner.frame=recipeImageView.frame;
如何仅修改所选项目的大小和位置?
答案 0 :(得分:1)
selectedIndexPath
为所选单元格创建UICollectionViewLayoutAttributes
并致电invalidateItemsAtIndexPaths:(NSArray *)indexPaths
更新所选UICollectionViewLayoutAttributes
的单元格
对您的UICollectionViewLayout
进行子类化并在UICollectionViewLayout
中添加功能,并使任何indexPath
无效以更新
- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewLayoutAttributes *attribute = [super layoutAttributesForItemAtIndexPath:indexPath];
if ([indexPath isEqual:selectedIndexPath]) {
//set attributes
//attribute.frame = //setframe;
}
return attribute;
}
答案 1 :(得分:0)
if ([selectedIndexPath isEqual:indexPath])
我认为您必须在cellforRow
方法中编写此部分。
不在didSelectRowAtIndexpath
。