0

我正在使用 MCSwipeTableViewCell,所以这个想法是用户向左或向右滑动它来完成操作。但是,用户可能并不总是熟悉此操作,因此当他们点击单元格(期望选择它)时,我希望文本短暂闪烁一个简短的指令,然后返回原始文本。

我已经做了好几天了,一直没有运气。我试过使用完成块,玩延迟,各种但动画似乎完成得太快了你实际上没有看到变化,我做错了什么?

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    [tableView deselectRowAtIndexPath:indexPath animated:NO];

    MCSwipeTableViewCell *cell = (MCSwipeTableViewCell *)[self.tableView cellForRowAtIndexPath:indexPath];
    Station *station = self.recentStations[indexPath.row];

    [UIView animateWithDuration:0.5 animations:^{

        //code to fade the text out
        CATransition *animation = [CATransition animation];
        animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
        animation.type = kCATransitionFade;
        animation.duration = 0.35;
        [cell.textLabel.layer addAnimation:animation forKey:@"kCATransitionFade"];

        //instructions to appear briefly
        cell.textLabel.text = @"Swipe left to set alarm or right to remove";


        //nested animation to revert text after a 1.5 second delay
       [UIView animateWithDuration:.05 delay:1.5 options:UIViewAnimationOptionCurveEaseIn animations:^{

           //code to fade the text back in
           CATransition *animation = [CATransition animation];
           animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
           animation.type = kCATransitionFade;
           animation.duration = 0.35;
           [cell.textLabel.layer addAnimation:animation forKey:@"kCATransitionFade"];
           cell.textLabel.text = station.name;

       } completion:nil];

    }];

}
4

1 回答 1

0

您正在使用重复的嵌套动画 API。试试下面的代码。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];

    MCSwipeTableViewCell *cell = (MCSwipeTableViewCell *)[self.tableView cellForRowAtIndexPath:indexPath];
    Station *station = self.recentStations[indexPath.row];

    [UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        cell.textLabel.alpha = 0.0f;              
    } completion:^(BOOL finished) {
        //instructions to appear briefly
        cell.textLabel.alpha = 1.0f;
        cell.textLabel.text = @"Swipe left to set alarm or right to remove";

        [UIView animateWithDuration:0.5 delay:1.5 options:UIViewAnimationOptionCurveEaseInOut animations:^{
            cell.textLabel.alpha = 0.0f;
        } completion:^(BOOL finished) {
            cell.textLabel.alpha = 1.0f;
            cell.textLabel.text = station.name;
        }];
    }];
}

该代码将立即将新文本换出旧文本并出现 - 如果需要,您可能会弄清楚如何添加更多动画以防止这种情况发生。

于 2013-10-20T19:19:13.337 回答