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 8312481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:10:48+00:00 2026-06-08T20:10:48+00:00

I’m making a custom ImagePicker, similar to the usual UIImagePickerController, except that you can

  • 0

I’m making a custom ImagePicker, similar to the usual UIImagePickerController, except that you can tap to select up to 3 photos. As you tap to select the first photo, a small UIView tray will slide in from the bottom and the selected thumbnail will appear there. As you tap to select the 2nd and 3rd photo, they are added to the selected photos tray. If you tap the same photo in the picker, it will be removed from the tray. (Apologies for the magic numbers in the code; I am still testing things out for now)

I’ve attached a cropped photo below to give an idea of how the tray looks with 3 photos correctly selected.

http://dl.dropbox.com/u/762437/screen1.jpg

Everything is working ok if the photos are tapped at a normal speed. However, if the user somehow decided to rapidly tap the photos in a random manner, it occasionally messes up the animation and the placement of the photos on the tray.

I’ve attached an example below. In the example below, there are actually only 2 photos selected, but somehow, the 3rd photo is still partially visible.

http://dl.dropbox.com/u/762437/screen2.jpg

I’m not sure how to to alleviate such behaviours when the user decides to just “mash the buttons”, so to speak.

I thought that maybe it might be good to use @synchronized(self) and wrap the inside of the assetsWasTapped function, but it didnt seem to do anything (assetsWasTapped is called from the main thread).

On occasion, I might see two photos being added to the same position in the tray, which makes me think that there is some timing issue with my NSMutableArray count (selectedPhotos), which I use to determine where each thumbnail should go.

I apologize for the specific question, but perhaps the more general version of it would be how to deal with animations and rapid user input.

Any help would be much, much appreciated. Thank you!

- (void)assetWasTapped:(CustomAsset*)tappedAsset
{
    // The asset thumbnail was tapped.  Check if the count is < 3 and add to the tray
    if([selectedAssets count] < 3)
    {
        NSMutableDictionary *dataToAdd = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                          tappedAsset, @"selectedAsset",
                                          [[tappedAsset.asset defaultRepresentation] url], @"selectedAssetURL",
                                          tappedAsset.indexPath, @"selectedAssetIndexPath",
                                          [NSNumber numberWithInt:[tappedAsset tag]], @"selectedAssetTag", nil];
        [selectedAssets addObject:dataToAdd];
        [self addAssetToSelectedTray:tappedAsset];
    }
}

- (void)addAssetToSelectedTray:(CustomAsset*)tappedAsset
{
    UIView *existingButton;
    int xPos = 30;

    CustomAsset *tempCustomAsset = [[[CustomAsset alloc] initWithAsset:tappedAsset.asset] autorelease];

    // Switch to deal with 1~3 selected assets
    switch ([selectedAssets count]) 
    {  
        case 1:
            tempCustomAsset.frame = CGRectMake(125, 8, 73, 73);
            [selectedPhotosTray addSubview:tempCustomAsset];
            break;
        case 2:
            for(existingButton in [selectedPhotosTray subviews])
            {

                [UIView animateWithDuration:0.1
                                      delay:0.0
                                    options:UIViewAnimationOptionCurveEaseOut 
                                 animations:^{ 
                                     existingButton.frame = CGRectMake(70, 8, 73, 73);
                                 }

                                 completion:^(BOOL  completed){

                                 }
                 ];
            }
            tempCustomAsset.frame = CGRectMake(180, 8, 73, 73);
            [selectedPhotosTray addSubview:tempCustomAsset];
            break;
        case 3:
            for(existingButton in [selectedPhotosTray subviews])
            {

                [UIView animateWithDuration:0.1
                                      delay:0.0
                                    options:UIViewAnimationOptionCurveEaseOut 
                                 animations:^{ 
                                     existingButton.frame = CGRectMake(xPos, 8, 73, 73);
                                 }

                                 completion:^(BOOL  completed){

                                 }
                 ];
                xPos += 95;
            }

            tempCustomAsset.frame = CGRectMake(220, 8, 73, 73);
            [selectedPhotosTray addSubview:tempCustomAsset];
            break;
        default:
            break;
    }
}

- (void)removeAssetFromSelectedTray:(CustomAsset*)tappedAsset
{
    // If the asset was removed, remove from the tray
    [UIView animateWithDuration:0.2
                          delay:0.0
                        options:UIViewAnimationOptionCurveEaseInOut 
                     animations:^{ 
                         tappedAsset.transform = CGAffineTransformMakeScale(0.3, 0.3);
                         tappedAsset.alpha = 0.0;
                     }

                     completion:^(BOOL  completed){
                         [tappedAsset removeFromSuperview];

                         if([selectedAssets count] == 0)
                         {
                             [self closeSelectedPhotosTrayWithAnimation:YES];
                         }

                         int xPos = 70;
                         UIButton *existingButton;
                         switch ([selectedAssets count]) 
                         {
                             case 1:
                                 for(existingButton in [selectedPhotosTray subviews])
                                 {
                                     [UIView animateWithDuration:0.1
                                                           delay:0.0
                                                         options:UIViewAnimationOptionCurveEaseOut 
                                                      animations:^{ 
                                                          existingButton.frame = CGRectMake(125, 8, 73, 73);
                                                      }

                                                      completion:^(BOOL  completed){

                                                      }
                                      ];
                                 }
                                 break;
                             case 2:

                                 for(existingButton in [selectedPhotosTray subviews])
                                 {
                                     [UIView animateWithDuration:0.1
                                                           delay:0.0
                                                         options:UIViewAnimationOptionCurveEaseOut 
                                                      animations:^{ 
                                                          existingButton.frame = CGRectMake(xPos, 8, 73, 73);
                                                      }
                                                      completion:^(BOOL  completed){
                                                      }
                                      ];

                                     xPos += 110;
                                 }            
                                 break;            
                             default:

                                 break;
                         }
                     }
     ];
}
  • 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-08T20:10:50+00:00Added an answer on June 8, 2026 at 8:10 pm

    When something like that happens for me the answer tends to be using the UIViewAnimationOptionBeginFromCurrentState or whatever its named. Don’t have code completion here haha.

    But the could depend on how you’re doing your path. If it has a final resting place then that should fix it.

    The other thing that you could do is set the userInteractionEnabled to NO in the beginning of the animation and then set it back to YES in the completion block to ensure only one animation goes at a time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
We're building an app, our first using Rails 3, and we're having to build

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.