在select上animationuicollectionview单元格
我已经创build了一个customlayout,并像这样在layoutAttributesForItemAtIndexPath中设置了我的单元格位置属性
attributes.center = CGPointMake((size.width/2 - 100) + 100, (size.height/2 - 150) +100);
我想在选中时为单元格设置animation。 复制我们用initialLayoutAttributesForAppearingItemAtIndexPath
& finalLayoutAttributesForDisappearingItemAtIndexPath
获得的animationfinalLayoutAttributesForDisappearingItemAtIndexPath
。
我想这样做,当一个单元格被选中和取消select。
例如:
单元格A在位置0,0
。 单元格B在位置50,100
。 如果我select单元格B,我想将其设置为0,0
。 同时使单元格A的值为50,100
。 基本上切换位置,但animation。
也许是另一种方法。 只需重写collectionViewCell中的isSelected即可。
override var isHighlighted: Bool { didSet { if isHighlighted { UIView.animate(withDuration: 0.2, delay: 0, options: .curveEaseOut, animations: { // animate highlight }, completion: nil) } else { UIView.animate(withDuration: 0.2, delay: 0, options: .curveEaseOut, animations: { // animate unHighligh }, completion: nil) } } }
在这个postUICollectionView:animation单元大小更改select,你可以看到一个例子如何animation大小的变化。
我通过在我的UICollectionViewDelegate中使用didSelectItemAtIndexPathanimation的属性:
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { [_collectionView.collectionViewLayout invalidateLayout]; UICollectionViewLayoutAttributes *newAttributes = [_collectionView layoutAttributesForItemAtIndexPath:indexPath]; //use new attributes for animation }