Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIView animation for CGAffineTransformMake not working

I have a simple transform animation that moves a UITableViewCell 70 pixels to the left. In the if part, the animation works just fine and I get a smooth transition. However, when the function is called again to put the cell back in its original position, which is the else part, I get no animation. It just returns back to normal but without animation. How can I fix this?

 if([[slideArray objectAtIndex:indexPath.row] intValue]==0)
    {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.4];
        selectedCell.transform=CGAffineTransformMakeTranslation(-70, 0);
        [UIView commitAnimations];
        [slideArray replaceObjectAtIndex:indexPath.row withObject:[NSNumber numberWithInt:1]];

    }

    else
    {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.4];
        selectedCell.transform=CGAffineTransformMakeTranslation(0, 0);
        [UIView commitAnimations];
        [slideArray replaceObjectAtIndex:indexPath.row withObject:[NSNumber numberWithInt:0]];
    }
like image 276
Snowman Avatar asked Jan 18 '23 15:01

Snowman


1 Answers

try the following animation in else condition this will work fine if you alreadyb have perform translation of if condition....

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.4];
    selectedCell.transform=CGAffineTransformMakeTranslation(70, 0);
    [UIView commitAnimations];
    [slideArray replaceObjectAtIndex:indexPath.row withObject:[NSNumber numberWithInt:0]];

if above code not working for you than try the following

[UIView animateWithDuration:0.5 
                  delay:0
                options:UIViewAnimationOptionBeginFromCurrentState
             animations:(void (^)(void)) ^{
                 myImageView.transform=CGAffineTransformMakeTranslation(-70, 0);
             }
             completion:^(BOOL finished){
                 myImageView.transform=CGAffineTransformIdentity;
             }];
  [slideArray replaceObjectAtIndex:indexPath.row withObject:[NSNumber numberWithInt:0]];

let me know if any issues .. regards.

like image 172
NIKHIL Avatar answered Jan 29 '23 00:01

NIKHIL