UICollectionView insertItem -> adjust animation time?

前端 未结 3 1576
滥情空心
滥情空心 2020-12-29 12:28

So, I have a UICollectionView where I insert new items.

I used the most of the suggestions from the Collection View Programming Guide - section \"Making Insertion an

相关标签:
3条回答
  • 2020-12-29 13:19

    You cannot adjust the animation with the Apple-provided layout methods. If you want to customize the animation you need to hide the item via attributes (just show and empty space), do your animation yourself and an at the end of the animation pop the item back in via attributes.

    I asked a similar question about customizing the moving animation, but the consensus has been what I described. Animate yourself if you need to.

    This question shows how to do a custom removal animation, customzing insertion should be similar: UICollectionView horizontal scrolling, deleting last item, animation not working

    0 讨论(0)
  • 2020-12-29 13:26

    Or just do

    [UIView animateWithDuration:0.5f animations:^(void) {
      [self.collectionView insertItemsAtIndexPaths:@[newIndexPath]];
    }];
    

    The animation duration will affect the internal duration of the collection view insertion animation.

    0 讨论(0)
  • 2020-12-29 13:27

    You can change any animation speed with CALayer. So for UICollectionView this looks like the following:

    [self.collectionView.viewForBaselineLayout.layer setSpeed:0.1f];
    

    And you can change back the original speed:

    [self.collectionView.viewForBaselineLayout.layer setSpeed:1.0f];
    

    For this to work you may need to import QuartzCore:

    #import <QuartzCore/QuartzCore.h>
    
    0 讨论(0)
提交回复
热议问题