Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8890995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:37:37+00:00 2026-06-14T22:37:37+00:00

I would like to start some animation on a UICollectionViewCell when the user taps

  • 0

I would like to start some animation on a UICollectionViewCell when the user taps on a cell. My idea was to select the corresponding cell in didSelectItemAtIndexPath and trigger an animation. However, this doesn’t work:

- (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];
                     }
    ];
}

Actually, the animation starts and ends at the same time (although animateWithDuration is set to 5). Next attempt was to skip the animation and simply set for instance a different border style:

- (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];
}

However, this doesn’t change anything (probably because I have to redraw the cell manually?).

Do you have any ideas how to animate a UICollectionViewCell when the user tapped on it?

Kind regards,
Christian

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:37:38+00:00Added an answer on June 14, 2026 at 10:37 pm

    It would appear that you are obtaining the wrong Cell. Sending the dequeueReusableCellWithReuseIdentifier:forIndexPath: message does not obtain the cell in use in the view at the indexPath in the second parameter, but dequeues a previously used but reusable cell; if no reusable cell is available, a new one is created. See Reference 1 below.

    Replacing:

    ProductCollectionViewCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ProductReuseID" forIndexPath:indexPath];
    

    With:

    ProductCollectionViewCell* cell = [collectionView cellForItemAtIndexPath:indexPath];
    

    In your code above, should give you the proper cell to work with.

    Here is your fist example, rewritten.

    - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath(NSIndexPath *)indexPath
    {
        // animate the cell user tapped on
        UICollectionViewCell  *cell = [collectionView cellForItemAtIndexPath:indexPath];    
        [UIView animateWithDuration:5.0
                delay:0
                options:(UIViewAnimationOptionAllowUserInteraction)
                    animations:^{
                        NSLog(@"animation start");
                        [cell setBackgroundColor:[UIColor colorWithRed: 180.0/255.0 green: 238.0/255.0 blue:180.0/255.0 alpha: 1.0]];
                    }
                    completion:^(BOOL finished){
                        NSLog(@"animation end");
                        [cell setBackgroundColor:[UIColor whiteColor]];
                    }
        ];
    }
    

    References:

    • http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UICollectionView_class/Reference/Reference.html#//apple_ref/occ/cl/UICollectionView
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to replay some animation. I would like to find a component suitable
I would like to start publishing some news articles from time to time. An
I would like only to start some applications dynamically with the package name from
I've been reading about HTML5 and would like to start using some of it,
I would like to add some animation to my main application tile when it
I start learning Silverlight and would like to create some simple game. I am
I would like start with .NET Micro Framework as my hobby project. What hardware
I would like to start an IntentService when pressing on my app widget. I
I would like to start making code patches to Rails. Are there any good
I would like to start a personal project that will give me a lot

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.