小编jei*_*oft的帖子

核心动画 - 未调用animationDidStop

那里.

在iOS应用程序中,Core动画回调不起作用.

- (void)startAnim {
    CABasicAnimation* anim = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    anim.fromValue = startAngle;
    anim.toValue = endAngle;
    anim.duration = 2;
    anim.delegate = self;

    [self.target addAnimation:anim forKey:nil];   // self.target is CALayer instance, it's sublayer of Custom UIView
}

- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag {
   [self.target setValue:@(endAngle) forKeyPath:@"transform.rotation.z"];
}
Run Code Online (Sandbox Code Playgroud)

但是从未调用过animationDidStop.如果我像下面那样更改代码,则调用完成阻止.

- (void)startAnim {
    CABasicAnimation* anim = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    anim.fromValue = startAngle;
    anim.toValue = endAngle;
    anim.duration = 2;
    anim.delegate = self;

    [CATransaction begin];
    [CATransaction setCompletionBlock:^{
        [self.target setValue:@(endAngle) forKeyPath:@"transform.rotation.z"];
    }];

    [self.target addAnimation:anim forKey:nil];
    [CATransaction commit];
} …
Run Code Online (Sandbox Code Playgroud)

iphone core-animation ios

3
推荐指数
1
解决办法
2822
查看次数

标签 统计

core-animation ×1

ios ×1

iphone ×1