CATransform3DRotate和UIImageView

Pie*_*rre 8 iphone core-animation

我正在UIImage用这段代码制作一个视图

CABasicAnimation *animation;
animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
animation.duration = 1;
animation.toValue = [NSNumber numberWithFloat:M_PI];
animation.fromValue = [NSNumber numberWithInt:0];
[square.layer addAnimation:animation forKey:@"rotation"];
Run Code Online (Sandbox Code Playgroud)

一切正常但我的阵列在动画结束时占据了原来的位置.我查看了图层属性,发现:

[square.layer setTransform:CATransform3DRotate(HERE, -M_PI, 0, 0, 0)];
Run Code Online (Sandbox Code Playgroud)

我不知道写什么而不是"HERE".请问你能帮帮我吗?非常感谢 !

Bra*_*son 5

CATransform3DRotate()将要对其应用旋转的变换作为其第一个参数。如果您想旋转图层的变换,则可以使用

[square.layer setTransform:CATransform3DRotate(square.layer.transform, -M_PI, 0, 0, 0)];
Run Code Online (Sandbox Code Playgroud)

就是说,如果您遇到的问题是该图层在动画结束时突然跳回到起始位置,则只需将动画的removedOnCompletion属性设置为NO并将其fillMode属性设置为即可kCAFillModeForwards