Note that there are some explanatory texts on larger screens.

plurals
  1. POAnimate UICollectionViewCell on Tap
    text
    copied!<p>I would like to start some animation on a <code>UICollectionViewCell</code> when the user taps on a cell. My idea was to select the corresponding cell in <code>didSelectItemAtIndexPath</code> and trigger an animation. However, this doesn't work:</p> <pre><code>- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { // animate the cell user tapped on ProductCollectionViewCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ProductReuseID" forIndexPath:indexPath]; [UIView animateWithDuration:5.0 delay:0 options:(UIViewAnimationOptionAllowUserInteraction) animations:^{ NSLog(@"animation start"); [cell.layer setBackgroundColor:[UIColor colorWithRed: 180.0/255.0 green: 238.0/255.0 blue:180.0/255.0 alpha: 1.0].CGColor]; } completion:^(BOOL finished){ NSLog(@"animation end"); [cell.layer setBackgroundColor:[UIColor whiteColor].CGColor]; } ]; } </code></pre> <p>Actually, the animation starts and ends at the same time (although <code>animateWithDuration</code> is set to 5). Next attempt was to skip the animation and simply set for instance a different border style:</p> <pre><code>- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { // animate the cell user tapped on ProductCollectionViewCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ProductReuseID" forIndexPath:indexPath]; [cell.layer setBorderWidth:5.0f]; } </code></pre> <p>However, this doesn't change anything (probably because I have to redraw the cell manually?).</p> <p><strong>Do you have any ideas how to animate a UICollectionViewCell when the user tapped on it?</strong></p> <p>Kind regards, Christian</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload