Search code examples
iphonecore-animationuitableview

how to chech rotation of a button


I am developing a app in which i have rotate a delete button when user clicks it as in contacts as follows

[UIView beginAnimations:nil context:nil];

    [UIView setAnimationDuration:.5];

    btn.transform=CGAffineTransformMakeRotation((0.0174532925)*90);

    //put the -ve sign before 30 if you want to rotate the button in the anticlockwise else use this one 

    [UIView commitAnimations];
    selectedRow=btn.tag;
    [self.tableView reloadData];

i want to reload the table when animation is completed how can i do this?


Solution

  • [UIView beginAnimations:@"rotateButton" context:nil];
    [UIView setAnimationDuration:.5];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(myAnimDidStop:finished:context:)];
    btn.transform = CGAffineTransformMakeRotation((0.0174532925)*90);
    [UIView commitAnimations];
    selectedRow = btn.tag;
    

    The delegate method will look like:

    - (void)myAnimDidStop:(NSString *)animID finished:(BOOL)finished context:(void*)ctx {
        if ([@"rotateButton" isEqualToString:animID]) {
            [self.tableView reloadData];
        }
    }
    

    Note that if you're targeting iOS 4 and newer, you could use animations blocks:

    [UIView animateWithDuration:0.5 
                     animations:^{ 
                         btn.transform = CGAffineTransformMakeRotation((0.0174532925)*90);
                         selectedRow = btn.tag;
                     } 
                     completion:^(BOOL finished) { 
                         [self.tableView reloadData]; 
                     }];