它应该是非常简单的东西,但我还没有成功地使用块来实现它.有这样的问题和答案,但我发现的所有这些都是通过使用CABasicAnimation而不是UIView基于块的动画来解决的,这就是我所追求的.
以下代码不起作用(基于块),没有动画:
CGAffineTransform spin = CGAffineTransformRotate(spiningView.transform, DEGREES_RADIANS(360));
CATransform3D identity = CATransform3DIdentity;
CATransform3D spin2 = CATransform3DRotate(identity, DEGREES_RADIANS(360), 0.0f, 0.0f, 1.0f);
[UIView animateWithDuration:3.0f
delay:0.0f
options:UIViewAnimationOptionCurveLinear
animations:^
{
spiningView.transform = spin;
//spiningView.layer.transform = spin2;
//Have also tried the above, doesn't work either.
}
completion:^(BOOL finished)
{
spiningView.transform = spin;
//spiningView.layer.transform = spin2;
}];
Run Code Online (Sandbox Code Playgroud)
根据我的理解,当我们每次使用Block-Based时,当UIViewAnimationBlock"看到"begin值与最终值相同时,不会发生任何动画.足够公平,将其设置为360度将意味着物体保持原状.但它必须是一种使用基于块的动画来制作动画的方法,因为以下内容CABasicAnimation可以完美地工作:
CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0f];
rotationAnimation.duration = 3.0f;
rotationAnimation.cumulative …Run Code Online (Sandbox Code Playgroud)