我有一个 Collection View ,当我选择一个项目时,我想放大该图像并添加一个框架。我这样做了,但其余的图像也在移动。这就是我所做的:
- (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;
如何仅修改所选项目的大小和位置?
最佳答案
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;
}
关于ios - 如何只修改从 collectionView 中选择的项目的大小和位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28961171/