那里.
在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)