ohh*_*hho 2 iphone core-animation objective-c
有两个相似大小的UIView.UIView one(A)最初位于UIView二(B)之上.当我尝试transform.rotation.y在A层上执行CABasicAnimation 时:
CABasicAnimation *rotateAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
CGFloat startValue = 0.0;
CGFloat endValue = M_PI;
rotateAnimation.fromValue = [NSNumber numberWithDouble:startValue];
rotateAnimation.toValue = [NSNumber numberWithDouble:endValue];
rotateAnimation.duration = 5.0;
[CATransaction begin];
[imageA.layer addAnimation:rotateAnimation forKey:@"rotate"];
[CATransaction commit];
Run Code Online (Sandbox Code Playgroud)
在动画期间,动画层的UIView(A)将是:
有没有办法在整个动画期间将A保持在B的顶部?谢谢!
更新:附加项目源:FlipLayer.zip
Lil*_*ard 10
问题是围绕Y轴的旋转将在真正的3D合成系统中使层A与层B相交,使得层A的一半应该是可见的而一半应该在层B之后.CoreAnimation不提供真正的3D合成系统.相反,它试图确定哪个层位于哪个其他层的前面,并完全呈现它而没有交叉.在您的情况下,在旋转的前半部分,CoreAnimation已决定B层位于3D空间中的A层之上.最简单的解决方案可能layer.bounds.size.width是在动画持续时间内将图层A的zPosition设置为(默认值为0)(或永久性地,如果它应始终位于顶部).
如果只想在动画持续时间内设置它,可以为transform.translation.z关键路径添加第二个动画.以下是-flip修改后使用此方法的方法:
- (IBAction)flip:(id)sender {
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
CGFloat startValue = 0.0;
CGFloat endValue = M_PI;
animation.fromValue = [NSNumber numberWithDouble:startValue];
animation.toValue = [NSNumber numberWithDouble:endValue];
animation.duration = 5.0;
[imageOne.layer addAnimation:animation forKey:@"rotate"];
animation.keyPath = @"transform.translation.z";
animation.fromValue = [NSNumber numberWithFloat:imageOne.layer.bounds.size.width];
animation.toValue = animation.fromValue;
[imageOne.layer addAnimation:animation forKey:@"zPosition"];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3709 次 |
| 最近记录: |