为每个单元格启动动画一次

时间:2014-11-13 15:57:33

标签: ios cabasicanimation

当用户进行编辑模式时,我使用缩放按钮创建动画。 动画开始但是,当我滚动单元格时,它会重复。

有什么建议吗?

drawRect中的Conde

CABasicAnimation *fullRotation1 = [CABasicAnimation animationWithKeyPath:@"transform.scale"];

        fullRotation1.fromValue = [NSNumber numberWithFloat:0];
        fullRotation1.toValue = [NSNumber numberWithFloat:1];
        fullRotation1.duration = 0.3;
        fullRotation1.repeatCount = 1;
        fullRotation1.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

        [self.deleteButton.layer addAnimation:fullRotation1 forKey:@"scale"];

1 个答案:

答案 0 :(得分:0)

drawRect不是你应该调用动画函数的地方。尝试更像这样的东西:

@interface MyTableViewCell : UITableViewCell

@property (nonatomic, strong) UIButton *deleteButton;
@property (nonatomic, assign) BOOL animationPlayed;

- (void)playAnimation;

@end

@implementation MyTableViewCell

- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    [super setEditing:editing animated:animated];

    if (editing)
    {
        [self playAnimation];
    }
}

- (void)playAnimation
{
    if (self.animationPlayed == NO)
    {
        self.animationPlayed = YES;

        self.deleteButton.transform = CGAffineTransformMakeScale(0.0, 0.0);
        [UIView animateWithDuration:0.3
                              delay:0.0
                            options:UIViewAnimationOptionCurveEaseInOut
                         animations:^{
                             self.deleteButton.transform = CGAffineTransformMakeScale(1.0, 1.0);
                         }
                         completion:nil];
    }
}

@end