【问题标题】:Start animation one times for each cell每个单元格启动一次动画
【发布时间】:2014-11-13 15:57:32
【问题描述】:

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

有什么建议吗?

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"];

【问题讨论】:

  • 使用BOOL属性检查动画是否已经播放。

标签: ios cabasicanimation


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2013-08-22
    • 1970-01-01
    • 2020-12-27
    • 1970-01-01
    • 1970-01-01
    • 2020-07-05
    • 1970-01-01
    • 1970-01-01
    • 2016-01-29
    相关资源
    最近更新 更多