Search code examples
iosobjective-ciphoneuitableviewcatransform3d

UITableViewCell animation breaks UITableView touch detection and scrolling


I was trying to achieve similar to google+ animation on showing new UITableViewCells when they appear for the first time.

This is what I'm doing:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if([[self serverFetchControllerForTableView:tableView] hasDataAtIndexPath:indexPath])
    {
        if (![[self shownIndexesForTableView:tableView] containsObject:indexPath]) {
            [[self shownIndexesForTableView:tableView] addObject:indexPath];

            UIView* view = [cell contentView];
            view.layer.transform = self.initialTransformation;
            view.layer.opacity = 0.0;

            [UIView animateWithDuration:ANIMATION_CELL_APPEARANCE_TIME animations:^{
                view.layer.transform = CATransform3DIdentity;
                view.layer.opacity = 1;
            }];
        }
    }
}

//initial transformation looks like that
CGFloat rotationAngleRadians = ANIMATION_CELL_APPEARANCE_ANGLE_DEG * (M_PI/180);
CATransform3D transform = CATransform3DIdentity;
transform = CATransform3DRotate(transform, rotationAngleRadians, 1.0, 0.0, 1.0);
transform = CATransform3DTranslate(transform, ANIMATION_CELL_APPEARANCE_X, ANIMATION_CELL_APPEARANCE_Y, 0.0);
self.initialTransformation = transform;

Everything works in terms of visuals, but while those cells are appearing, I'm losing complete control of UITableView scrolling - I cannot touch cells, stop scrolling or select any of them, until animation is finished.

Does anyone have any suggestion what I can do better here to fix that problem ?

Same problem can be found here: http://www.raywenderlich.com/49311/advanced-table-view-animations-tutorial-drop-in-cards

Try putting time to 3.0seconds in TipInCellAnimator any for 3.0 control is lost completely.


Solution

  • This is the normal behavior for animations using one of the animateWithDuration... methods. If you want user interaction during the animation, try using animateWithDuration:delay:options:animations:completion: and passing UIViewAnimationOptionAllowUserInteraction as the option. I don't know what that might do to your animation, but it should allow user interaction.