gpt4 book ai didi

ios - 如何只修改从 collectionView 中选择的项目的大小和位置?

转载 作者:行者123 更新时间:2023-11-29 02:14:01 24 4
gpt4 key购买 nike

我有一个 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com