I would create a subclassed UITableViewCell with the animation methods in it to depict a cell selection. The cell would have a protocol which would notify the delegate when the animation is completed, so the delegate (in this case, your UIViewController) would dismiss the modal only when the cell tells it that the animation is complete.
Step 1 would be to create a delegate protocol in the header of your UITableViewCell with a method like subclassedCellSelected:(NSIndexPath*)myIndexPath
Step 2 would be to have an ivar declared in your cell which stores the index path of the cell. Declare this ivar as a property (and synthesize it, of course) so that when your UIViewController creates the cell in cellForRowAtIndexPath, you can set the indexPath ivar on the cell. This tells the cell it's indexpath position and will be helpful when it's notifying the delegate about it's selection.
Step 3 Would be to implement the actual animation methods:
- (void)startPulse
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDuration:0.1];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(endPulse)];
CGAffineTransform transform = CGAffineTransformMakeScale(0.9, 0.9);
self.transform = transform;
self.alpha = 0.5;
[UIView commitAnimations];
}
- (void)endPulse
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDuration:0.1];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(completeAction)];
CGAffineTransform transform = CGAffineTransformMakeScale(1, 1);
self.transform = transform;
self.alpha = 1;
[UIView commitAnimations];
}
- (void)completeAction
{
if([self.delegate respondsToSelector:@selector(subclassedCellDelegate:)])
[self.delegate subclassedCellSelected:self.indexPath];
}
In the didSelectRowAtIndexPath method in your view controller, you should now call the startPulse method on the cell. You do this as follows:
CustomTableViewCell *myCell = (CustomTableViewCell*)[tableView cellForRowAtIndexPath:indexPath]
[myCell startPulse];
The indexPath to be passed is the one you get from the didSelectRowAtIndexPath callback.
What's going to happen now is that the cell will kick off it's animation methods, and once the animations are complete, will post the delegate callback for subclassedCellSelected.
Your UIViewController should subscribe to the custom cell's protocol and implement the delegate callback method in your class file as follows:
- (void)subclassedCellSelected(NSIndexPath*)cellIndexPath
{
//dismiss the modal here
}
If you need help in setting up a delegate protocol, check my answer here: dismissModalViewController AND pass data back
What this code will end up doing is showing a simple animation where our cell 'bounces' in and out before carrying out the desired action.