- Rapid user input messing up UIViewAnimation
- - (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;
- }
- }
- ];
- }